comparison planemo/lib/python3.7/site-packages/past/builtins/misc.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 from __future__ import unicode_literals
2
3 import inspect
4
5 from future.utils import PY2, PY3, exec_
6
7 if PY2:
8 from collections import Mapping
9 else:
10 from collections.abc import Mapping
11
12 if PY3:
13 import builtins
14 from collections.abc import Mapping
15
16 def apply(f, *args, **kw):
17 return f(*args, **kw)
18
19 from past.builtins import str as oldstr
20
21 def chr(i):
22 """
23 Return a byte-string of one character with ordinal i; 0 <= i <= 256
24 """
25 return oldstr(bytes((i,)))
26
27 def cmp(x, y):
28 """
29 cmp(x, y) -> integer
30
31 Return negative if x<y, zero if x==y, positive if x>y.
32 """
33 return (x > y) - (x < y)
34
35 from sys import intern
36
37 def oct(number):
38 """oct(number) -> string
39
40 Return the octal representation of an integer
41 """
42 return '0' + builtins.oct(number)[2:]
43
44 raw_input = input
45 from imp import reload
46 unicode = str
47 unichr = chr
48 xrange = range
49 else:
50 import __builtin__
51 from collections import Mapping
52 apply = __builtin__.apply
53 chr = __builtin__.chr
54 cmp = __builtin__.cmp
55 execfile = __builtin__.execfile
56 intern = __builtin__.intern
57 oct = __builtin__.oct
58 raw_input = __builtin__.raw_input
59 reload = __builtin__.reload
60 unicode = __builtin__.unicode
61 unichr = __builtin__.unichr
62 xrange = __builtin__.xrange
63
64
65 if PY3:
66 def execfile(filename, myglobals=None, mylocals=None):
67 """
68 Read and execute a Python script from a file in the given namespaces.
69 The globals and locals are dictionaries, defaulting to the current
70 globals and locals. If only globals is given, locals defaults to it.
71 """
72 if myglobals is None:
73 # There seems to be no alternative to frame hacking here.
74 caller_frame = inspect.stack()[1]
75 myglobals = caller_frame[0].f_globals
76 mylocals = caller_frame[0].f_locals
77 elif mylocals is None:
78 # Only if myglobals is given do we set mylocals to it.
79 mylocals = myglobals
80 if not isinstance(myglobals, Mapping):
81 raise TypeError('globals must be a mapping')
82 if not isinstance(mylocals, Mapping):
83 raise TypeError('locals must be a mapping')
84 with open(filename, "rb") as fin:
85 source = fin.read()
86 code = compile(source, filename, "exec")
87 exec_(code, myglobals, mylocals)
88
89
90 if PY3:
91 __all__ = ['apply', 'chr', 'cmp', 'execfile', 'intern', 'raw_input',
92 'reload', 'unichr', 'unicode', 'xrange']
93 else:
94 __all__ = []