fix_future_standard_library_urllib.py 1001 B

12345678910111213141516171819202122232425262728
  1. """
  2. For the ``future`` package.
  3. A special fixer that ensures that these lines have been added::
  4. from future import standard_library
  5. standard_library.install_hooks()
  6. even if the only module imported was ``urllib``, in which case the regular fixer
  7. wouldn't have added these lines.
  8. """
  9. from lib2to3.fixes.fix_urllib import FixUrllib
  10. from libfuturize.fixer_util import touch_import_top, find_root
  11. class FixFutureStandardLibraryUrllib(FixUrllib): # not a subclass of FixImports
  12. run_order = 8
  13. def transform(self, node, results):
  14. # transform_member() in lib2to3/fixes/fix_urllib.py breaks node so find_root(node)
  15. # no longer works after the super() call below. So we find the root first:
  16. root = find_root(node)
  17. result = super(FixFutureStandardLibraryUrllib, self).transform(node, results)
  18. # TODO: add a blank line between any __future__ imports and this?
  19. touch_import_top(u'future', u'standard_library', root)
  20. return result