File: future_builtins.py

package info (click to toggle)
jython 2.7.3%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 62,820 kB
  • sloc: python: 641,384; java: 306,981; xml: 2,066; sh: 514; ansic: 126; makefile: 77
file content (33 lines) | stat: -rw-r--r-- 903 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""This module provides functions that will be builtins in Python 3.0,
but that conflict with builtins that already exist in Python 2.x.

Functions:

hex(arg) -- Returns the hexadecimal representation of an integer
oct(arg) -- Returns the octal representation of an integer
ascii(arg) -- Same as repr(arg)
map, filter, zip -- Same as itertools.imap, ifilter, izip

The typical usage of this module is to replace existing builtins in a
module's namespace:

from future_builtins import hex, oct
"""

__all__ = ['hex', 'oct', 'ascii', 'map', 'filter', 'zip']

from itertools import imap as map, ifilter as filter, izip as zip

ascii = repr
_builtin_hex = hex
_builtin_oct = oct

def hex(arg):
    return _builtin_hex(arg).rstrip('L')

def oct(arg):
    result = _builtin_oct(arg).rstrip('L')
    if result == '0':
        return '0o0'
    i = result.index('0') + 1
    return result[:i] + 'o' + result[i:]