diff options
| -rw-r--r-- | mitmproxy/addons/script.py | 18 | ||||
| -rw-r--r-- | test/mitmproxy/addons/test_script.py | 7 | ||||
| -rw-r--r-- | test/mitmproxy/test_examples.py | 2 | 
3 files changed, 4 insertions, 23 deletions
| diff --git a/mitmproxy/addons/script.py b/mitmproxy/addons/script.py index c89fa085..93245760 100644 --- a/mitmproxy/addons/script.py +++ b/mitmproxy/addons/script.py @@ -4,6 +4,7 @@ import shlex  import sys  import threading  import traceback +import types  from mitmproxy import exceptions  from mitmproxy import ctx @@ -14,19 +15,6 @@ import watchdog.events  from watchdog.observers import polling -class NS: -    def __init__(self, ns): -        self.__dict__["ns"] = ns - -    def __getattr__(self, key): -        if key not in self.ns: -            raise AttributeError("No such element: %s", key) -        return self.ns[key] - -    def __setattr__(self, key, value): -        self.__dict__["ns"][key] = value - -  def parse_command(command):      """          Returns a (path, args) tuple. @@ -113,8 +101,8 @@ def load_script(path, args):              return      ns = {'__file__': os.path.abspath(path)}      with scriptenv(path, args): -        exec(code, ns, ns) -    return NS(ns) +        exec(code, ns) +    return types.SimpleNamespace(**ns)  class ReloadHandler(watchdog.events.FileSystemEventHandler): diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index 06463fa3..777f8f4d 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -18,13 +18,6 @@ import watchdog.events  from .. import tutils as ttutils -def test_ns(): -    n = script.NS({}) -    n.one = "one" -    assert n.one == "one" -    assert n.__dict__["ns"]["one"] == "one" - -  def test_scriptenv():      with taddons.context() as tctx:          with script.scriptenv("path", []): diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 8db2507f..610c9dad 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -150,7 +150,7 @@ class TestHARDump:      def test_format_cookies(self):          m, sc = tscript("complex/har_dump.py", "-") -        format_cookies = sc.ns.ns["format_cookies"] +        format_cookies = sc.ns.format_cookies          CA = cookies.CookieAttrs | 
