__init__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """
  2. A resurrection of some old functions from Python 2 for use in Python 3. These
  3. should be used sparingly, to help with porting efforts, since code using them
  4. is no longer standard Python 3 code.
  5. This module provides the following:
  6. 1. Implementations of these builtin functions which have no equivalent on Py3:
  7. - apply
  8. - chr
  9. - cmp
  10. - execfile
  11. 2. Aliases:
  12. - intern <- sys.intern
  13. - raw_input <- input
  14. - reduce <- functools.reduce
  15. - reload <- imp.reload
  16. - unichr <- chr
  17. - unicode <- str
  18. - xrange <- range
  19. 3. List-producing versions of the corresponding Python 3 iterator-producing functions:
  20. - filter
  21. - map
  22. - range
  23. - zip
  24. 4. Forward-ported Py2 types:
  25. - basestring
  26. - dict
  27. - str
  28. - long
  29. - unicode
  30. """
  31. from future.utils import PY3
  32. from past.builtins.noniterators import (filter, map, range, reduce, zip)
  33. # from past.builtins.misc import (ascii, hex, input, oct, open)
  34. if PY3:
  35. from past.types import (basestring,
  36. olddict as dict,
  37. oldstr as str,
  38. long,
  39. unicode)
  40. else:
  41. from __builtin__ import (basestring, dict, str, long, unicode)
  42. from past.builtins.misc import (apply, chr, cmp, execfile, intern, oct,
  43. raw_input, reload, unichr, unicode, xrange)
  44. from past import utils
  45. if utils.PY3:
  46. # We only import names that shadow the builtins on Py3. No other namespace
  47. # pollution on Py3.
  48. # Only shadow builtins on Py3; no new names
  49. __all__ = ['filter', 'map', 'range', 'reduce', 'zip',
  50. 'basestring', 'dict', 'str', 'long', 'unicode',
  51. 'apply', 'chr', 'cmp', 'execfile', 'intern', 'raw_input',
  52. 'reload', 'unichr', 'xrange'
  53. ]
  54. else:
  55. # No namespace pollution on Py2
  56. __all__ = []