diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-05-29 20:17:35 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-05-29 20:17:35 +1200 |
commit | 8638000cfa859ca2ae5fb39c58cbdf5e6fc10c19 (patch) | |
tree | d12c4d6a83d654c1027176899956b4f70172d6e8 | |
parent | f3bee6f24539005e0916e786805e1655bb7f80f8 (diff) | |
download | mitmproxy-8638000cfa859ca2ae5fb39c58cbdf5e6fc10c19.tar.gz mitmproxy-8638000cfa859ca2ae5fb39c58cbdf5e6fc10c19.tar.bz2 mitmproxy-8638000cfa859ca2ae5fb39c58cbdf5e6fc10c19.zip |
Add some comments to controller wrapper.
-rw-r--r-- | mitmproxy/controller.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index dcf920ef..a19c2f5a 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -170,6 +170,7 @@ NO_REPLY = object() def handler(f): @functools.wraps(f) def wrapper(*args, **kwargs): + # We can either be called as a method, or as a wrapped solo function if len(args) == 1: message = args[0] elif len(args) == 2: @@ -180,6 +181,9 @@ def handler(f): if not hasattr(message, "reply"): raise ControlError("Message %s has no reply attribute"%message) + # The following ensures that inheritance with wrapped handlers in the + # base class works. If we're the first handler, then responsibility for + # acking is ours. If not, it's someone else's and we ignore it. handling = False # We're the first handler - ack responsibility is ours if not message.reply.handled: @@ -191,6 +195,7 @@ def handler(f): if handling and not message.reply.acked and not message.reply.taken: message.reply() return ret + # Mark this function as a handler wrapper wrapper.func_dict["__handler"] = True return wrapper |