diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-12-13 15:06:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-13 15:06:14 +0100 |
commit | 727abdba44fa72321f51402b03e9d39c6489dc95 (patch) | |
tree | 23a6d50af83bffd0521cc3cc750423bdc95b2a8b /mitmproxy | |
parent | e2c6d7ed0f6d4fb4375d8bb1f372a47f6d43b85b (diff) | |
parent | 44f94c884481c768991a4817bb4772d0c3e59bef (diff) | |
download | mitmproxy-727abdba44fa72321f51402b03e9d39c6489dc95.tar.gz mitmproxy-727abdba44fa72321f51402b03e9d39c6489dc95.tar.bz2 mitmproxy-727abdba44fa72321f51402b03e9d39c6489dc95.zip |
Merge pull request #1852 from mhils/simplenamespace
Use types.SimpleNamespace instead of custom NS class
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/addons/script.py | 18 |
1 files changed, 3 insertions, 15 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): |