aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-06-02 13:03:37 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-06-02 13:04:19 +1200
commit09da1febbd9beac5ef5650274899439f5ce10e98 (patch)
tree76ba04357353645f49e0f4bd8d835e471239b54b /mitmproxy
parent31012d782f64727de1d86662139e9ec6618043c5 (diff)
downloadmitmproxy-09da1febbd9beac5ef5650274899439f5ce10e98.tar.gz
mitmproxy-09da1febbd9beac5ef5650274899439f5ce10e98.tar.bz2
mitmproxy-09da1febbd9beac5ef5650274899439f5ce10e98.zip
Shift a bunch more string-related functions to strutils
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/contentviews.py9
-rw-r--r--mitmproxy/utils.py38
2 files changed, 4 insertions, 43 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py
index 0ddf7c64..42061a8c 100644
--- a/mitmproxy/contentviews.py
+++ b/mitmproxy/contentviews.py
@@ -37,7 +37,6 @@ from netlib import http
from netlib import odict
from netlib.http import url
from netlib import strutils
-import netlib.utils
try:
import pyamf
@@ -130,11 +129,11 @@ class ViewAuto(View):
ct = "%s/%s" % (ct[0], ct[1])
if ct in content_types_map:
return content_types_map[ct][0](data, **metadata)
- elif mitmproxy.utils.isXML(data):
+ elif strutils.isXML(data):
return get("XML")(data, **metadata)
if metadata.get("query"):
return get("Query")(data, **metadata)
- if data and mitmproxy.utils.isMostlyBin(data):
+ if data and strutils.isMostlyBin(data):
return get("Hex")(data)
if not data:
return "No content", []
@@ -157,7 +156,7 @@ class ViewHex(View):
@staticmethod
def _format(data):
- for offset, hexa, s in netlib.utils.hexdump(data):
+ for offset, hexa, s in strutils.hexdump(data):
yield [
("offset", offset + " "),
("text", hexa + " "),
@@ -227,7 +226,7 @@ class ViewHTML(View):
content_types = ["text/html"]
def __call__(self, data, **metadata):
- if mitmproxy.utils.isXML(data):
+ if strutils.isXML(data):
parser = lxml.etree.HTMLParser(
strip_cdata=True,
remove_blank_text=True
diff --git a/mitmproxy/utils.py b/mitmproxy/utils.py
index 672805d0..680bc495 100644
--- a/mitmproxy/utils.py
+++ b/mitmproxy/utils.py
@@ -25,32 +25,6 @@ def format_timestamp_with_milli(s):
return d.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
-def isBin(s):
- """
- Does this string have any non-ASCII characters?
- """
- for i in s:
- i = ord(i)
- if i < 9 or 13 < i < 32 or 126 < i:
- return True
- return False
-
-
-def isMostlyBin(s):
- s = s[:100]
- return sum(isBin(ch) for ch in s) / len(s) > 0.3
-
-
-def isXML(s):
- for i in s:
- if i in "\n \t":
- continue
- elif i == "<":
- return True
- else:
- return False
-
-
def pretty_json(s):
try:
p = json.loads(s)
@@ -92,15 +66,3 @@ class LRUCache:
d = self.cacheList.pop()
self.cache.pop(d)
return ret
-
-
-def clean_hanging_newline(t):
- """
- Many editors will silently add a newline to the final line of a
- document (I'm looking at you, Vim). This function fixes this common
- problem at the risk of removing a hanging newline in the rare cases
- where the user actually intends it.
- """
- if t and t[-1] == "\n":
- return t[:-1]
- return t