aboutsummaryrefslogtreecommitdiffstats
path: root/examples/custom_contentviews.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-02-15 23:00:11 +0100
committerMaximilian Hils <git@maximilianhils.com>2016-02-15 23:00:11 +0100
commit87d9afcf2e257eee7c5aa08c3f0dc64da79b0647 (patch)
tree71b10729d160f0269d02548d1ef9e183be1397d9 /examples/custom_contentviews.py
parent36f34f701991b5d474c005ec45e3b66e20f326a8 (diff)
parent3d9a5157e77b5a3237dc62994f4e3d4c75c2066e (diff)
downloadmitmproxy-87d9afcf2e257eee7c5aa08c3f0dc64da79b0647.tar.gz
mitmproxy-87d9afcf2e257eee7c5aa08c3f0dc64da79b0647.tar.bz2
mitmproxy-87d9afcf2e257eee7c5aa08c3f0dc64da79b0647.zip
Merge pull request #937 from mhils/single-repo
Combine mitmproxy, pathod and netlib in a single repo.
Diffstat (limited to 'examples/custom_contentviews.py')
-rw-r--r--examples/custom_contentviews.py68
1 files changed, 0 insertions, 68 deletions
diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py
deleted file mode 100644
index 17920e51..00000000
--- a/examples/custom_contentviews.py
+++ /dev/null
@@ -1,68 +0,0 @@
-import string
-import lxml.html
-import lxml.etree
-from libmproxy import utils, contentviews
-
-
-class ViewPigLatin(contentviews.View):
- name = "pig_latin_HTML"
- prompt = ("pig latin HTML", "l")
- content_types = ["text/html"]
-
- def __call__(self, data, **metadata):
- if utils.isXML(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 = string.split(src)
- 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(context, argv):
- context.add_contentview(pig_view)
-
-
-def stop(context):
- context.remove_contentview(pig_view)