diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-06-18 18:12:11 +0200 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-06-18 18:15:22 +0200 |
commit | 7a3623a14ee2ffa021c1a2a8f337826e055b328d (patch) | |
tree | 7abdfdba135ea1f6022a8a72b1c52371f76fbea2 /libpathod | |
parent | 90aeda47aead50110ee4a0a29b01edd170539818 (diff) | |
download | mitmproxy-7a3623a14ee2ffa021c1a2a8f337826e055b328d.tar.gz mitmproxy-7a3623a14ee2ffa021c1a2a8f337826e055b328d.tar.bz2 mitmproxy-7a3623a14ee2ffa021c1a2a8f337826e055b328d.zip |
fix pep8 whitespace
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/app.py | 13 | ||||
-rw-r--r-- | libpathod/language/__init__.py | 8 | ||||
-rw-r--r-- | libpathod/language/actions.py | 2 | ||||
-rw-r--r-- | libpathod/language/base.py | 28 | ||||
-rw-r--r-- | libpathod/language/exceptions.py | 1 | ||||
-rw-r--r-- | libpathod/language/generators.py | 23 | ||||
-rw-r--r-- | libpathod/language/websockets.py | 3 | ||||
-rw-r--r-- | libpathod/pathoc.py | 74 | ||||
-rw-r--r-- | libpathod/pathoc_cmdline.py | 4 | ||||
-rw-r--r-- | libpathod/pathod.py | 69 | ||||
-rw-r--r-- | libpathod/test.py | 3 | ||||
-rw-r--r-- | libpathod/utils.py | 20 |
12 files changed, 140 insertions, 108 deletions
diff --git a/libpathod/app.py b/libpathod/app.py index cd7a8bd6..4a8d2b63 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -12,6 +12,7 @@ EXAMPLE_WEBSOCKET_KEY = "examplekey" # pylint: disable=unused-variable + def make_app(noapi, debug): app = Flask(__name__) app.debug = debug @@ -20,13 +21,13 @@ def make_app(noapi, debug): @app.route('/api/info') def api_info(): return jsonify( - version = version.IVERSION + version=version.IVERSION ) @app.route('/api/log') def api_log(): return jsonify( - log = app.config["pathod"].get_log() + log=app.config["pathod"].get_log() ) @app.route('/api/clear_log') @@ -125,10 +126,10 @@ def make_app(noapi, debug): spec = request.args["spec"] args = dict( - spec = spec, - section = "main", - syntaxerror = None, - error = None, + spec=spec, + section="main", + syntaxerror=None, + error=None, ) if not spec.strip(): args["error"] = "Can't parse an empty spec." diff --git a/libpathod/language/__init__.py b/libpathod/language/__init__.py index 4b06f7e4..32199e08 100644 --- a/libpathod/language/__init__.py +++ b/libpathod/language/__init__.py @@ -75,7 +75,7 @@ def parse_websocket_frame(s): websockets.WebsocketFrame.expr() ).parseString( s, - parseAll = True + parseAll=True ) except pp.ParseException as v: raise exceptions.ParseException(v.msg, v.line, v.col) @@ -105,9 +105,9 @@ def serve(msg, fp, settings): disconnect = writer.write_values(fp, vals, actions[:]) duration = time.time() - started ret = dict( - disconnect = disconnect, - started = started, - duration = duration, + disconnect=disconnect, + started=started, + duration=duration, ) ret.update(msg.log(settings)) return ret diff --git a/libpathod/language/actions.py b/libpathod/language/actions.py index 7bb61005..34a9bafb 100644 --- a/libpathod/language/actions.py +++ b/libpathod/language/actions.py @@ -8,6 +8,7 @@ from . import base class _Action(base.Token): + """ An action that operates on the raw data stream of the message. All actions have one thing in common: an offset that specifies where the @@ -76,6 +77,7 @@ class PauseAt(_Action): class DisconnectAt(_Action): + def __init__(self, offset): _Action.__init__(self, offset) diff --git a/libpathod/language/base.py b/libpathod/language/base.py index 1f42f65e..a4302998 100644 --- a/libpathod/language/base.py +++ b/libpathod/language/base.py @@ -7,14 +7,15 @@ from .. import utils from . import generators, exceptions class Settings(object): + def __init__( self, - is_client = False, - staticdir = None, - unconstrained_file_access = False, - request_host = None, - websocket_key = None, - protocol = None, + is_client=False, + staticdir=None, + unconstrained_file_access=False, + request_host=None, + websocket_key=None, + protocol=None, ): self.is_client = is_client self.staticdir = staticdir @@ -56,6 +57,7 @@ v_naked_literal = pp.MatchFirst( class Token(object): + """ A token in the specification language. Tokens are immutable. The token classes have no meaning in and of themselves, and are combined into @@ -101,6 +103,7 @@ class Token(object): class _TokValueLiteral(Token): + def __init__(self, val): self.val = val.decode("string_escape") @@ -112,6 +115,7 @@ class _TokValueLiteral(Token): class TokValueLiteral(_TokValueLiteral): + """ A literal with Python-style string escaping """ @@ -132,6 +136,7 @@ class TokValueLiteral(_TokValueLiteral): class TokValueNakedLiteral(_TokValueLiteral): + @classmethod def expr(cls): e = v_naked_literal.copy() @@ -142,6 +147,7 @@ class TokValueNakedLiteral(_TokValueLiteral): class TokValueGenerate(Token): + def __init__(self, usize, unit, datatype): if not unit: unit = "b" @@ -185,6 +191,7 @@ class TokValueGenerate(Token): class TokValueFile(Token): + def __init__(self, path): self.path = str(path) @@ -246,6 +253,7 @@ TokOffset = pp.MatchFirst( class _Component(Token): + """ A value component of the primary specification of an message. Components produce byte values desribe the bytes of the message. @@ -265,6 +273,7 @@ class _Component(Token): class KeyValue(_Component): + """ A key/value pair. cls.preamble: leader @@ -291,6 +300,7 @@ class KeyValue(_Component): class CaselessLiteral(_Component): + """ A caseless token that can take only one value. """ @@ -315,6 +325,7 @@ class CaselessLiteral(_Component): class OptionsOrValue(_Component): + """ Can be any of a specified set of options, or a value specifier. """ @@ -395,6 +406,7 @@ class Integer(_Component): class Value(_Component): + """ A value component lead by an optional preamble. """ @@ -421,6 +433,7 @@ class Value(_Component): class FixedLengthValue(Value): + """ A value component lead by an optional preamble. """ @@ -461,6 +474,7 @@ class FixedLengthValue(Value): class Boolean(_Component): + """ A boolean flag. name = true @@ -489,6 +503,7 @@ class Boolean(_Component): class IntField(_Component): + """ An integer field, where values can optionally specified by name. """ @@ -522,6 +537,7 @@ class IntField(_Component): class NestedMessage(Token): + """ A nested message, as an escaped string with a preamble. """ diff --git a/libpathod/language/exceptions.py b/libpathod/language/exceptions.py index a65c7936..84ad3c02 100644 --- a/libpathod/language/exceptions.py +++ b/libpathod/language/exceptions.py @@ -8,6 +8,7 @@ class FileAccessDenied(RenderError): class ParseException(Exception): + def __init__(self, msg, s, col): Exception.__init__(self) self.msg = msg diff --git a/libpathod/language/generators.py b/libpathod/language/generators.py index d351e790..a17e7052 100644 --- a/libpathod/language/generators.py +++ b/libpathod/language/generators.py @@ -3,20 +3,21 @@ import random import mmap DATATYPES = dict( - ascii_letters = string.ascii_letters, - ascii_lowercase = string.ascii_lowercase, - ascii_uppercase = string.ascii_uppercase, - digits = string.digits, - hexdigits = string.hexdigits, - octdigits = string.octdigits, - punctuation = string.punctuation, - whitespace = string.whitespace, - ascii = string.printable, - bytes = "".join(chr(i) for i in range(256)) + ascii_letters=string.ascii_letters, + ascii_lowercase=string.ascii_lowercase, + ascii_uppercase=string.ascii_uppercase, + digits=string.digits, + hexdigits=string.hexdigits, + octdigits=string.octdigits, + punctuation=string.punctuation, + whitespace=string.whitespace, + ascii=string.printable, + bytes="".join(chr(i) for i in range(256)) ) class TransformGenerator(object): + """ Perform a byte-by-byte transform another generator - that is, for each input byte, the transformation must produce one output byte. @@ -45,6 +46,7 @@ class TransformGenerator(object): class RandomGenerator(object): + def __init__(self, dtype, length): self.dtype = dtype self.length = length @@ -65,6 +67,7 @@ class RandomGenerator(object): class FileGenerator(object): + def __init__(self, path): self.path = path self.fp = file(path, "rb") diff --git a/libpathod/language/websockets.py b/libpathod/language/websockets.py index 18a20025..2c0231e6 100644 --- a/libpathod/language/websockets.py +++ b/libpathod/language/websockets.py @@ -5,6 +5,7 @@ from . import base, generators, actions, message NESTED_LEADER = "pathod!" + class WF(base.CaselessLiteral): TOK = "wf" @@ -197,7 +198,7 @@ class WebsocketFrame(message.Message): if self.toklength: length = int(self.toklength.value) frameparts = dict( - payload_length = length + payload_length=length ) if self.mask and self.mask.value: frameparts["mask"] = True diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 6b040214..0627f8ca 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -26,6 +26,7 @@ class PathocError(Exception): class SSLInfo(object): + def __init__(self, certchain, cipher, alp): self.certchain, self.cipher, self.alp = certchain, cipher, alp @@ -66,6 +67,7 @@ class SSLInfo(object): class Response(object): + def __init__( self, httpversion, @@ -85,6 +87,7 @@ class Response(object): class WebsocketFrameReader(threading.Thread): + def __init__( self, rfile, @@ -143,6 +146,7 @@ class WebsocketFrameReader(threading.Thread): class Pathoc(tcp.TCPClient): + def __init__( self, address, @@ -157,23 +161,23 @@ class Pathoc(tcp.TCPClient): # HTTP/2 use_http2=False, http2_skip_connection_preface=False, - http2_framedump = False, + http2_framedump=False, # Websockets - ws_read_limit = None, + ws_read_limit=None, # Network - timeout = None, + timeout=None, # Output control - showreq = False, - showresp = False, - explain = False, - hexdump = False, - ignorecodes = (), - ignoretimeout = False, - showsummary = False, - fp = sys.stdout + showreq=False, + showresp=False, + explain=False, + hexdump=False, + ignorecodes=(), + ignoretimeout=False, + showsummary=False, + fp=sys.stdout ): """ spec: A request specification @@ -222,11 +226,11 @@ class Pathoc(tcp.TCPClient): self.protocol = None self.settings = language.Settings( - is_client = True, - staticdir = os.getcwd(), - unconstrained_file_access = True, - request_host = self.address.host, - protocol = self.protocol, + is_client=True, + staticdir=os.getcwd(), + unconstrained_file_access=True, + request_host=self.address.host, + protocol=self.protocol, ) def log(self): @@ -323,8 +327,8 @@ class Pathoc(tcp.TCPClient): while True: try: frm = self.ws_framereader.frames_queue.get( - timeout = timeout, - block = True if timeout != 0 else False + timeout=timeout, + block=True if timeout != 0 else False ) except Queue.Empty: if finish: @@ -394,7 +398,7 @@ class Pathoc(tcp.TCPClient): ) resp.append(self.sslinfo) resp = Response(*resp) - except http.HttpError, v: + except http.HttpError as v: log("Invalid server response: %s" % v) raise except tcp.NetLibTimeout: @@ -455,22 +459,22 @@ def main(args): # pragma: nocover playlist = random.choice(args.requests) p = Pathoc( (args.host, args.port), - ssl = args.ssl, - sni = args.sni, - sslversion = args.sslversion, - clientcert = args.clientcert, - ciphers = args.ciphers, - use_http2 = args.use_http2, - http2_skip_connection_preface = args.http2_skip_connection_preface, - http2_framedump = args.http2_framedump, - showreq = args.showreq, - showresp = args.showresp, - explain = args.explain, - hexdump = args.hexdump, - ignorecodes = args.ignorecodes, - timeout = args.timeout, - ignoretimeout = args.ignoretimeout, - showsummary = True + ssl=args.ssl, + sni=args.sni, + sslversion=args.sslversion, + clientcert=args.clientcert, + ciphers=args.ciphers, + use_http2=args.use_http2, + http2_skip_connection_preface=args.http2_skip_connection_preface, + http2_framedump=args.http2_framedump, + showreq=args.showreq, + showresp=args.showresp, + explain=args.explain, + hexdump=args.hexdump, + ignorecodes=args.ignorecodes, + timeout=args.timeout, + ignoretimeout=args.ignoretimeout, + showsummary=True ) trycount = 0 try: diff --git a/libpathod/pathoc_cmdline.py b/libpathod/pathoc_cmdline.py index 3722c7dc..02eb6e5d 100644 --- a/libpathod/pathoc_cmdline.py +++ b/libpathod/pathoc_cmdline.py @@ -30,7 +30,7 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): ) parser.add_argument( "-c", dest="connect_to", type=str, default=False, - metavar = "HOST:PORT", + metavar="HOST:PORT", help="Issue an HTTP CONNECT to connect to the specified host." ) parser.add_argument( @@ -77,7 +77,7 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): parser.add_argument( 'host', type=str, - metavar = "host[:port]", + metavar="host[:port]", help='Host and port to connect to' ) parser.add_argument( diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 695f62a5..76170990 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -29,6 +29,7 @@ class PathodError(Exception): class SSLOptions(object): + def __init__( self, confdir=CONFDIR, @@ -92,7 +93,7 @@ class PathodHandler(tcp.BaseHandler): language.serve(err, self.wfile, self.settings) return None, dict( type="error", - msg = error + msg=error ) if self.server.explain and not hasattr(crafted, 'is_error_response'): @@ -116,17 +117,17 @@ class PathodHandler(tcp.BaseHandler): started = time.time() try: frm = websockets.Frame.from_file(self.rfile) - except tcp.NetLibIncomplete, e: - lg("Error reading websocket frame: %s"%e) + except tcp.NetLibIncomplete as e: + lg("Error reading websocket frame: %s" % e) break ended = time.time() lg(frm.human_readable()) retlog = dict( - type = "inbound", - protocol = "websockets", - started = started, - duration = ended - started, - frame = dict( + type="inbound", + protocol="websockets", + started=started, + duration=ended - started, + frame=dict( ), cipher=None, ) @@ -138,7 +139,7 @@ class PathodHandler(tcp.BaseHandler): nest = frm.payload[len(ld):] try: wf_gen = language.parse_websocket_frame(nest) - except language.exceptions.ParseException, v: + except language.exceptions.ParseException as v: log.write( self.logfp, "Parse error in reflected frame specifcation:" @@ -509,7 +510,7 @@ class Pathod(tcp.TCPServer): self.anchors = anchors self.settings = language.Settings( - staticdir = self.staticdir + staticdir=self.staticdir ) def check_policy(self, req, settings): @@ -587,13 +588,13 @@ class Pathod(tcp.TCPServer): def main(args): # pragma: nocover ssloptions = SSLOptions( - cn = args.cn, - confdir = args.confdir, - not_after_connect = args.ssl_not_after_connect, - ciphers = args.ciphers, - sslversion = utils.SSLVERSIONS[args.sslversion], - certs = args.ssl_certs, - sans = args.sans, + cn=args.cn, + confdir=args.confdir, + not_after_connect=args.ssl_not_after_connect, + ciphers=args.ciphers, + sslversion=utils.SSLVERSIONS[args.sslversion], + certs=args.ssl_certs, + sans=args.sans, ) root = logging.getLogger() @@ -619,23 +620,23 @@ def main(args): # pragma: nocover try: pd = Pathod( (args.address, args.port), - craftanchor = args.craftanchor, - ssl = args.ssl, - ssloptions = ssloptions, - staticdir = args.staticdir, - anchors = args.anchors, - sizelimit = args.sizelimit, - noweb = args.noweb, - nocraft = args.nocraft, - noapi = args.noapi, - nohang = args.nohang, - timeout = args.timeout, - logreq = args.logreq, - logresp = args.logresp, - hexdump = args.hexdump, - http2_framedump = args.http2_framedump, - explain = args.explain, - webdebug = args.webdebug + craftanchor=args.craftanchor, + ssl=args.ssl, + ssloptions=ssloptions, + staticdir=args.staticdir, + anchors=args.anchors, + sizelimit=args.sizelimit, + noweb=args.noweb, + nocraft=args.nocraft, + noapi=args.noapi, + nohang=args.nohang, + timeout=args.timeout, + logreq=args.logreq, + logresp=args.logresp, + hexdump=args.hexdump, + http2_framedump=args.http2_framedump, + explain=args.explain, + webdebug=args.webdebug ) except PathodError as v: print >> sys.stderr, "Error: %s" % v diff --git a/libpathod/test.py b/libpathod/test.py index ebb3a49f..33a6b763 100644 --- a/libpathod/test.py +++ b/libpathod/test.py @@ -82,6 +82,7 @@ class Daemon: class _PaThread(threading.Thread): + def __init__(self, iface, q, ssl, daemonargs): threading.Thread.__init__(self) self.name = "PathodThread" @@ -91,7 +92,7 @@ class _PaThread(threading.Thread): def run(self): self.server = pathod.Pathod( (self.iface, 0), - ssl = self.ssl, + ssl=self.ssl, **self.daemonargs ) self.name = "PathodThread (%s:%s)" % ( diff --git a/libpathod/utils.py b/libpathod/utils.py index ac21dd13..8aec9d19 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -5,22 +5,23 @@ from netlib import tcp SSLVERSIONS = { 'TLSv1.2': tcp.TLSv1_2_METHOD, 'TLSv1.1': tcp.TLSv1_1_METHOD, - 'TLSv1': tcp.TLSv1_METHOD, - 'SSLv3': tcp.SSLv3_METHOD, - 'SSLv2': tcp.SSLv2_METHOD, - 'SSLv23': tcp.SSLv23_METHOD, + 'TLSv1': tcp.TLSv1_METHOD, + 'SSLv3': tcp.SSLv3_METHOD, + 'SSLv2': tcp.SSLv2_METHOD, + 'SSLv23': tcp.SSLv23_METHOD, } SIZE_UNITS = dict( - b = 1024 ** 0, - k = 1024 ** 1, - m = 1024 ** 2, - g = 1024 ** 3, - t = 1024 ** 4, + b=1024 ** 0, + k=1024 ** 1, + m=1024 ** 2, + g=1024 ** 3, + t=1024 ** 4, ) class MemBool(object): + """ Truth-checking with a memory, for use in chained if statements. """ @@ -84,6 +85,7 @@ def escape_unprintables(s): class Data(object): + def __init__(self, name): m = __import__(name) dirname, _ = os.path.split(m.__file__) |