diff options
| author | Kubilay Kocak <koobs@FreeBSD.org> | 2014-02-21 13:42:08 +0000 |
|---|---|---|
| committer | Kubilay Kocak <koobs@FreeBSD.org> | 2014-02-21 13:42:08 +0000 |
| commit | b1bc680e1c6dee1fd0f6fa3bf33cc6dec56e5f18 (patch) | |
| tree | 0ea6df1de66751b351f1021403fb1d5babecbe29 /lang/python31/files | |
| parent | Remove trailing whitespaces from category x11-wm (diff) | |
lang/python31: Backport fox for Python issue #8168
- Backport Python issue #8168 [1]:
python3 py_compile does not ignore UTF-8 BOM characters
This causes installation (during bytecode compilation) errors for Python
ports with sources that contain BOM characters [2]
The issue was fixed [3] in the default branch at the time (3.2) but was
not backported to 3.1.
Since Python 3.1 is now in security-fix-only mode (no new features or bug
fixes), backporting is required.
[1] http://bugs.python.org/issue8168
[2] http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/186034
[3] http://hg.python.org/cpython/rev/e15a8a476494/
PR: ports/186034
Reported by: Mark Andrews <marka at isc dot org>
Notes
Notes:
svn path=/head/; revision=345444
Diffstat (limited to 'lang/python31/files')
| -rw-r--r-- | lang/python31/files/patch-Lib__py_compile.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lang/python31/files/patch-Lib__py_compile.py b/lang/python31/files/patch-Lib__py_compile.py new file mode 100644 index 000000000000..1eaaca1e5697 --- /dev/null +++ b/lang/python31/files/patch-Lib__py_compile.py @@ -0,0 +1,49 @@ +# Description: python3 py_compile does not ignore UTF-8 BOM characters +# Issue: http://bugs.python.org/issue8168 +# Commit: http://hg.python.org/cpython/rev/e15a8a476494/ +# PR: ports/186034 + +--- ./Lib/py_compile.py.orig 2014-02-21 23:28:42.491208180 +1100 ++++ ./Lib/py_compile.py 2014-02-21 23:29:22.052513709 +1100 +@@ -7,8 +7,8 @@ + import imp + import marshal + import os +-import re + import sys ++import tokenize + import traceback + + MAGIC = imp.get_magic() +@@ -78,21 +78,6 @@ + (x >> 16) & 0xff, + (x >> 24) & 0xff])) + +-def read_encoding(file, default): +- """Read the first two lines of the file looking for coding: xyzzy.""" +- f = open(file, "rb") +- try: +- for i in range(2): +- line = f.readline() +- if not line: +- break +- m = re.match(br".*\bcoding:\s*(\S+)\b", line) +- if m: +- return m.group(1).decode("ascii") +- return default +- finally: +- f.close() +- + def compile(file, cfile=None, dfile=None, doraise=False): + """Byte-compile one Python source file to Python bytecode. + +@@ -128,7 +113,8 @@ + directories). + + """ +- encoding = read_encoding(file, "utf-8") ++ with open(file, "rb") as f: ++ encoding = tokenize.detect_encoding(f.readline)[0] + f = open(file, 'U', encoding=encoding) + try: + timestamp = int(os.fstat(f.fileno()).st_mtime) |
