diff --git a/warped/actions.py b/warped/actions.py index 18cbfd2..14e6de3 100644 --- a/warped/actions.py +++ b/warped/actions.py @@ -98,6 +98,8 @@ class StoreAction(Action): class StoreConstAction(Action): def store_type_function(self, x): + if x == 'false': + x = None return self.const if x is not None else self.on_none def __init__(self, action, **kwargs): diff --git a/warped/context.py b/warped/context.py index fbfe911..66dc86d 100644 --- a/warped/context.py +++ b/warped/context.py @@ -1,6 +1,5 @@ import argparse import sys -import io import runpy from traceback import print_exc from contextlib import redirect_stdout, redirect_stderr @@ -24,9 +23,284 @@ class Context(Process): sys.argv = [''] + self.arguments else: sys.argv = [''] - #if not self.original_modules is None: - # sys.modules = self.original_modules - # print(sys.modules) + # if not self.original_modules is None: + # sys.modules.clear() + # sys.modules.update(self.original_modules) + + del sys.modules['io'] + del sys.modules['abc'] + del sys.modules['_weakrefset'] + del sys.modules['site'] + del sys.modules['os'] + del sys.modules['errno'] + del sys.modules['stat'] + del sys.modules['_stat'] + del sys.modules['posixpath'] + del sys.modules['genericpath'] + del sys.modules['os.path'] + del sys.modules['_collections_abc'] + del sys.modules['_bootlocale'] + del sys.modules['_locale'] + del sys.modules['re'] + del sys.modules['enum'] + del sys.modules['types'] + del sys.modules['functools'] + del sys.modules['_functools'] + del sys.modules['collections'] + del sys.modules['operator'] + del sys.modules['_operator'] + del sys.modules['keyword'] + del sys.modules['heapq'] + del sys.modules['_heapq'] + del sys.modules['itertools'] + del sys.modules['reprlib'] + del sys.modules['_collections'] + del sys.modules['weakref'] + del sys.modules['collections.abc'] + del sys.modules['sre_compile'] + del sys.modules['_sre'] + del sys.modules['sre_parse'] + del sys.modules['sre_constants'] + del sys.modules['copyreg'] + del sys.modules['pkg_resources'] + del sys.modules['__future__'] + del sys.modules['time'] + del sys.modules['zipfile'] + del sys.modules['importlib'] + del sys.modules['importlib._bootstrap'] + del sys.modules['importlib._bootstrap_external'] + del sys.modules['warnings'] + del sys.modules['importlib.util'] + del sys.modules['importlib.abc'] + del sys.modules['importlib.machinery'] + del sys.modules['contextlib'] + del sys.modules['shutil'] + del sys.modules['fnmatch'] + del sys.modules['zlib'] + del sys.modules['bz2'] + del sys.modules['_compression'] + del sys.modules['threading'] + del sys.modules['linecache'] + del sys.modules['tokenize'] + del sys.modules['token'] + del sys.modules['_bz2'] + del sys.modules['lzma'] + del sys.modules['_lzma'] + del sys.modules['pwd'] + del sys.modules['grp'] + del sys.modules['struct'] + del sys.modules['_struct'] + del sys.modules['binascii'] + del sys.modules['pkgutil'] + del sys.modules['platform'] + del sys.modules['subprocess'] + del sys.modules['signal'] + del sys.modules['_posixsubprocess'] + del sys.modules['select'] + del sys.modules['selectors'] + del sys.modules['math'] + del sys.modules['plistlib'] + del sys.modules['datetime'] + del sys.modules['_datetime'] + del sys.modules['xml'] + del sys.modules['xml.parsers'] + del sys.modules['xml.parsers.expat'] + del sys.modules['pyexpat.errors'] + del sys.modules['pyexpat.model'] + del sys.modules['pyexpat'] + del sys.modules['xml.parsers.expat.model'] + del sys.modules['xml.parsers.expat.errors'] + del sys.modules['email'] + del sys.modules['email.parser'] + del sys.modules['email.feedparser'] + del sys.modules['email.errors'] + del sys.modules['email._policybase'] + del sys.modules['email.header'] + del sys.modules['email.quoprimime'] + del sys.modules['string'] + del sys.modules['_string'] + del sys.modules['email.base64mime'] + del sys.modules['base64'] + del sys.modules['email.charset'] + del sys.modules['email.encoders'] + del sys.modules['quopri'] + del sys.modules['email.utils'] + del sys.modules['random'] + del sys.modules['hashlib'] + del sys.modules['_hashlib'] + del sys.modules['_blake2'] + del sys.modules['_sha3'] + del sys.modules['bisect'] + del sys.modules['_bisect'] + del sys.modules['_random'] + del sys.modules['socket'] + del sys.modules['_socket'] + del sys.modules['urllib'] + del sys.modules['urllib.parse'] + del sys.modules['email._parseaddr'] + del sys.modules['calendar'] + del sys.modules['locale'] + del sys.modules['tempfile'] + del sys.modules['textwrap'] + del sys.modules['six'] + del sys.modules['six.moves'] + del sys.modules['six.moves.urllib'] + del sys.modules['packaging'] + del sys.modules['packaging.__about__'] + del sys.modules['packaging.version'] + del sys.modules['packaging._structures'] + del sys.modules['packaging.specifiers'] + del sys.modules['packaging._compat'] + del sys.modules['packaging.requirements'] + del sys.modules['pyparsing'] + del sys.modules['copy'] + del sys.modules['pprint'] + del sys.modules['packaging.markers'] + del sys.modules['appdirs'] + del sys.modules['sysconfig'] + del sys.modules['email.message'] + del sys.modules['uu'] + del sys.modules['email._encoded_words'] + del sys.modules['email.iterators'] + del sys.modules['argparse'] + del sys.modules['gettext'] + del sys.modules['pickle'] + del sys.modules['_compat_pickle'] + del sys.modules['_pickle'] + del sys.modules['array'] + del sys.modules['__mp_main__'] + del sys.modules['queue'] + del sys.modules['ctypes'] + del sys.modules['_ctypes'] + del sys.modules['ctypes._endian'] + del sys.modules['ctypes.util'] + del sys.modules['json'] + del sys.modules['json.decoder'] + del sys.modules['json.scanner'] + del sys.modules['_json'] + del sys.modules['json.encoder'] + del sys.modules['flask'] + del sys.modules['werkzeug'] + del sys.modules['werkzeug._compat'] + del sys.modules['werkzeug.exceptions'] + del sys.modules['werkzeug._internal'] + del sys.modules['inspect'] + del sys.modules['ast'] + del sys.modules['_ast'] + del sys.modules['dis'] + del sys.modules['opcode'] + del sys.modules['_opcode'] + del sys.modules['werkzeug.wrappers'] + del sys.modules['werkzeug.http'] + del sys.modules['urllib.request'] + del sys.modules['http'] + del sys.modules['http.client'] + del sys.modules['ssl'] + del sys.modules['ipaddress'] + del sys.modules['_ssl'] + del sys.modules['urllib.error'] + del sys.modules['urllib.response'] + del sys.modules['werkzeug.datastructures'] + del sys.modules['mimetypes'] + del sys.modules['werkzeug.filesystem'] + del sys.modules['werkzeug.urls'] + del sys.modules['werkzeug.formparser'] + del sys.modules['werkzeug.wsgi'] + del sys.modules['werkzeug.utils'] + del sys.modules['html'] + del sys.modules['html.entities'] + del sys.modules['jinja2'] + del sys.modules['jinja2.environment'] + del sys.modules['jinja2.nodes'] + del sys.modules['jinja2.utils'] + del sys.modules['jinja2._compat'] + del sys.modules['markupsafe'] + del sys.modules['markupsafe._compat'] + del sys.modules['markupsafe._speedups'] + del sys.modules['jinja2.defaults'] + del sys.modules['jinja2.filters'] + del sys.modules['jinja2.runtime'] + del sys.modules['jinja2.exceptions'] + del sys.modules['jinja2.tests'] + del sys.modules['decimal'] + del sys.modules['_pydecimal'] + del sys.modules['numbers'] + del sys.modules['jinja2.lexer'] + del sys.modules['unicodedata'] + del sys.modules['jinja2.parser'] + del sys.modules['jinja2.compiler'] + del sys.modules['jinja2.visitor'] + del sys.modules['jinja2.optimizer'] + del sys.modules['jinja2.idtracking'] + del sys.modules['jinja2.loaders'] + del sys.modules['jinja2.bccache'] + del sys.modules['jinja2.asyncsupport'] + del sys.modules['asyncio'] + del sys.modules['asyncio.base_events'] + del sys.modules['concurrent'] + del sys.modules['concurrent.futures'] + del sys.modules['concurrent.futures._base'] + del sys.modules['logging'] + del sys.modules['atexit'] + del sys.modules['concurrent.futures.process'] + del sys.modules['multiprocessing.connection'] + del sys.modules['_multiprocessing'] + del sys.modules['multiprocessing.util'] + del sys.modules['concurrent.futures.thread'] + del sys.modules['asyncio.compat'] + del sys.modules['asyncio.coroutines'] + del sys.modules['asyncio.events'] + del sys.modules['asyncio.base_futures'] + del sys.modules['asyncio.log'] + del sys.modules['asyncio.futures'] + del sys.modules['asyncio.base_tasks'] + del sys.modules['_asyncio'] + del sys.modules['asyncio.tasks'] + del sys.modules['asyncio.locks'] + del sys.modules['asyncio.protocols'] + del sys.modules['asyncio.queues'] + del sys.modules['asyncio.streams'] + del sys.modules['asyncio.subprocess'] + del sys.modules['asyncio.transports'] + del sys.modules['asyncio.unix_events'] + del sys.modules['asyncio.base_subprocess'] + del sys.modules['asyncio.constants'] + del sys.modules['asyncio.selector_events'] + del sys.modules['asyncio.sslproto'] + del sys.modules['jinja2.asyncfilters'] + del sys.modules['flask.app'] + del sys.modules['werkzeug.routing'] + del sys.modules['difflib'] + del sys.modules['flask.helpers'] + del sys.modules['flask.signals'] + del sys.modules['flask.globals'] + del sys.modules['werkzeug.local'] + del sys.modules['flask._compat'] + del sys.modules['flask.json'] + del sys.modules['itsdangerous'] + del sys.modules['hmac'] + del sys.modules['flask.cli'] + del sys.modules['click'] + del sys.modules['click.core'] + del sys.modules['click.types'] + del sys.modules['click._compat'] + del sys.modules['click.exceptions'] + del sys.modules['click.utils'] + del sys.modules['click.globals'] + del sys.modules['click.termui'] + del sys.modules['click.formatting'] + del sys.modules['click.parser'] + del sys.modules['click._unicodefun'] + del sys.modules['click.decorators'] + del sys.modules['flask.wrappers'] + del sys.modules['flask.config'] + del sys.modules['flask.ctx'] + del sys.modules['flask.sessions'] + del sys.modules['flask.templating'] + del sys.modules['flask.blueprints'] + del sys.modules['werkzeug.serving'] + + print(sys.modules.keys()) sys.modules.update(self.overwritten_modules) with redirect_stdout(self.stdout): with redirect_stderr(self.stderr): diff --git a/warped/hook.py b/warped/hook.py index 06098e9..7c1cf2e 100644 --- a/warped/hook.py +++ b/warped/hook.py @@ -1,3 +1,4 @@ +from . import savemodules import sys import io @@ -24,9 +25,15 @@ class QueuedOut(io.StringIO): lines = b.split('\n') for line in lines[:-1]: super().write(line) - self.flush() + self.explflush() super().write(lines[-1]) + def explflush(self): + value = self.getvalue() + self.queue.put((self.name, value)) + self.seek(0) + self.truncate(0) + def flush(self): value = self.getvalue() if len(value) > 1: @@ -100,7 +107,7 @@ def start_module(name, is_module): ioerr, overwritten_modules={'argparse': argparser}, is_module = is_module, - #original_modules = emptymodules + original_modules = savemodules.savedmodules ) views.app.module_process.start() views.app.output.start() diff --git a/warped/savemodules.py b/warped/savemodules.py new file mode 100644 index 0000000..e11ff01 --- /dev/null +++ b/warped/savemodules.py @@ -0,0 +1,2 @@ +import sys +savedmodules = dict(sys.modules)