--- python27.spec.orig	2013-02-19 14:50:11.308773442 +0000
+++ python27.spec	2013-02-21 08:58:08.170572235 +0000
@@ -130,6 +130,7 @@
 # (keep this list alphabetized)
 
 BuildRequires: autoconf
+BuildRequires: bluez-libs-devel
 BuildRequires: bzip2
 BuildRequires: bzip2-devel
 BuildRequires: db4-devel
@@ -339,6 +340,7 @@
 # by default which is what el6 has.
 Patch54: python-2.6.4-setup-db43.patch
 
+# 00055 #
 # Systemtap support: add statically-defined probe points
 # Patch based on upstream bug: http://bugs.python.org/issue4111
 # fixed up by mjw and wcohen for 2.6.2, then fixed up by dmalcolm for 2.6.4
@@ -373,14 +375,18 @@
 # and platform-specific code go to /usr/lib64 not /usr/lib, on 64-bit archs:
 Patch103: python-2.7-lib64-sysconfig.patch
 
+# 00104 #
 # Only used when "%{_lib}" == "lib64"
 # Another lib64 fix, for distutils/tests/test_install.py; not upstream:
 Patch104: 00104-lib64-fix-for-test_install.patch
 
+# 00111 #
 # Patch the Makefile.pre.in so that the generated Makefile doesn't try to build
 # a libpythonMAJOR.MINOR.a (bug 550692):
+# Downstream only: not appropriate for upstream
 Patch111: 00111-no-static-lib.patch
 
+# 00112 #
 # Patch to support building both optimized vs debug stacks DSO ABIs, sharing
 # the same .py and .pyc files, using "_d.so" to signify a debug build of an
 # extension module.
@@ -445,14 +451,18 @@
 Patch112: python-2.7.3-debug-build.patch
 
 
+# 00113 #
 # Add configure-time support for the COUNT_ALLOCS and CALL_PROFILE options
 # described at http://svn.python.org/projects/python/trunk/Misc/SpecialBuilds.txt
 # so that if they are enabled, they will be in that build's pyconfig.h, so that
 # extension modules will reliably use them
+# Not yet sent upstream
 Patch113: 00113-more-configuration-flags.patch
 
+# 00114 #
 # Add flags for statvfs.f_flag to the constant list in posixmodule (i.e. "os")
 # (rhbz:553020); partially upstream as http://bugs.python.org/issue7647
+# Not yet sent upstream
 Patch114: 00114-statvfs-f_flag-constants.patch
 
 # Upstream as of Python 2.7.3:
@@ -474,11 +484,12 @@
 # For now, revert this patch:
 Patch121: python-2.7rc2-r79310.patch
 
+# 00125 #
 # COUNT_ALLOCS is useful for debugging, but the upstream behaviour of always
 # emitting debug info to stdout on exit is too verbose and makes it harder to
 # use the debug build.  Add a "PYTHONDUMPCOUNTS" environment variable which
 # must be set to enable the output on exit
-# Not yet sent upstream:
+# Not yet sent upstream
 Patch125: 00125-less-verbose-COUNT_ALLOCS.patch
 
 # Fix dbm module on big-endian 64-bit
@@ -495,6 +506,7 @@
 # Not yet sent upstream
 Patch128: python-2.7.1-fix_test_abc_with_COUNT_ALLOCS.patch
 
+# 00130 #
 # Add "--extension-suffix" option to python-config and python-debug-config
 # (rhbz#732808)
 #
@@ -511,12 +523,14 @@
 # Not yet sent upstream
 Patch130: python-2.7.2-add-extension-suffix-to-python-config.patch
 
+# 00131 #
 # The four tests in test_io built on top of check_interrupted_write_retry
 # fail when built in Koji, for ppc and ppc64; for some reason, the SIGALRM
 # handlers are never called, and the call to write runs to completion
 # (rhbz#732998)
 Patch131: 00131-disable-tests-in-test_io.patch
 
+# 00132 #
 # Add non-standard hooks to unittest for use in the "check" phase below, when
 # running selftests within the build:
 #   @unittest._skipInRpmBuild(reason)
@@ -530,53 +544,68 @@
 # these unittest hooks in their own "check" phases)
 Patch132: 00132-add-rpmbuild-hooks-to-unittest.patch
 
+# 00133 #
 # "dl" is deprecated, and test_dl doesn't work on 64-bit builds:
 Patch133: 00133-skip-test_dl.patch
 
+# 00134 #
 # Fix a failure in test_sys.py when configured with COUNT_ALLOCS enabled
 # Not yet sent upstream
 Patch134: 00134-fix-COUNT_ALLOCS-failure-in-test_sys.patch
 
+# 00135 #
 # Skip "test_callback_in_cycle_resurrection" in a debug build, where it fails:
 # Not yet sent upstream
 Patch135: 00135-skip-test-within-test_weakref-in-debug-build.patch
 
+# 00136 #
 # Some tests try to seek on sys.stdin, but don't work as expected when run
 # within Koji/mock; skip them within the rpm build:
 Patch136: 00136-skip-tests-of-seeking-stdin-in-rpmbuild.patch
 
+# 00137 #
 # Some tests within distutils fail when run in an rpmbuild:
 Patch137: 00137-skip-distutils-tests-that-fail-in-rpmbuild.patch
 
+# 00138 #
 # Fixup some tests within distutils to work with how debug builds are set up:
 Patch138: 00138-fix-distutils-tests-in-debug-build.patch
 
+# 00139 #
 # ARM-specific: skip known failure in test_float:
 #  http://bugs.python.org/issue8265 (rhbz#706253)
 Patch139: 00139-skip-test_float-known-failure-on-arm.patch
 
+# 00140 #
 # Sparc-specific: skip known failure in test_ctypes:
 #  http://bugs.python.org/issue8314 (rhbz#711584)
 # which appears to be a libffi bug
 Patch140: 00140-skip-test_ctypes-known-failure-on-sparc.patch
 
+# 00141 #
 # Fix test_gc's test_newinstance case when configured with COUNT_ALLOCS:
+# Not yet sent upstream
 Patch141: 00141-fix-test_gc_with_COUNT_ALLOCS.patch
 
+# 00142 #
 # Some pty tests fail when run in mock (rhbz#714627):
 Patch142: 00142-skip-failing-pty-tests-in-rpmbuild.patch
 
+# 00143 #
 # Fix the --with-tsc option on ppc64, and rework it on 32-bit ppc to avoid
 # aliasing violations (rhbz#698726)
 # Sent upstream as http://bugs.python.org/issue12872
 Patch143: 00143-tsc-on-ppc.patch
 
+# 00144 #
 # (Optionally) disable the gdbm module:
 Patch144: 00144-no-gdbm.patch
 
+# 00145 #
 # Upstream as of Python 2.7.3:
 #  Patch145: 00145-force-sys-platform-to-be-linux2.patch
 
+# 00146 #
 # Support OpenSSL FIPS mode (e.g. when OPENSSL_FORCE_FIPS_MODE=1 is set)
 # - handle failures from OpenSSL (e.g. on attempts to use MD5 in a
 #   FIPS-enforcing environment)
@@ -594,46 +623,108 @@
 # (rhbz#563986)
 Patch146: 00146-hashlib-fips.patch
 
+# 00147 #
 # Add a sys._debugmallocstats() function
 # Based on patch 202 from RHEL 5's python.spec, with updates from rhbz#737198
-#  Not yet sent upstream
+# Sent upstream as http://bugs.python.org/issue14785
 Patch147: 00147-add-debug-malloc-stats.patch
 
+# 00148 #
 # Upstream as of Python 2.7.3:
 #  Patch148: 00148-gdbm-1.9-magic-values.patch
 
+# 00149 #
 # python3.spec's
 #   Patch149: 00149-backport-issue11254-pycache-bytecompilation-fix.patch
 # is not relevant for Python 2
 
+# 00150 #
 # python3.spec has:
 #  Patch150: 00150-disable-rAssertAlmostEqual-cmath-on-ppc.patch
 # as a workaround for a glibc bug on PPC (bz #750811)
 
+# 00151 #
 # Upstream as of Python 2.7.3:
 #  Patch151: 00151-fork-deadlock.patch
 
+# 00152 #
 # python3.spec has:
 #  Patch152: 00152-fix-test-gdb-regex.patch
 
+# 00153 #
 # Strip out lines of the form "warning: Unable to open ..." from gdb's stderr
 # when running test_gdb.py; also cope with change to gdb in F17 onwards in
 # which values are printed as "v@entry" rather than just "v":
+# Not yet sent upstream
 Patch153: 00153-fix-test_gdb-noise.patch
 
+# 00154 #
 # python3.spec on f15 has:
 #  Patch154: 00154-skip-urllib-test-requiring-working-DNS.patch
 
+# 00155 #
 # Avoid allocating thunks in ctypes unless absolutely necessary, to avoid
 # generating SELinux denials on "import ctypes" and "import uuid" when
 # embedding Python within httpd (rhbz#814391)
 Patch155: 00155-avoid-ctypes-thunks.patch
 
+# 00156 #
 # Recent builds of gdb will only auto-load scripts from certain safe
 # locations.  Turn off this protection when running test_gdb in the selftest
 # suite to ensure that it can load our -gdb.py script (rhbz#817072):
+# Not yet sent upstream
 #Patch156: 00156-gdb-autoload-safepath.patch
 
+# 00157 #
+# Update uid/gid handling throughout the standard library: uid_t and gid_t are
+# unsigned 32-bit values, but existing code often passed them through C long
+# values, which are signed 32-bit values on 32-bit architectures, leading to
+# negative int objects for uid/gid values >= 2^31 on 32-bit architectures.
+#
+# Introduce _PyObject_FromUid/Gid to convert uid_t/gid_t values to python
+# objects, using int objects where the value will fit (long objects otherwise),
+# and _PyArg_ParseUid/Gid to convert int/long to uid_t/gid_t, with -1 allowed
+# as a special case (since this is given special meaning by the chown syscall)
+#
+# Update standard library to use this throughout for uid/gid values, so that
+# very large uid/gid values are round-trippable, and -1 remains usable.
+# (rhbz#697470)
+Patch157: 00157-uid-gid-overflows.patch
+
+# 00158 #
+# This patch fixes a memory leak in _hashlib module, as reported in
+# RHBZ #836285; upstream report http://bugs.python.org/issue15219.
+# The patch has been accepted upstream, so this should be commented out
+# when packaging next upstream release.
+# The fix for Fedora specific "implement_specific_EVP_new()" function
+# has been merged into patch 00146.
+Patch158: 00158-fix-hashlib-leak.patch
+
+# 00159 #
+# From F18 on, there is a libdb4 package, that replaces db4. It places header
+# files in "/usr/include/libdb4", not in "/usr/include/db4", this patch
+# fixes this.
+# Downstream only modification.
+#Patch159: 00159-correct-libdb-include-path.patch
+
+# 00160 #
+# python3.spec's
+#   Patch160: 00160-disable-test_fs_holes-in-rpm-build.patch
+# is not relevant for Python 2
+
+# 00161 #
+# python3.spec has:
+#   Patch161: 00161-fix-test_tools-directory.patch
+# which will likely become relevant for Python 2 next time we rebase
+
+# 00162 #
+# python3.spec has:
+#  Patch162: 00162-distutils-sysconfig-fix-CC-options.patch
+
+# 00163 #
+# python3.spec has:
+#  Patch163: 00163-disable-parts-of-test_socket-in-rpm-build.patch
+
 # Prevent build failures with pre-3.5.0 versions of sqlite3, such as was shipped
 # with Centos 5
 #
@@ -665,13 +756,15 @@
 # This is the generated patch to "configure"; see the description of
 #   %{regenerate_autotooling_patch}
 # above:
-Patch300: autotool-intermediates.patch
+Patch5000: 05000-autotool-intermediates.patch
 
 # ======================================================
 # Additional metadata, and subpackages
 # ======================================================
 
 %if %{main_python}
+Obsoletes: Distutils
+Provides: Distutils
 Obsoletes: python2 < %{version}
 Provides: python2 = %{version}
 Obsoletes: python-elementtree <= 1.2.6
@@ -962,13 +1055,20 @@
 %if 0%{?rhel} == 5
 %patch201 -p1
 %endif
+%patch157 -p1 -b .uid-gid-overflows
+%patch158 -p1
+# 00160: not for python 2
+# 00161: not for python 2 yet
+# 00162: not for python 2 yet
+# 00163: not for python 2 yet
+
 # This shouldn't be necesarry, but is right now (2.2a3)
 find -name "*~" |xargs rm -f
 
 %if ! 0%{regenerate_autotooling_patch}
 # Normally we apply the patch to "configure"
 # We don't apply the patch if we're working towards regenerating it
-%patch300 -p0 -b .autotool-intermediates
+%patch5000 -p0 -b .autotool-intermediates
 %endif
 
 
@@ -1008,7 +1108,7 @@
 autoheader
 
 # Regenerate the patch:
-gendiff . .autotool-intermediates > %{PATCH300}
+gendiff . .autotool-intermediates > %{PATCH5000}
 
 
 # Exit the build
@@ -1031,22 +1131,28 @@
 
   pushd $ConfDir
 
+  # Use the freshly created "configure" script, but in the directory two above:
+%if 0%{?rhel} == 5
 $topdir/configure \
   --prefix=%{_prefix} \
   --libdir=%{_libdir} \
+%else
+  %global _configure $topdir/configure
+%configure \
+%endif
   --enable-ipv6 \
-  --enable-unicode=%{unicode} \
   --enable-shared \
+  --enable-unicode=%{unicode} \
+  --with-dbmliborder=gdbm:ndbm:bdb \
+  --with-system-expat \
   --with-system-ffi \
-%if 0%{?with_valgrind}
-  --with-valgrind \
-%endif
 %if 0%{?with_systemtap}
   --with-dtrace \
   --with-tapset-install-dir=%{tapsetdir} \
 %endif
-  --with-system-expat \
-  --with-dbmliborder=gdbm:ndbm:bdb \
+%if 0%{?with_valgrind}
+  --with-valgrind \
+%endif
   $ExtraConfigArgs \
   %{nil}
 
