python-pefile/pefile-fix-py2-build-43c1cc79a.patch
2016-11-01 21:15:16 +01:00

55 lines
1.6 KiB
Diff

From 43c1cc79a7120981e7465dc69c531f373fee326c Mon Sep 17 00:00:00 2001
From: Athmane Madjoudj <athmane@fedoraproject.org>
Date: Tue, 1 Nov 2016 20:35:23 +0100
Subject: [PATCH] Fix python2 build
---
setup.py | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/setup.py b/setup.py
index b22ed88..b932eb7 100755
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,9 @@
import os
import re
import sys
-from io import open
+
+if sys.version_info.major == 3:
+ from io import open
try:
from setuptools import setup, Command
@@ -23,8 +25,12 @@ def _read_doc():
Parse docstring from file 'pefile.py' and avoid importing
this module directly.
"""
- with open('pefile.py', 'r', encoding='utf-8') as f:
- tree = ast.parse(f.read().encode('ascii', 'backslashreplace'))
+ if sys.version_info.major == 2:
+ with open('pefile.py', 'r') as f:
+ tree = ast.parse(f.read())
+ else:
+ with open('pefile.py', 'r', encoding='utf-8') as f:
+ tree = ast.parse(f.read())
return ast.get_docstring(tree)
@@ -36,8 +42,12 @@ def _read_attr(attr_name):
__version__, __author__, __contact__,
"""
regex = attr_name + r"\s+=\s+'(.+)'"
- with open('pefile.py', 'r', encoding='utf-8') as f:
- match = re.search(regex, f.read())
+ if sys.version_info.major == 2:
+ with open('pefile.py', 'r') as f:
+ match = re.search(regex, f.read())
+ else:
+ with open('pefile.py', 'r', encoding='utf-8') as f:
+ match = re.search(regex, f.read())
# Second item in the group is the value of attribute.
return match.group(1)