コード例 #1
0
ファイル: addons.py プロジェクト: weloverandom/mitmproxy
 def invoke(self, addon, name, *args, **kwargs):
     func = getattr(addon, name, None)
     if func:
         if not callable(func):
             raise exceptions.AddonError("Addon handler %s not callable" %
                                         name)
         func(*args, **kwargs)
コード例 #2
0
 def invoke_addon(self, addon, name, *args, **kwargs):
     """
         Invoke an event on an addon. This method must run within an
         established handler context.
     """
     if not ctx.master:
         raise exceptions.AddonError(
             "invoke_addon called without a handler context.")
     if name not in eventsequence.Events:
         name = "event_" + name
     func = getattr(addon, name, None)
     if func:
         if not callable(func):
             raise exceptions.AddonError("Addon handler %s not callable" %
                                         name)
         func(*args, **kwargs)
コード例 #3
0
ファイル: addonmanager.py プロジェクト: syahn/mitmproxy
 def invoke(self, addon, name, *args, **kwargs):
     if name not in eventsequence.Events:  # prama: no cover
         raise NotImplementedError("Unknown event")
     func = getattr(addon, name, None)
     if func:
         if not callable(func):
             raise exceptions.AddonError("Addon handler %s not callable" %
                                         name)
         func(*args, **kwargs)
コード例 #4
0
def parse_command(command):
    """
        Returns a (path, args) tuple.
    """
    if not command or not command.strip():
        raise exceptions.AddonError("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("\\")
        command = command.replace("\\", "\\\\", backslashes)
    args = shlex.split(command)  # pragma: no cover
    args[0] = os.path.expanduser(args[0])
    if not os.path.exists(args[0]):
        raise exceptions.AddonError((
            "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 exceptions.AddonError("Not a file: %s" % args[0])
    return args[0], args[1:]
コード例 #5
0
 def invoke_addon(self, addon, name, *args, **kwargs):
     """
         Invoke an event on an addon and all its children. This method must
         run within an established handler context.
     """
     if name not in eventsequence.Events:
         name = "event_" + name
     for a in traverse([addon]):
         func = getattr(a, name, None)
         if func:
             if not callable(func):
                 raise exceptions.AddonError(
                     "Addon handler %s not callable" % name)
             func(*args, **kwargs)
コード例 #6
0
    def remove(self, addon):
        """
            Remove an addon and all its sub-addons.

            If the addon is not in the chain - that is, if it's managed by a
            parent addon - it's the parent's responsibility to remove it from
            its own addons attribute.
        """
        for a in traverse([addon]):
            n = _get_name(a)
            if n not in self.lookup:
                raise exceptions.AddonError("No such addon: %s" % n)
            self.chain = [i for i in self.chain if i is not a]
            del self.lookup[_get_name(a)]
        with self.master.handlecontext():
            self.invoke_addon(a, "done")
コード例 #7
0
    def register(self, addon):
        """
            Register an addon, call its load event, and then register all its
            sub-addons. This should be used by addons that dynamically manage
            addons.

            If the calling addon is already running, it should follow with
            running and configure events. Must be called within a current
            context.
        """
        for a in traverse([addon]):
            name = _get_name(a)
            if name in self.lookup:
                raise exceptions.AddonError(
                    "An addon called '%s' already exists." % name)
        l = Loader(self.master)
        self.invoke_addon(addon, "load", l)
        for a in traverse([addon]):
            name = _get_name(a)
            self.lookup[name] = a
        return addon