Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python27
/
lib
/
python2.7
/
site-packages
/
libpasteurize
/
fixes
/
File Content:
fix_imports.py
u""" Fixer for standard library imports renamed in Python 3 """ from lib2to3 import fixer_base from lib2to3.fixer_util import Name, is_probably_builtin, Newline, does_tree_import from lib2to3.pygram import python_symbols as syms from lib2to3.pgen2 import token from lib2to3.pytree import Node, Leaf from libfuturize.fixer_util import touch_import_top # from ..fixer_util import NameImport # used in simple_mapping_to_pattern() MAPPING = {u"reprlib": u"repr", u"winreg": u"_winreg", u"configparser": u"ConfigParser", u"copyreg": u"copy_reg", u"queue": u"Queue", u"socketserver": u"SocketServer", u"_markupbase": u"markupbase", u"test.support": u"test.test_support", u"dbm.bsd": u"dbhash", u"dbm.ndbm": u"dbm", u"dbm.dumb": u"dumbdbm", u"dbm.gnu": u"gdbm", u"html.parser": u"HTMLParser", u"html.entities": u"htmlentitydefs", u"http.client": u"httplib", u"http.cookies": u"Cookie", u"http.cookiejar": u"cookielib", # "tkinter": "Tkinter", u"tkinter.dialog": u"Dialog", u"tkinter._fix": u"FixTk", u"tkinter.scrolledtext": u"ScrolledText", u"tkinter.tix": u"Tix", u"tkinter.constants": u"Tkconstants", u"tkinter.dnd": u"Tkdnd", u"tkinter.__init__": u"Tkinter", u"tkinter.colorchooser": u"tkColorChooser", u"tkinter.commondialog": u"tkCommonDialog", u"tkinter.font": u"tkFont", u"tkinter.ttk": u"ttk", u"tkinter.messagebox": u"tkMessageBox", u"tkinter.turtle": u"turtle", u"urllib.robotparser": u"robotparser", u"xmlrpc.client": u"xmlrpclib", u"builtins": u"__builtin__", } # generic strings to help build patterns # these variables mean (with http.client.HTTPConnection as an example): # name = http # attr = client # used = HTTPConnection # fmt_name is a formatted subpattern (simple_name_match or dotted_name_match) # helps match 'queue', as in 'from queue import ...' simple_name_match = u"name='%s'" # helps match 'client', to be used if client has been imported from http subname_match = u"attr='%s'" # helps match 'http.client', as in 'import urllib.request' dotted_name_match = u"dotted_name=dotted_name< %s '.' %s >" # helps match 'queue', as in 'queue.Queue(...)' power_onename_match = u"%s" # helps match 'http.client', as in 'http.client.HTTPConnection(...)' power_twoname_match = u"power< %s trailer< '.' %s > any* >" # helps match 'client.HTTPConnection', if 'client' has been imported from http power_subname_match = u"power< %s any* >" # helps match 'from http.client import HTTPConnection' from_import_match = u"from_import=import_from< 'from' %s 'import' imported=any >" # helps match 'from http import client' from_import_submod_match = u"from_import_submod=import_from< 'from' %s 'import' (%s | import_as_name< %s 'as' renamed=any > | import_as_names< any* (%s | import_as_name< %s 'as' renamed=any >) any* > ) >" # helps match 'import urllib.request' name_import_match = u"name_import=import_name< 'import' %s > | name_import=import_name< 'import' dotted_as_name< %s 'as' renamed=any > >" # helps match 'import http.client, winreg' multiple_name_import_match = u"name_import=import_name< 'import' dotted_as_names< names=any* > >" def all_patterns(name): u""" Accepts a string and returns a pattern of possible patterns involving that name Called by simple_mapping_to_pattern for each name in the mapping it receives. """ # i_ denotes an import-like node # u_ denotes a node that appears to be a usage of the name if u'.' in name: name, attr = name.split(u'.', 1) simple_name = simple_name_match % (name) simple_attr = subname_match % (attr) dotted_name = dotted_name_match % (simple_name, simple_attr) i_from = from_import_match % (dotted_name) i_from_submod = from_import_submod_match % (simple_name, simple_attr, simple_attr, simple_attr, simple_attr) i_name = name_import_match % (dotted_name, dotted_name) u_name = power_twoname_match % (simple_name, simple_attr) u_subname = power_subname_match % (simple_attr) return u' | \n'.join((i_name, i_from, i_from_submod, u_name, u_subname)) else: simple_name = simple_name_match % (name) i_name = name_import_match % (simple_name, simple_name) i_from = from_import_match % (simple_name) u_name = power_onename_match % (simple_name) return u' | \n'.join((i_name, i_from, u_name)) class FixImports(fixer_base.BaseFix): PATTERN = u' | \n'.join([all_patterns(name) for name in MAPPING]) PATTERN = u' | \n'.join((PATTERN, multiple_name_import_match)) def transform(self, node, results): touch_import_top(u'future', u'standard_library', node)
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
__init__.py
3719 bytes
0644
__init__.pyc
974 bytes
0644
__init__.pyo
974 bytes
0644
feature_base.py
1723 bytes
0644
feature_base.pyc
2985 bytes
0644
feature_base.pyo
2985 bytes
0644
fix_add_all__future__imports.py
676 bytes
0644
fix_add_all__future__imports.pyc
1309 bytes
0644
fix_add_all__future__imports.pyo
1309 bytes
0644
fix_add_all_future_builtins.py
1269 bytes
0644
fix_add_all_future_builtins.pyc
1430 bytes
0644
fix_add_all_future_builtins.pyo
1430 bytes
0644
fix_add_future_standard_library_import.py
663 bytes
0644
fix_add_future_standard_library_import.pyc
1233 bytes
0644
fix_add_future_standard_library_import.pyo
1233 bytes
0644
fix_annotations.py
1581 bytes
0644
fix_annotations.pyc
2253 bytes
0644
fix_annotations.pyo
2153 bytes
0644
fix_division.py
904 bytes
0644
fix_division.pyc
1724 bytes
0644
fix_division.pyo
1724 bytes
0644
fix_features.py
2675 bytes
0644
fix_features.pyc
3399 bytes
0644
fix_features.pyo
3399 bytes
0644
fix_fullargspec.py
438 bytes
0644
fix_fullargspec.pyc
1063 bytes
0644
fix_fullargspec.pyo
1063 bytes
0644
fix_future_builtins.py
1450 bytes
0644
fix_future_builtins.pyc
1758 bytes
0644
fix_future_builtins.pyo
1758 bytes
0644
fix_getcwd.py
873 bytes
0644
fix_getcwd.pyc
1352 bytes
0644
fix_getcwd.pyo
1352 bytes
0644
fix_imports.py
4944 bytes
0644
fix_imports.pyc
4403 bytes
0644
fix_imports.pyo
4403 bytes
0644
fix_imports2.py
8580 bytes
0644
fix_imports2.pyc
10321 bytes
0644
fix_imports2.pyo
10321 bytes
0644
fix_kwargs.py
5991 bytes
0644
fix_kwargs.pyc
4791 bytes
0644
fix_kwargs.pyo
4674 bytes
0644
fix_memoryview.py
551 bytes
0644
fix_memoryview.pyc
1144 bytes
0644
fix_memoryview.pyo
1144 bytes
0644
fix_metaclass.py
3260 bytes
0644
fix_metaclass.pyc
2668 bytes
0644
fix_metaclass.pyo
2668 bytes
0644
fix_newstyle.py
888 bytes
0644
fix_newstyle.pyc
1582 bytes
0644
fix_newstyle.pyo
1582 bytes
0644
fix_next.py
1233 bytes
0644
fix_next.pyc
1891 bytes
0644
fix_next.pyo
1858 bytes
0644
fix_printfunction.py
401 bytes
0644
fix_printfunction.pyc
991 bytes
0644
fix_printfunction.pyo
991 bytes
0644
fix_raise.py
1099 bytes
0644
fix_raise.pyc
1697 bytes
0644
fix_raise.pyo
1697 bytes
0644
fix_raise_.py
1225 bytes
0644
fix_raise_.pyc
1828 bytes
0644
fix_raise_.pyo
1828 bytes
0644
fix_throw.py
835 bytes
0644
fix_throw.pyc
1497 bytes
0644
fix_throw.pyo
1497 bytes
0644
fix_unpacking.py
5946 bytes
0644
fix_unpacking.pyc
6339 bytes
0644
fix_unpacking.pyo
6339 bytes
0644
N4ST4R_ID | Naxtarrr