mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +09:00
Issue #1761 - Enable use of Tauthon instead of Python 2.7 at build
Make essential Tauthon's builtins and modules available in sandboxes, without disrupting building with Python 2.7. 1. Allow new builtins and modules. "__build_class__" is for building... new-style classes (to handle the new metaclass syntax imported from 3.x). "_oserror" is necessary because of internal changes to raise errors deriving from OSError (which are reported as IOError if not caught). 2. Look for modules and packages in the right places. This was tested on FreeBSD, and should work out of the box on Linux.
This commit is contained in:
parent
2fea3f29bc
commit
d094352ddf
4 changed files with 30 additions and 16 deletions
|
|
@ -192,8 +192,9 @@ class ConfigureSandbox(dict):
|
|||
b: __builtins__[b]
|
||||
for b in ('None', 'False', 'True', 'int', 'bool', 'any', 'all', 'len',
|
||||
'list', 'tuple', 'set', 'dict', 'isinstance', 'getattr',
|
||||
'hasattr', 'enumerate', 'range', 'zip')
|
||||
}, __import__=forbidden_import, str=unicode)
|
||||
'hasattr', 'enumerate', 'range', 'zip', '__build_class__')
|
||||
if b in __builtins__},
|
||||
__import__=forbidden_import, str=unicode)
|
||||
|
||||
# Expose a limited set of functions from os.path
|
||||
OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,10 @@ class Sandbox(dict):
|
|||
def __init__(self, context, builtins=None, finder=default_finder):
|
||||
"""Initialize a Sandbox ready for execution.
|
||||
"""
|
||||
self._builtins = builtins or self.BUILTINS
|
||||
self._builtins = ReadOnlyDict(
|
||||
(builtins or self.BUILTINS).viewitems() |
|
||||
{b: __builtins__[b] for b in ('__build_class__',)
|
||||
if b in __builtins__}.viewitems())
|
||||
dict.__setitem__(self, '__builtins__', self._builtins)
|
||||
|
||||
assert isinstance(self._builtins, ReadOnlyDict)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue