From c5d5cf8463c47687c1ee8f7523079d5a526458d3 Mon Sep 17 00:00:00 2001
From: Orion Poplawski <orion@cora.nwra.com>
Date: Wed, 24 Aug 2016 15:34:12 -0600
Subject: [PATCH] Update to build on EL6

---
 python34-readline.patch | 14 ++++++++++++++
 python34.spec           | 27 +++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 python34-readline.patch

diff --git a/python34-readline.patch b/python34-readline.patch
new file mode 100644
index 0000000..83601d8
--- /dev/null
+++ b/python34-readline.patch
@@ -0,0 +1,14 @@
+diff -up Python-3.4.3/Lib/test/test_readline.py.readline Python-3.4.3/Lib/test/test_readline.py
+--- Python-3.4.3/Lib/test/test_readline.py.readline	2016-08-24 14:12:57.026751263 -0600
++++ Python-3.4.3/Lib/test/test_readline.py	2016-08-24 14:13:28.768616872 -0600
+@@ -45,7 +45,7 @@ class TestHistoryManipulation (unittest.
+ 
+ class TestReadline(unittest.TestCase):
+ 
+-    @unittest.skipIf(readline._READLINE_VERSION < 0x0600
++    @unittest.skipIf(readline._READLINE_VERSION < 0x0601
+                      and "libedit" not in readline.__doc__,
+                      "not supported in this library version")
+     def test_init(self):
+diff -up Python-3.4.3/Misc/NEWS.readline Python-3.4.3/Misc/NEWS
+diff -up Python-3.4.3/Modules/readline.c.readline Python-3.4.3/Modules/readline.c
diff --git a/python34.spec b/python34.spec
index 45e632a..cc80561 100644
--- a/python34.spec
+++ b/python34.spec
@@ -104,11 +104,16 @@
 # (/usr/bin/python, rather than the freshly built python), thus leading to
 # numerous syntax errors, and incorrect magic numbers in the .pyc files.  We
 # thus override __os_install_post to avoid invoking this script:
+%if 0%{?fedora} || 0%{?rhel} >= 7
+%global brp_python_hardlink /usr/lib/rpm/brp-python-hardlink
+%else
+%global brp_python_hardlink /usr/lib/rpm/redhat/brp-python-hardlink
+%endif
 %global __os_install_post /usr/lib/rpm/brp-compress \
   %{!?__debug_package:/usr/lib/rpm/brp-strip %{__strip}} \
   /usr/lib/rpm/brp-strip-static-archive %{__strip} \
   /usr/lib/rpm/brp-strip-comment-note %{__strip} %{__objdump} \
-  /usr/lib/rpm/brp-python-hardlink 
+  %{brp_python_hardlink}
 # to remove the invocation of brp-python-bytecompile, whilst keeping the
 # invocation of brp-python-hardlink (since this should still work for python3
 # pyc/pyo files)
@@ -148,7 +153,7 @@
 Summary: Version 3 of the Python programming language aka Python 3000
 Name: python%{pyshortver}
 Version: %{pybasever}.3
-Release: 7%{?dist}
+Release: 8%{?dist}
 License: Python
 Group: Development/Languages
 
@@ -167,7 +172,11 @@ BuildRequires: db4-devel >= 4.7
 
 # expat 2.1.0 added the symbol XML_SetHashSalt without bumping SONAME.  We use
 # it (in pyexpat) in order to enable the fix in Python-3.2.3 for CVE-2012-0876:
+%if 0%{?fedora} || 0%{?rhel} >= 7
 BuildRequires: expat-devel >= 2.1.0
+%else
+Provides:      bundled(expat) = 2.1.0
+%endif
 
 BuildRequires: findutils
 BuildRequires: gcc-c++
@@ -251,6 +260,10 @@ Source8: check-pyc-and-pyo-timestamps.py
 # Was Patch0 in ivazquez' python3000 specfile:
 Patch1:         Python-3.1.1-rpath.patch
 
+# readline test fails on EL6 readline 6.0
+# https://bugs.python.org/issue19884
+Patch2:         python34-readline.patch
+
 # Some tests were removed due to audiotest.au not being packaged. This was
 # however added to the archive in 3.3.1, so we no longer delete the tests.
 #  Patch3: 00003-remove-mimeaudio-tests.patch
@@ -818,7 +831,9 @@ Group:          Development/Libraries
 # this symbol (in pyexpat), so we must explicitly state this dependency to
 # prevent "import pyexpat" from failing with a linker error if someone hasn't
 # yet upgraded expat:
+%if 0%{?fedora} || 0%{?rhel} >= 7
 Requires: expat >= 2.1.0
+%endif
 
 %description libs
 This package contains files used to embed Python 3 into applications.
@@ -918,7 +933,9 @@ cp -a %{SOURCE7} .
 # Ensure that we're using the system copy of various libraries, rather than
 # copies shipped by upstream in the tarball:
 #   Remove embedded copy of expat:
+%if 0%{?fedora} || 0%{?rhel} >= 7
 rm -r Modules/expat || exit 1
+%endif
 
 #   Remove embedded copy of libffi:
 for SUBDIR in darwin libffi libffi_arm_wince libffi_msvc libffi_osx ; do
@@ -949,6 +966,7 @@ sed -r -i s/'_PIP_VERSION = "[0-9.]+"'/'_PIP_VERSION = "%{pip_version}"'/ Lib/en
 # Apply patches:
 #
 %patch1 -p1
+%patch2 -p1 -b .readline
 # 3: upstream as of Python 3.3.1
 
 %if 0%{?with_systemtap}
@@ -1134,7 +1152,9 @@ BuildPython() {
   --enable-shared \
   --with-computed-gotos=%{with_computed_gotos} \
   --with-dbmliborder=gdbm:ndbm:bdb \
+%if 0%{?fedora} || 0%{?rhel} >= 7
   --with-system-expat \
+%endif
   --with-system-ffi \
   --enable-loadable-sqlite-extensions \
 %if 0%{?with_systemtap}
@@ -2003,6 +2023,9 @@ rm -fr %{buildroot}
 # ======================================================
 
 %changelog
+* Wed Aug 24 2016 Orion Poplawski <orion@cora.nwra.com> - 3.4.3-8
+- Update to build on EL6
+
 * Tue Aug 09 2016 Charalampos Stratakis <cstratak@redhat.com> - 3.4.3-7
 - Fix for CVE-2016-1000110 HTTPoxy attack
 
-- 
1.8.3.1

