Skip to content

Commit

Permalink
:add: minor version with runtime.safebuiltin function.
Browse files Browse the repository at this point in the history
  • Loading branch information
b3j0f committed Oct 29, 2015
1 parent e8d4d64 commit 20b5ab9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
40 changes: 37 additions & 3 deletions b3j0f/utils/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,47 @@
from types import FunctionType, ModuleType

try:
import __builtin__
import __builtin__ #: builtin module.
except ImportError:
import builtins as __builtin__
import builtins as __builtin__ #: builtin module.

from .version import PY3

__all__ = ['bind_all', 'make_constants']
__all__ = ['bind_all', 'make_constants', '__builtin__', 'safebuiltin']


IO_PROPS = [
'open', '__name__', '__debug__', '__doc__', '__import__', '__package__',
'compile', 'copyright', 'credits', 'eval', 'execfile', 'exit', 'file',
'globals', 'help', 'input', 'intern', 'license', 'locals', 'open', 'print',
'quit', 'raw_input', 'reload'
] #: set of builtin objects to remove from a safe builtin.

_SAFEBUILTIN = None #: protected safebuiltin.


def safebuiltin(renew=False):
"""Construct a safe builtin environment without I/O functions.
:param bool renew: renew the safebuiltin if True (False by default).
:rtype: dict
"""

result = _SAFEBUILTIN

if result is None or renew:

result = {}

objectnames = [
objectname for objectname in dir(__builtin__)
if objectname not in IO_PROPS
]

for objectname in objectnames:
result[objectname] = __builtin__[objectname]

return result

STORE_GLOBAL = opmap['STORE_GLOBAL']
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
Expand Down
19 changes: 10 additions & 9 deletions b3j0f/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@
# thanks to https://github.com/pycontribs/jira/blob/master/jira/version.py

#: project version
__version__ = '1.0.0'
__version__ = '1.1.0'


PY3 = version_info[0] == 3 #: python3
PY2 = version_info[0] == 2 #: python2
PY26 = PY2 and version_info[1] == 6 #: python2.6
PY27 = PY2 and version_info[1] == 7 #: python2.7
PYPY = python_implementation() == 'PyPy' #: pypy
CPYTHON = python_implementation() == 'CPython' #: cpython
JYTHON = python_implementation() == 'Jython' #: jython
IRONPYTHON = python_implementation() == 'IronPython' #: IronPython
PY3 = version_info[0] == 3 #: python3.
PY2 = version_info[0] == 2 #: python2.
PY26 = PY2 and version_info[1] == 6 #: python2.6.
PY27 = PY2 and version_info[1] == 7 #: python2.7.
PYPY = python_implementation() == 'PyPy' #: pypy.
CPYTHON = python_implementation() == 'CPython' #: cpython.
JYTHON = python_implementation() == 'Jython' #: jython.
IRONPYTHON = python_implementation() == 'IronPython' #: IronPython.


if PY3: # set references to common object with different names
# define python3 functions with python2 names
Expand Down
5 changes: 5 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
ChangeLog
=========

1.0.1 (2015/10/29)
------------------

- add the function safebuiltin and the module __builtin__ in the runtime module.

1.0.0 (2015/10/20)
------------------

Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
'Natural Language :: French',
'Operating System :: OS Independent',
'Topic :: Utilities',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
Expand All @@ -93,7 +93,9 @@
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5'
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy'
],
test_suite='b3j0f',
keywords=KEYWORDS
Expand Down

0 comments on commit 20b5ab9

Please sign in to comment.