diff options
Diffstat (limited to 'pathod')
-rw-r--r-- | pathod/app.py | 5 | ||||
-rw-r--r-- | pathod/language/base.py | 14 | ||||
-rw-r--r-- | pathod/log.py | 8 | ||||
-rw-r--r-- | pathod/pathoc.py | 9 | ||||
-rw-r--r-- | pathod/utils.py | 18 |
5 files changed, 20 insertions, 34 deletions
diff --git a/pathod/app.py b/pathod/app.py index 7e9860b9..e3216c58 100644 --- a/pathod/app.py +++ b/pathod/app.py @@ -3,8 +3,9 @@ import pprint import io import copy from flask import Flask, jsonify, render_template, request, abort, make_response -from . import version, language, utils +from . import version, language from netlib.http import user_agents +from netlib import strutils logging.basicConfig(level="DEBUG") EXAMPLE_HOST = "example.com" @@ -166,7 +167,7 @@ def make_app(noapi, debug): settings.websocket_key = EXAMPLE_WEBSOCKET_KEY language.serve(safe, s, settings) - args["output"] = utils.escape_unprintables(s.getvalue()) + args["output"] = strutils.bytes_to_escaped_str(s.getvalue()) return render(template, False, **args) @app.route('/response_preview') 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..5bf55de4 100644 --- a/pathod/log.py +++ b/pathod/log.py @@ -2,9 +2,7 @@ import datetime import six -import netlib.utils -import netlib.tcp -import netlib.http +from netlib import strutils TIMEFMT = '%d-%m-%y %H:%M:%S' @@ -62,10 +60,10 @@ class LogCtx(object): def dump(self, data, hexdump): if hexdump: - for line in netlib.utils.hexdump(data): + for line in strutils.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/pathoc.py b/pathod/pathoc.py index 910387b6..2b7d053c 100644 --- a/pathod/pathoc.py +++ b/pathod/pathoc.py @@ -18,14 +18,19 @@ from netlib.exceptions import HttpException, TcpDisconnect, TcpTimeout, TlsExcep NetlibException from netlib.http import http1, http2 -from . import utils, log, language +from . import log, language import logging from netlib.tutils import treq +from netlib import strutils logging.getLogger("hpack").setLevel(logging.WARNING) +def xrepr(s): + return repr(s)[1:-1] + + class PathocError(Exception): pass @@ -423,7 +428,7 @@ class Pathoc(tcp.TCPClient): finally: if resp: lg("<< %s %s: %s bytes" % ( - resp.status_code, utils.xrepr(resp.reason), len(resp.content) + resp.status_code, strutils.bytes_to_escaped_str(resp.reason), len(resp.content) )) if resp.status_code in self.ignorecodes: lg.suppress() diff --git a/pathod/utils.py b/pathod/utils.py index fe12f541..3276198a 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -2,8 +2,6 @@ import os import sys import netlib.utils -from netlib.utils import bytes_to_escaped_str - class MemBool(object): @@ -28,22 +26,6 @@ def parse_anchor_spec(s): return tuple(s.split("=", 1)) -def xrepr(s): - return repr(s)[1:-1] - - -def escape_unprintables(s): - """ - Like inner_repr, but preserves line breaks. - """ - 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 = s.replace("PATHOD_MARKER_RN", "\n") - s = s.replace("PATHOD_MARKER_N", "\n") - return s - - data = netlib.utils.Data(__name__) |