contrib/import-checker.py
branchstable
changeset 43415 a8454e846736
parent 43084 c2e284cee333
child 43641 0ad5d6c4bfad
equal deleted inserted replaced
43414:a0916e8819f6 43415:a8454e846736
     2 
     2 
     3 from __future__ import absolute_import, print_function
     3 from __future__ import absolute_import, print_function
     4 
     4 
     5 import ast
     5 import ast
     6 import collections
     6 import collections
       
     7 import io
     7 import os
     8 import os
     8 import sys
     9 import sys
     9 
    10 
    10 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
    11 # Import a minimal set of stdlib modules needed for list_stdlib_modules()
    11 # to work when run from a virtualenv.  The modules were chosen empirically
    12 # to work when run from a virtualenv.  The modules were chosen empirically
   752     if not f.endswith('.t'):
   753     if not f.endswith('.t'):
   753         with open(f, 'rb') as src:
   754         with open(f, 'rb') as src:
   754             yield src.read(), modname, f, 0
   755             yield src.read(), modname, f, 0
   755             py = True
   756             py = True
   756     if py or f.endswith('.t'):
   757     if py or f.endswith('.t'):
   757         with open(f, 'r') as src:
   758         # Strictly speaking we should sniff for the magic header that denotes
       
   759         # Python source file encoding. But in reality we don't use anything
       
   760         # other than ASCII (mainly) and UTF-8 (in a few exceptions), so
       
   761         # simplicity is fine.
       
   762         with io.open(f, 'r', encoding='utf-8') as src:
   758             for script, modname, t, line in embedded(f, modname, src):
   763             for script, modname, t, line in embedded(f, modname, src):
   759                 yield script, modname.encode('utf8'), t, line
   764                 yield script, modname.encode('utf8'), t, line
   760 
   765 
   761 
   766 
   762 def main(argv):
   767 def main(argv):