Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/future/builtins/misc.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
1 """ | |
2 A module that brings in equivalents of various modified Python 3 builtins | |
3 into Py2. Has no effect on Py3. | |
4 | |
5 The builtin functions are: | |
6 | |
7 - ``ascii`` (from Py2's future_builtins module) | |
8 - ``hex`` (from Py2's future_builtins module) | |
9 - ``oct`` (from Py2's future_builtins module) | |
10 - ``chr`` (equivalent to ``unichr`` on Py2) | |
11 - ``input`` (equivalent to ``raw_input`` on Py2) | |
12 - ``next`` (calls ``__next__`` if it exists, else ``next`` method) | |
13 - ``open`` (equivalent to io.open on Py2) | |
14 - ``super`` (backport of Py3's magic zero-argument super() function | |
15 - ``round`` (new "Banker's Rounding" behaviour from Py3) | |
16 - ``max`` (new default option from Py3.4) | |
17 - ``min`` (new default option from Py3.4) | |
18 | |
19 ``isinstance`` is also currently exported for backwards compatibility | |
20 with v0.8.2, although this has been deprecated since v0.9. | |
21 | |
22 | |
23 input() | |
24 ------- | |
25 Like the new ``input()`` function from Python 3 (without eval()), except | |
26 that it returns bytes. Equivalent to Python 2's ``raw_input()``. | |
27 | |
28 Warning: By default, importing this module *removes* the old Python 2 | |
29 input() function entirely from ``__builtin__`` for safety. This is | |
30 because forgetting to import the new ``input`` from ``future`` might | |
31 otherwise lead to a security vulnerability (shell injection) on Python 2. | |
32 | |
33 To restore it, you can retrieve it yourself from | |
34 ``__builtin__._old_input``. | |
35 | |
36 Fortunately, ``input()`` seems to be seldom used in the wild in Python | |
37 2... | |
38 | |
39 """ | |
40 | |
41 from future import utils | |
42 | |
43 | |
44 if utils.PY2: | |
45 from io import open | |
46 from future_builtins import ascii, oct, hex | |
47 from __builtin__ import unichr as chr, pow as _builtin_pow | |
48 import __builtin__ | |
49 | |
50 # Only for backward compatibility with future v0.8.2: | |
51 isinstance = __builtin__.isinstance | |
52 | |
53 # Warning: Python 2's input() is unsafe and MUST not be able to be used | |
54 # accidentally by someone who expects Python 3 semantics but forgets | |
55 # to import it on Python 2. Versions of ``future`` prior to 0.11 | |
56 # deleted it from __builtin__. Now we keep in __builtin__ but shadow | |
57 # the name like all others. Just be sure to import ``input``. | |
58 | |
59 input = raw_input | |
60 | |
61 from future.builtins.newnext import newnext as next | |
62 from future.builtins.newround import newround as round | |
63 from future.builtins.newsuper import newsuper as super | |
64 from future.builtins.new_min_max import newmax as max | |
65 from future.builtins.new_min_max import newmin as min | |
66 from future.types.newint import newint | |
67 | |
68 _SENTINEL = object() | |
69 | |
70 def pow(x, y, z=_SENTINEL): | |
71 """ | |
72 pow(x, y[, z]) -> number | |
73 | |
74 With two arguments, equivalent to x**y. With three arguments, | |
75 equivalent to (x**y) % z, but may be more efficient (e.g. for ints). | |
76 """ | |
77 # Handle newints | |
78 if isinstance(x, newint): | |
79 x = long(x) | |
80 if isinstance(y, newint): | |
81 y = long(y) | |
82 if isinstance(z, newint): | |
83 z = long(z) | |
84 | |
85 try: | |
86 if z == _SENTINEL: | |
87 return _builtin_pow(x, y) | |
88 else: | |
89 return _builtin_pow(x, y, z) | |
90 except ValueError: | |
91 if z == _SENTINEL: | |
92 return _builtin_pow(x+0j, y) | |
93 else: | |
94 return _builtin_pow(x+0j, y, z) | |
95 | |
96 | |
97 # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this: | |
98 # callable = __builtin__.callable | |
99 | |
100 __all__ = ['ascii', 'chr', 'hex', 'input', 'isinstance', 'next', 'oct', | |
101 'open', 'pow', 'round', 'super', 'max', 'min'] | |
102 | |
103 else: | |
104 import builtins | |
105 ascii = builtins.ascii | |
106 chr = builtins.chr | |
107 hex = builtins.hex | |
108 input = builtins.input | |
109 next = builtins.next | |
110 # Only for backward compatibility with future v0.8.2: | |
111 isinstance = builtins.isinstance | |
112 oct = builtins.oct | |
113 open = builtins.open | |
114 pow = builtins.pow | |
115 round = builtins.round | |
116 super = builtins.super | |
117 if utils.PY34_PLUS: | |
118 max = builtins.max | |
119 min = builtins.min | |
120 __all__ = [] | |
121 else: | |
122 from future.builtins.new_min_max import newmax as max | |
123 from future.builtins.new_min_max import newmin as min | |
124 __all__ = ['min', 'max'] | |
125 | |
126 # The callable() function was removed from Py3.0 and 3.1 and | |
127 # reintroduced into Py3.2+. ``future`` doesn't support Py3.0/3.1. If we ever | |
128 # did, we'd add this: | |
129 # try: | |
130 # callable = builtins.callable | |
131 # except AttributeError: | |
132 # # Definition from Pandas | |
133 # def callable(obj): | |
134 # return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) | |
135 # __all__.append('callable') |