diff -Nru python-distutils-extra-2.32/debian/changelog python-distutils-extra-2.33/debian/changelog --- python-distutils-extra-2.32/debian/changelog 2012-05-25 04:53:31.000000000 +0000 +++ python-distutils-extra-2.33/debian/changelog 2012-06-11 16:15:27.000000000 +0000 @@ -1,3 +1,11 @@ +python-distutils-extra (2.33-1) unstable; urgency=low + + * auto.py: Fix crash when encountering binary files with Python 3. + (LP: #995653) + * auto.py: Fix crash when encountering an UTF-8 Python source code file. + + -- Martin Pitt Mon, 11 Jun 2012 18:14:28 +0200 + python-distutils-extra (2.32-5) unstable; urgency=low [ Andrew Starr-Bochicchio ] diff -Nru python-distutils-extra-2.32/DistUtilsExtra/auto.py python-distutils-extra-2.33/DistUtilsExtra/auto.py --- python-distutils-extra-2.32/DistUtilsExtra/auto.py 2012-03-02 16:45:10.000000000 +0000 +++ python-distutils-extra-2.33/DistUtilsExtra/auto.py 2012-06-11 16:12:55.000000000 +0000 @@ -377,7 +377,8 @@ cur_module = None try: - tree = ast.parse(open(file).read(), file) + with open(file, 'rb') as f: + tree = ast.parse(f.read().decode('UTF-8'), file) for node in ast.walk(tree): if isinstance(node, ast.Import): @@ -439,8 +440,11 @@ continue ext = os.path.splitext(s)[1] if ext == '': - f = open(s) - line = f.readline() + try: + with open(s) as f: + line = f.readline() + except (UnicodeDecodeError, IOError): + continue if not line.startswith('#!') or 'python' not in line: continue elif ext != '.py': diff -Nru python-distutils-extra-2.32/DistUtilsExtra/__init__.py python-distutils-extra-2.33/DistUtilsExtra/__init__.py --- python-distutils-extra-2.32/DistUtilsExtra/__init__.py 2012-03-02 16:46:22.000000000 +0000 +++ python-distutils-extra-2.33/DistUtilsExtra/__init__.py 2012-06-11 16:14:21.000000000 +0000 @@ -1 +1 @@ -__version__ = '2.32' +__version__ = '2.33' diff -Nru python-distutils-extra-2.32/PKG-INFO python-distutils-extra-2.33/PKG-INFO --- python-distutils-extra-2.32/PKG-INFO 2012-03-02 16:50:39.000000000 +0000 +++ python-distutils-extra-2.33/PKG-INFO 2012-06-11 16:14:37.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: python-distutils-extra -Version: 2.32 +Version: 2.33 Summary: Add support for i18n, documentation and icons to distutils Home-page: UNKNOWN Author: Sebastian Heinlein, Martin Pitt diff -Nru python-distutils-extra-2.32/python_distutils_extra.egg-info/PKG-INFO python-distutils-extra-2.33/python_distutils_extra.egg-info/PKG-INFO --- python-distutils-extra-2.32/python_distutils_extra.egg-info/PKG-INFO 2012-03-02 16:50:39.000000000 +0000 +++ python-distutils-extra-2.33/python_distutils_extra.egg-info/PKG-INFO 2012-06-11 16:14:37.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: python-distutils-extra -Version: 2.32 +Version: 2.33 Summary: Add support for i18n, documentation and icons to distutils Home-page: UNKNOWN Author: Sebastian Heinlein, Martin Pitt diff -Nru python-distutils-extra-2.32/test/auto.py python-distutils-extra-2.33/test/auto.py --- python-distutils-extra-2.32/test/auto.py 2012-03-02 16:45:10.000000000 +0000 +++ python-distutils-extra-2.33/test/auto.py 2012-06-11 16:11:45.000000000 +0000 @@ -85,8 +85,8 @@ def test_modules(self): '''Python modules''' - self._mksrc('yesme.py') - self._mksrc('stuff/notme.py') + self._mksrc('yesme.py', b'x ="a\xc3\xa4b\xe2\x99\xa5"'.decode('UTF-8')) + self._mksrc('stuff/notme.py', b'x ="a\xc3\xa4b\xe2\x99\xa5"'.decode('UTF-8')) (o, e, s) = self.do_install() self.assertEqual(e, '') @@ -351,7 +351,7 @@ (o, e, s) = self.do_install() self.assertEqual(e, '') self.assertEqual(s, 0) - self.assertFalse('following files are not recognized' in o) + self.assertFalse('following files are not recognized' in o, o) f = self.installed_files() self.assertTrue('/usr/share/foo/stuff' in f) @@ -799,6 +799,21 @@ self.assertTrue('/usr/share/gnome/help/foo/de/legal.page' in f) self.assertTrue('/usr/share/gnome/help/foo/de/figures/mainscreen.png' in f) + def test_binary_files(self): + '''Binary files are ignored''' + + with open(os.path.join(self.src, 'binary_trap'), 'wb') as f: + f.write(b'\x00\x01abc\xFF\xFE') + (o, e, s) = self.do_install() + self.assertEqual(e, '') + self.assertEqual(s, 0) + self.assertTrue('following files are not recognized' in o, o) + self.assertTrue('\n binary_trap\n' in o) + + f = self.installed_files() + self.assertEqual(len(f), 1, f) + self.assertTrue('egg-info' in f[0]) + # # helper methods # @@ -857,13 +872,12 @@ dir = os.path.dirname(path) if not os.path.isdir(dir): os.makedirs(dir) - f = open(path, 'w') - if content is None: - # default content, to spot with diff - f.write('dummy') - else: - f.write(content + '\n') - f.close() + with open(path, 'wb') as f: + if content is None: + # default content, to spot with diff + f.write(b'dummy') + else: + f.write((content + '\n').encode('UTF-8')) if executable: os.chmod(path, 0o755)