comparison env/lib/python3.7/site-packages/future/builtins/disabled.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 This disables builtin functions (and one exception class) which are
3 removed from Python 3.3.
4
5 This module is designed to be used like this::
6
7 from future.builtins.disabled import *
8
9 This disables the following obsolete Py2 builtin functions::
10
11 apply, cmp, coerce, execfile, file, input, long,
12 raw_input, reduce, reload, unicode, xrange
13
14 We don't hack __builtin__, which is very fragile because it contaminates
15 imported modules too. Instead, we just create new functions with
16 the same names as the obsolete builtins from Python 2 which raise
17 NameError exceptions when called.
18
19 Note that both ``input()`` and ``raw_input()`` are among the disabled
20 functions (in this module). Although ``input()`` exists as a builtin in
21 Python 3, the Python 2 ``input()`` builtin is unsafe to use because it
22 can lead to shell injection. Therefore we shadow it by default upon ``from
23 future.builtins.disabled import *``, in case someone forgets to import our
24 replacement ``input()`` somehow and expects Python 3 semantics.
25
26 See the ``future.builtins.misc`` module for a working version of
27 ``input`` with Python 3 semantics.
28
29 (Note that callable() is not among the functions disabled; this was
30 reintroduced into Python 3.2.)
31
32 This exception class is also disabled:
33
34 StandardError
35
36 """
37
38 from __future__ import division, absolute_import, print_function
39
40 from future import utils
41
42
43 OBSOLETE_BUILTINS = ['apply', 'chr', 'cmp', 'coerce', 'execfile', 'file',
44 'input', 'long', 'raw_input', 'reduce', 'reload',
45 'unicode', 'xrange', 'StandardError']
46
47
48 def disabled_function(name):
49 '''
50 Returns a function that cannot be called
51 '''
52 def disabled(*args, **kwargs):
53 '''
54 A function disabled by the ``future`` module. This function is
55 no longer a builtin in Python 3.
56 '''
57 raise NameError('obsolete Python 2 builtin {0} is disabled'.format(name))
58 return disabled
59
60
61 if not utils.PY3:
62 for fname in OBSOLETE_BUILTINS:
63 locals()[fname] = disabled_function(fname)
64 __all__ = OBSOLETE_BUILTINS
65 else:
66 __all__ = []