Merge lp:~didrocks/python-distutils-extra/fix-warning-using-python2 into lp:python-distutils-extra

Proposed by Didier Roche on 2012-07-09
Status: Merged
Merged at revision: 295
Proposed branch: lp:~didrocks/python-distutils-extra/fix-warning-using-python2
Merge into: lp:python-distutils-extra
Diff against target: 50 lines (+13/-1)
3 files modified
DistUtilsExtra/auto.py (+7/-1)
debian/changelog (+5/-0)
test/auto.py (+1/-0)
To merge this branch: bzr merge lp:~didrocks/python-distutils-extra/fix-warning-using-python2
Reviewer Review Type Date Requested Status
Martin Pitt (community) 2012-07-09 Approve on 2012-07-09
Review via email: mp+113928@code.launchpad.net

Description of the Change

Fix a regression on python2 when files contain an utf-8 encoding directive

To post a comment you must log in.
Martin Pitt (pitti) wrote :

Thanks! Merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUtilsExtra/auto.py'
2--- DistUtilsExtra/auto.py 2012-06-26 05:31:31 +0000
3+++ DistUtilsExtra/auto.py 2012-07-09 09:09:21 +0000
4@@ -378,7 +378,13 @@
5
6 try:
7 with open(file, 'rb') as f:
8- tree = ast.parse(f.read().decode('UTF-8'), file)
9+ # send binary blob for python2, otherwise sending an unicode object with
10+ # "encoding" directive makes ast triggering an exception in python2
11+ if(sys.version_info.major < 3):
12+ file_content = f.read()
13+ else:
14+ file_content = f.read().decode('UTF-8')
15+ tree = ast.parse(file_content, file)
16
17 for node in ast.walk(tree):
18 if isinstance(node, ast.Import):
19
20=== modified file 'debian/changelog'
21--- debian/changelog 2012-06-26 05:33:02 +0000
22+++ debian/changelog 2012-07-09 09:09:21 +0000
23@@ -1,10 +1,15 @@
24 python-distutils-extra (2.34-1) UNRELEASED; urgency=low
25
26+ [ Martin Pitt ]
27 * debian/rules: Run Python3 tests under C locale, to expose more unicode
28 errors.
29 * auto.py: Fix *.ui detection to be robust for non-ASCII files.
30 (LP: #1017468)
31
32+ [ Didier Roche ]
33+ * auto.py: Fix a regression with python2 if files have some utf-8 directives
34+ (LP: #1021969)
35+
36 -- Martin Pitt <mpitt@debian.org> Tue, 26 Jun 2012 07:29:13 +0200
37
38 python-distutils-extra (2.33-1) unstable; urgency=low
39
40=== modified file 'test/auto.py'
41--- test/auto.py 2012-06-26 05:31:31 +0000
42+++ test/auto.py 2012-07-09 09:09:21 +0000
43@@ -87,6 +87,7 @@
44
45 self._mksrc('yesme.py', b'x ="a\xc3\xa4b\xe2\x99\xa5"'.decode('UTF-8'))
46 self._mksrc('stuff/notme.py', b'x ="a\xc3\xa4b\xe2\x99\xa5"'.decode('UTF-8'))
47+ self._mksrc('stuff/withencoding.py', b'# -*- Mode: Python; coding: utf-8; -*- \nfoo = 1'.decode('UTF-8'))
48
49 (o, e, s) = self.do_install()
50 self.assertEqual(e, '')

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: