diff options
Diffstat (limited to 'mitmproxy/script')
-rw-r--r-- | mitmproxy/script/__init__.py | 4 | ||||
-rw-r--r-- | mitmproxy/script/concurrent.py | 1 | ||||
-rw-r--r-- | mitmproxy/script/reloader.py | 4 | ||||
-rw-r--r-- | mitmproxy/script/script.py | 22 | ||||
-rw-r--r-- | mitmproxy/script/script_context.py | 3 |
5 files changed, 21 insertions, 13 deletions
diff --git a/mitmproxy/script/__init__.py b/mitmproxy/script/__init__.py index 3ee19b04..d6bff4c7 100644 --- a/mitmproxy/script/__init__.py +++ b/mitmproxy/script/__init__.py @@ -1,8 +1,8 @@ +from . import reloader +from .concurrent import concurrent from .script import Script from .script_context import ScriptContext -from .concurrent import concurrent from ..exceptions import ScriptException -from . import reloader __all__ = [ "Script", diff --git a/mitmproxy/script/concurrent.py b/mitmproxy/script/concurrent.py index 2f25e78c..43d0d328 100644 --- a/mitmproxy/script/concurrent.py +++ b/mitmproxy/script/concurrent.py @@ -3,6 +3,7 @@ This module provides a @concurrent decorator primitive to offload computations from mitmproxy's main master thread. """ from __future__ import absolute_import, print_function, division + import threading diff --git a/mitmproxy/script/reloader.py b/mitmproxy/script/reloader.py index 99ce7f60..f5470bbf 100644 --- a/mitmproxy/script/reloader.py +++ b/mitmproxy/script/reloader.py @@ -1,6 +1,10 @@ +from __future__ import absolute_import, print_function, division + import os import sys + from watchdog.events import RegexMatchingEventHandler + if sys.platform == 'darwin': # pragma: no cover from watchdog.observers.polling import PollingObserver as Observer else: diff --git a/mitmproxy/script/script.py b/mitmproxy/script/script.py index 9bf05f27..70f74817 100644 --- a/mitmproxy/script/script.py +++ b/mitmproxy/script/script.py @@ -4,13 +4,15 @@ Script objects know nothing about mitmproxy or mitmproxy's API - this knowledge by the mitmproxy-specific ScriptContext. """ # Do not import __future__ here, this would apply transitively to the inline scripts. +from __future__ import absolute_import, print_function, division + import os import shlex import sys import six -from ..exceptions import ScriptException +from mitmproxy import exceptions class Script(object): @@ -41,7 +43,7 @@ class Script(object): @staticmethod def parse_command(command): if not command or not command.strip(): - raise ScriptException("Empty script command.") + raise exceptions.ScriptException("Empty script command.") # Windows: escape all backslashes in the path. if os.name == "nt": # pragma: no cover backslashes = shlex.split(command, posix=False)[0].count("\\") @@ -49,13 +51,13 @@ class Script(object): args = shlex.split(command) # pragma: no cover args[0] = os.path.expanduser(args[0]) if not os.path.exists(args[0]): - raise ScriptException( + raise exceptions.ScriptException( ("Script file not found: %s.\r\n" "If your script path contains spaces, " "make sure to wrap it in additional quotes, e.g. -s \"'./foo bar/baz.py' --args\".") % args[0]) elif os.path.isdir(args[0]): - raise ScriptException("Not a file: %s" % args[0]) + raise exceptions.ScriptException("Not a file: %s" % args[0]) return args def load(self): @@ -69,7 +71,7 @@ class Script(object): ScriptException on failure """ if self.ns is not None: - raise ScriptException("Script is already loaded") + raise exceptions.ScriptException("Script is already loaded") script_dir = os.path.dirname(os.path.abspath(self.args[0])) self.ns = {'__file__': os.path.abspath(self.args[0])} sys.path.append(script_dir) @@ -80,8 +82,8 @@ class Script(object): exec(code, self.ns, self.ns) except Exception: six.reraise( - ScriptException, - ScriptException.from_exception_context(), + exceptions.ScriptException, + exceptions.ScriptException.from_exception_context(), sys.exc_info()[2] ) finally: @@ -107,15 +109,15 @@ class Script(object): ScriptException if there was an exception. """ if self.ns is None: - raise ScriptException("Script not loaded.") + raise exceptions.ScriptException("Script not loaded.") f = self.ns.get(name) if f: try: return f(self.ctx, *args, **kwargs) except Exception: six.reraise( - ScriptException, - ScriptException.from_exception_context(), + exceptions.ScriptException, + exceptions.ScriptException.from_exception_context(), sys.exc_info()[2] ) else: diff --git a/mitmproxy/script/script_context.py b/mitmproxy/script/script_context.py index cd5d4b61..44e2736b 100644 --- a/mitmproxy/script/script_context.py +++ b/mitmproxy/script/script_context.py @@ -2,7 +2,8 @@ The mitmproxy script context provides an API to inline scripts. """ from __future__ import absolute_import, print_function, division -from .. import contentviews + +from mitmproxy import contentviews class ScriptContext(object): |