diff options
author | Chris Czub <chris.czub@gmail.com> | 2015-11-13 16:55:27 -0500 |
---|---|---|
committer | Chris Czub <chris.czub@gmail.com> | 2015-11-13 16:55:27 -0500 |
commit | e72a9a62a107ea3f53b6b26d1abe63c554448d17 (patch) | |
tree | 6631b484b9029b8391d22a6bf22845058f4f2fce /libmproxy/contentviews.py | |
parent | d3feaa3bc6e2d9c2c7ee8286038c69c0b9601869 (diff) | |
download | mitmproxy-e72a9a62a107ea3f53b6b26d1abe63c554448d17.tar.gz mitmproxy-e72a9a62a107ea3f53b6b26d1abe63c554448d17.tar.bz2 mitmproxy-e72a9a62a107ea3f53b6b26d1abe63c554448d17.zip |
Feedback from PR #832
Diffstat (limited to 'libmproxy/contentviews.py')
-rw-r--r-- | libmproxy/contentviews.py | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/libmproxy/contentviews.py b/libmproxy/contentviews.py index aa2082d1..2f46ccca 100644 --- a/libmproxy/contentviews.py +++ b/libmproxy/contentviews.py @@ -479,34 +479,9 @@ class ViewWBXML(View): return None -views = [ - ViewAuto(), - ViewRaw(), - ViewHex(), - ViewJSON(), - ViewXML(), - ViewWBXML(), - ViewHTML(), - ViewHTMLOutline(), - ViewJavaScript(), - ViewCSS(), - ViewURLEncoded(), - ViewMultipart(), - ViewImage(), -] -if pyamf: - views.append(ViewAMF()) - -if ViewProtobuf.is_available(): - views.append(ViewProtobuf()) - +views = [] content_types_map = {} -for i in views: - for ct in i.content_types: - l = content_types_map.setdefault(ct, []) - l.append(i) - -view_prompts = [i.prompt for i in views] +view_prompts = [] def get_by_shortcut(c): @@ -515,23 +490,57 @@ def get_by_shortcut(c): return i -def add(obj): +def add(view): + # TODO: auto-select a different name (append an integer?) for i in views: - if i.name == obj.name: - raise ContentViewException("Duplicate view: " + obj.name) + if i.name == view.name: + raise ContentViewException("Duplicate view: " + view.name) + # TODO: the UI should auto-prompt for a replacement shortcut for prompt in view_prompts: - if prompt[1] == obj.prompt[1]: - raise ContentViewException("Duplicate view shortcut: " + obj.prompt[1]) + if prompt[1] == view.prompt[1]: + raise ContentViewException("Duplicate view shortcut: " + view.prompt[1]) + + views.append(view) + + for ct in view.content_types: + l = content_types_map.setdefault(ct, []) + l.append(view) + + view_prompts.append(view.prompt) - views.append(obj) - for ct in obj.content_types: +def remove(view): + for ct in view.content_types: l = content_types_map.setdefault(ct, []) - l.append(obj) + l.remove(view) + + if not len(l): + del content_types_map[ct] + + view_prompts.remove(view.prompt) + views.remove(view) - view_prompts.append(obj.prompt) +add(ViewAuto()) +add(ViewRaw()) +add(ViewHex()) +add(ViewJSON()) +add(ViewXML()) +add(ViewWBXML()) +add(ViewHTML()) +add(ViewHTMLOutline()) +add(ViewJavaScript()) +add(ViewCSS()) +add(ViewURLEncoded()) +add(ViewMultipart()) +add(ViewImage()) + +if pyamf: + add(ViewAMF()) + +if ViewProtobuf.is_available(): + add(ViewProtobuf()) def get(name): for i in views: |