Skip to content

Commit 87707b5

Browse files
committed
Add past.builtins.oct function
Also add docstring to ``cmp()``
1 parent 068c586 commit 87707b5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

past/builtins/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
else:
5252
from __builtin__ import (basestring, dict, str, long, unicode)
5353

54-
from past.builtins.misc import (apply, chr, cmp, execfile, intern, raw_input,
55-
reload, unichr, unicode, xrange)
54+
from past.builtins.misc import (apply, chr, cmp, execfile, intern, oct,
55+
raw_input, reload, unichr, unicode, xrange)
5656
from past import utils
5757

5858

past/builtins/misc.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,36 @@
77

88

99
if PY3:
10+
import builtins
11+
1012
def apply(f, *args, **kw):
1113
return f(*args, **kw)
14+
1215
from past.builtins import str as oldstr
16+
1317
def chr(i):
1418
"""
1519
Return a byte-string of one character with ordinal i; 0 <= i <= 256
1620
"""
1721
return oldstr(bytes((i,)))
18-
cmp = lambda a, b: (a > b) - (a < b)
22+
23+
def cmp(x, y):
24+
"""
25+
cmp(x, y) -> integer
26+
27+
Return negative if x<y, zero if x==y, positive if x>y.
28+
"""
29+
return (x > y) - (x < y)
30+
1931
from sys import intern
32+
33+
def oct(number):
34+
"""oct(number) -> string
35+
36+
Return the octal representation of an integer
37+
"""
38+
return '0' + builtins.oct(number)[2:]
39+
2040
raw_input = input
2141
from imp import reload
2242
unicode = str
@@ -29,6 +49,7 @@ def chr(i):
2949
cmp = __builtin__.cmp
3050
execfile = __builtin__.execfile
3151
intern = __builtin__.intern
52+
oct = __builtin__.oct
3253
raw_input = __builtin__.raw_input
3354
reload = __builtin__.reload
3455
unicode = __builtin__.unicode

0 commit comments

Comments
 (0)