Commit 641ab849 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #946 from kmod/custom_builtins

Add a check to make sure users don't request custom __builtins__
parents 8c8e595a 238196dc
......@@ -561,8 +561,14 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
Box* globals_dict = globals;
if (globals->cls == module_cls)
globals_dict = globals->getAttrWrapper();
if (PyDict_GetItemString(globals_dict, "__builtins__") == NULL)
auto requested_builtins = PyDict_GetItemString(globals_dict, "__builtins__");
if (requested_builtins == NULL)
PyDict_SetItemString(globals_dict, "__builtins__", builtins_module);
else
RELEASE_ASSERT(requested_builtins == builtins_module
|| requested_builtins == builtins_module->getAttrWrapper(),
"we don't support overriding __builtins__");
}
}
......
diff --git a/babel/messages/extract.py b/babel/messages/extract.py
index 2f8084a..22fc289 100644
--- a/babel/messages/extract.py
+++ b/babel/messages/extract.py
@@ -421,7 +421,7 @@ def extract_python(fileobj, keywords, comment_tags, options):
# https://sourceforge.net/tracker/?func=detail&atid=355470&
# aid=617979&group_id=5470
value = eval('# coding=%s\n%s' % (str(encoding), value),
- {'__builtins__':{}}, {})
+ {}, {})
if PY2 and not isinstance(value, text_type):
value = value.decode(encoding)
buf.append(value)
......@@ -12,6 +12,9 @@ NOSETESTS_EXE = os.path.abspath(os.path.join(ENV_NAME, "bin", "nosetests"))
packages = ["nose==1.3.7", "pytz==2015.4", "-e", "git+http://github.com/mitsuhiko/babel.git@1.3#egg=Babel"]
create_virtenv(ENV_NAME, packages, force_create = True)
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "babel.patch"))
subprocess.check_call(["patch", "-p1", "--input=" + PATCH_FILE], cwd=BABEL_DIR)
subprocess.check_call([PYTHON_EXE, "setup.py", "import_cldr"], cwd=BABEL_DIR)
subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=BABEL_DIR)
subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=BABEL_DIR)
......
......@@ -129,3 +129,11 @@ print format(5.011111111111, '+.6')
print format("abc", '')
print '{n}'.format(n=None)
# Thankfully, setting __builtins__ has no effect:
__builtins__ = {'zzz': 2}
try:
print zzz
assert 0
except NameError as e:
print "caught NameError"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment