future_builtins.py 903 B

12345678910111213141516171819202122232425262728293031323334
  1. """This module provides functions that will be builtins in Python 3.0,
  2. but that conflict with builtins that already exist in Python 2.x.
  3. Functions:
  4. hex(arg) -- Returns the hexadecimal representation of an integer
  5. oct(arg) -- Returns the octal representation of an integer
  6. ascii(arg) -- Same as repr(arg)
  7. map, filter, zip -- Same as itertools.imap, ifilter, izip
  8. The typical usage of this module is to replace existing builtins in a
  9. module's namespace:
  10. from future_builtins import hex, oct
  11. """
  12. __all__ = ['hex', 'oct', 'ascii', 'map', 'filter', 'zip']
  13. from itertools import imap as map, ifilter as filter, izip as zip
  14. ascii = repr
  15. _builtin_hex = hex
  16. _builtin_oct = oct
  17. def hex(arg):
  18. return _builtin_hex(arg).rstrip('L')
  19. def oct(arg):
  20. result = _builtin_oct(arg).rstrip('L')
  21. if result == '0':
  22. return '0o0'
  23. i = result.index('0') + 1
  24. return result[:i] + 'o' + result[i:]