Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: third_party/google-endpoints/future/builtins/disabled.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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__ = []
OLDNEW
« no previous file with comments | « third_party/google-endpoints/future/builtins/__init__.py ('k') | third_party/google-endpoints/future/builtins/iterators.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698