diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-11-21 02:16:20 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-11-21 02:28:10 +0100 |
commit | 9af8f4bb31c94a25780a4189bffa406906249626 (patch) | |
tree | cf52f1c312b7bac3d83d796d6b03bb33b4556f26 /examples/custom_contentviews.py | |
parent | f74e561524d04c93cd7953f34e78ebe67eaa58a8 (diff) | |
download | mitmproxy-9af8f4bb31c94a25780a4189bffa406906249626.tar.gz mitmproxy-9af8f4bb31c94a25780a4189bffa406906249626.tar.bz2 mitmproxy-9af8f4bb31c94a25780a4189bffa406906249626.zip |
organize examples
This commit is largely based on work by Thiago Arrais (@thiagoarrais)
and Shane Bradfield (@l33tLumberjack). I wasn't really able to get their
PR reasonably merged onto the latest master, so I reapplied their changes
manually here and did some further improvements on that.
Diffstat (limited to 'examples/custom_contentviews.py')
-rw-r--r-- | examples/custom_contentviews.py | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py deleted file mode 100644 index 3558eaca..00000000 --- a/examples/custom_contentviews.py +++ /dev/null @@ -1,70 +0,0 @@ -import string -import lxml.html -import lxml.etree -from mitmproxy import contentviews -from mitmproxy.utils import strutils - - -class ViewPigLatin(contentviews.View): - name = "pig_latin_HTML" - prompt = ("pig latin HTML", "l") - content_types = ["text/html"] - - def __call__(self, data, **metadata): - if strutils.is_xml(data): - parser = lxml.etree.HTMLParser( - strip_cdata=True, - remove_blank_text=True - ) - d = lxml.html.fromstring(data, parser=parser) - docinfo = d.getroottree().docinfo - - def piglify(src): - words = src.split() - ret = '' - for word in words: - idx = -1 - while word[idx] in string.punctuation and (idx * -1) != len(word): - idx -= 1 - if word[0].lower() in 'aeiou': - if idx == -1: - ret += word[0:] + "hay" - else: - ret += word[0:len(word) + idx + 1] + "hay" + word[idx + 1:] - else: - if idx == -1: - ret += word[1:] + word[0] + "ay" - else: - ret += word[1:len(word) + idx + 1] + word[0] + "ay" + word[idx + 1:] - ret += ' ' - return ret.strip() - - def recurse(root): - if hasattr(root, 'text') and root.text: - root.text = piglify(root.text) - if hasattr(root, 'tail') and root.tail: - root.tail = piglify(root.tail) - - if len(root): - for child in root: - recurse(child) - - recurse(d) - - s = lxml.etree.tostring( - d, - pretty_print=True, - doctype=docinfo.doctype - ) - return "HTML", contentviews.format_text(s) - - -pig_view = ViewPigLatin() - - -def start(): - contentviews.add(pig_view) - - -def done(): - contentviews.remove(pig_view) |