aboutsummaryrefslogtreecommitdiffstats
path: root/pathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-06-02 12:31:41 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-06-02 12:31:41 +1200
commitcccdc9842648518de7ee48ce461801954fc334c8 (patch)
tree288941673dc0db7ffe96be55ae2c34a1ce5db916 /pathod
parenteaa3b308f7bb48256ccf56ea07d008fa5f9dd6ad (diff)
downloadmitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.tar.gz
mitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.tar.bz2
mitmproxy-cccdc9842648518de7ee48ce461801954fc334c8.zip
Utils reorganisation: add netlib.strutils
Extract a number of string and format-related functions to netlib.strutils.
Diffstat (limited to 'pathod')
-rw-r--r--pathod/language/base.py14
-rw-r--r--pathod/log.py3
-rw-r--r--pathod/utils.py4
3 files changed, 11 insertions, 10 deletions
diff --git a/pathod/language/base.py b/pathod/language/base.py
index 1f4edb6f..11ee0623 100644
--- a/pathod/language/base.py
+++ b/pathod/language/base.py
@@ -5,7 +5,7 @@ import pyparsing as pp
import six
from six.moves import reduce
-from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str
+from netlib import strutils
from netlib import human
from . import generators, exceptions
@@ -110,7 +110,7 @@ class Token(object):
class _TokValueLiteral(Token):
def __init__(self, val):
- self.val = escaped_str_to_bytes(val)
+ self.val = strutils.escaped_str_to_bytes(val)
def get_generator(self, settings_):
return self.val
@@ -135,7 +135,7 @@ class TokValueLiteral(_TokValueLiteral):
return v
def spec(self):
- inner = bytes_to_escaped_str(self.val)
+ inner = strutils.bytes_to_escaped_str(self.val)
inner = inner.replace(r"\'", r"\x27")
return "'" + inner + "'"
@@ -148,7 +148,7 @@ class TokValueNakedLiteral(_TokValueLiteral):
return e.setParseAction(lambda x: cls(*x))
def spec(self):
- return bytes_to_escaped_str(self.val)
+ return strutils.bytes_to_escaped_str(self.val)
class TokValueGenerate(Token):
@@ -166,7 +166,7 @@ class TokValueGenerate(Token):
def freeze(self, settings):
g = self.get_generator(settings)
- return TokValueLiteral(bytes_to_escaped_str(g[:]))
+ return TokValueLiteral(strutils.bytes_to_escaped_str(g[:]))
@classmethod
def expr(cls):
@@ -226,7 +226,7 @@ class TokValueFile(Token):
return generators.FileGenerator(s)
def spec(self):
- return "<'%s'" % bytes_to_escaped_str(self.path)
+ return "<'%s'" % strutils.bytes_to_escaped_str(self.path)
TokValue = pp.MatchFirst(
@@ -578,4 +578,4 @@ class NestedMessage(Token):
def freeze(self, settings):
f = self.parsed.freeze(settings).spec()
- return self.__class__(TokValueLiteral(bytes_to_escaped_str(f)))
+ return self.__class__(TokValueLiteral(strutils.bytes_to_escaped_str(f)))
diff --git a/pathod/log.py b/pathod/log.py
index 3f6aaea0..85006ba8 100644
--- a/pathod/log.py
+++ b/pathod/log.py
@@ -5,6 +5,7 @@ import six
import netlib.utils
import netlib.tcp
import netlib.http
+from netlib import strutils
TIMEFMT = '%d-%m-%y %H:%M:%S'
@@ -65,7 +66,7 @@ class LogCtx(object):
for line in netlib.utils.hexdump(data):
self("\t%s %s %s" % line)
else:
- for i in netlib.utils.clean_bin(data).split("\n"):
+ for i in strutils.clean_bin(data).split("\n"):
self("\t%s" % i)
def __call__(self, line):
diff --git a/pathod/utils.py b/pathod/utils.py
index fe12f541..1b6ef3ef 100644
--- a/pathod/utils.py
+++ b/pathod/utils.py
@@ -2,7 +2,7 @@ import os
import sys
import netlib.utils
-from netlib.utils import bytes_to_escaped_str
+from netlib import strutils
class MemBool(object):
@@ -38,7 +38,7 @@ def escape_unprintables(s):
"""
s = s.replace(b"\r\n", b"PATHOD_MARKER_RN")
s = s.replace(b"\n", b"PATHOD_MARKER_N")
- s = bytes_to_escaped_str(s)
+ s = strutils.bytes_to_escaped_str(s)
s = s.replace("PATHOD_MARKER_RN", "\n")
s = s.replace("PATHOD_MARKER_N", "\n")
return s