~ubuntu-branches/ubuntu/trusty/python-distutils-extra/trusty-proposed

« back to all changes in this revision

Viewing changes to DistUtilsExtra/auto.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-06-11 18:14:28 UTC
  • mfrom: (18.1.12)
  • Revision ID: package-import@ubuntu.com-20120611181428-bd34t97e1qu8fn3v
Tags: 2.33-1
* 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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
377
377
        cur_module = None
378
378
 
379
379
    try:
380
 
        tree = ast.parse(open(file).read(), file)
 
380
        with open(file, 'rb') as f:
 
381
            tree = ast.parse(f.read().decode('UTF-8'), file)
381
382
 
382
383
        for node in ast.walk(tree):
383
384
            if isinstance(node, ast.Import):
439
440
            continue
440
441
        ext = os.path.splitext(s)[1]
441
442
        if ext == '':
442
 
            f = open(s)
443
 
            line = f.readline()
 
443
            try:
 
444
                with open(s) as f:
 
445
                    line = f.readline()
 
446
            except (UnicodeDecodeError, IOError):
 
447
                continue
444
448
            if not line.startswith('#!') or 'python' not in line:
445
449
                continue
446
450
        elif ext != '.py':