aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-18 11:07:33 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-18 11:07:33 +0200
commit65be004bb2e0f8ba9a4712d0172bb0d0151a33bb (patch)
treeefc377e4d4688264ca12e19f35d00ac04f4104ba /libpathod
parentbd0cfef357ff33ab8be216998e8de69c1784c043 (diff)
downloadmitmproxy-65be004bb2e0f8ba9a4712d0172bb0d0151a33bb.tar.gz
mitmproxy-65be004bb2e0f8ba9a4712d0172bb0d0151a33bb.tar.bz2
mitmproxy-65be004bb2e0f8ba9a4712d0172bb0d0151a33bb.zip
fix prospector code smells
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/language/actions.py12
-rw-r--r--libpathod/language/base.py88
-rw-r--r--libpathod/language/generators.py6
-rw-r--r--libpathod/language/http.py12
-rw-r--r--libpathod/language/http2.py29
-rw-r--r--libpathod/language/message.py2
-rw-r--r--libpathod/language/websockets.py6
-rw-r--r--libpathod/log.py2
-rw-r--r--libpathod/pathoc.py4
-rw-r--r--libpathod/pathod.py13
-rw-r--r--libpathod/pathod_cmdline.py3
-rw-r--r--libpathod/utils.py6
12 files changed, 93 insertions, 90 deletions
diff --git a/libpathod/language/actions.py b/libpathod/language/actions.py
index 40adb4ea..f825d0cc 100644
--- a/libpathod/language/actions.py
+++ b/libpathod/language/actions.py
@@ -53,7 +53,7 @@ class PauseAt(_Action):
self.seconds = seconds
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Literal("p").suppress()
e += base.TokOffset
e += pp.Literal(",").suppress()
@@ -63,7 +63,7 @@ class PauseAt(_Action):
pp.Literal("f")
]
)
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
return "p%s,%s" % (self.offset, self.seconds)
@@ -80,10 +80,10 @@ class DisconnectAt(_Action):
_Action.__init__(self, offset)
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Literal("d").suppress()
e += base.TokOffset
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
return "d%s" % self.offset
@@ -103,12 +103,12 @@ class InjectAt(_Action):
self.value = value
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Literal("i").suppress()
e += base.TokOffset
e += pp.Literal(",").suppress()
e += base.TokValue
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
return "i%s,%s" % (self.offset, self.value.spec())
diff --git a/libpathod/language/base.py b/libpathod/language/base.py
index 88712d69..726580fc 100644
--- a/libpathod/language/base.py
+++ b/libpathod/language/base.py
@@ -5,10 +5,8 @@ import pyparsing as pp
from .. import utils
from . import generators, exceptions
-from functools import reduce
-
-class Settings:
+class Settings(object):
def __init__(
self,
is_client = False,
@@ -66,7 +64,7 @@ class Token(object):
__metaclass__ = abc.ABCMeta
@classmethod
- def expr(klass): # pragma: no cover
+ def expr(cls): # pragma: no cover
"""
A parse expression.
"""
@@ -118,13 +116,13 @@ class TokValueLiteral(_TokValueLiteral):
A literal with Python-style string escaping
"""
@classmethod
- def expr(klass):
+ def expr(cls):
e = v_literal.copy()
- return e.setParseAction(klass.parseAction)
+ return e.setParseAction(cls.parseAction)
@classmethod
- def parseAction(klass, x):
- v = klass(*x)
+ def parseAction(cls, x):
+ v = cls(*x)
return v
def spec(self):
@@ -135,9 +133,9 @@ class TokValueLiteral(_TokValueLiteral):
class TokValueNakedLiteral(_TokValueLiteral):
@classmethod
- def expr(klass):
+ def expr(cls):
e = v_naked_literal.copy()
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
return self.val.encode("string_escape")
@@ -160,7 +158,7 @@ class TokValueGenerate(Token):
return TokValueLiteral(g[:].encode("string_escape"))
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Literal("@").suppress() + v_integer
u = reduce(
@@ -175,7 +173,7 @@ class TokValueGenerate(Token):
[pp.Literal(i) for i in generators.DATATYPES.keys()]
)
e += pp.Optional(s, default="bytes")
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
s = "@%s" % self.usize
@@ -191,10 +189,10 @@ class TokValueFile(Token):
self.path = str(path)
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Literal("<").suppress()
e = e + v_naked_literal
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def freeze(self, settings):
return self
@@ -269,19 +267,19 @@ class _Component(Token):
class KeyValue(_Component):
"""
A key/value pair.
- klass.preamble: leader
+ cls.preamble: leader
"""
def __init__(self, key, value):
self.key, self.value = key, value
@classmethod
- def expr(klass):
- e = pp.Literal(klass.preamble).suppress()
+ def expr(cls):
+ e = pp.Literal(cls.preamble).suppress()
e += TokValue
e += pp.Literal("=").suppress()
e += TokValue
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def spec(self):
return "%s%s=%s" % (self.preamble, self.key.spec(), self.value.spec())
@@ -301,9 +299,9 @@ class CaselessLiteral(_Component):
self.value = value
@classmethod
- def expr(klass):
- spec = pp.CaselessLiteral(klass.TOK)
- spec = spec.setParseAction(lambda x: klass(*x))
+ def expr(cls):
+ spec = pp.CaselessLiteral(cls.TOK)
+ spec = spec.setParseAction(lambda x: cls(*x))
return spec
def values(self, settings):
@@ -338,13 +336,13 @@ class OptionsOrValue(_Component):
self.value = value
@classmethod
- def expr(klass):
- parts = [pp.CaselessLiteral(i) for i in klass.options]
+ def expr(cls):
+ parts = [pp.CaselessLiteral(i) for i in cls.options]
m = pp.MatchFirst(parts)
spec = m | TokValue.copy()
- spec = spec.setParseAction(lambda x: klass(*x))
- if klass.preamble:
- spec = pp.Literal(klass.preamble).suppress() + spec
+ spec = spec.setParseAction(lambda x: cls(*x))
+ if cls.preamble:
+ spec = pp.Literal(cls.preamble).suppress() + spec
return spec
def values(self, settings):
@@ -380,11 +378,11 @@ class Integer(_Component):
self.value = str(value)
@classmethod
- def expr(klass):
+ def expr(cls):
e = v_integer.copy()
- if klass.preamble:
- e = pp.Literal(klass.preamble).suppress() + e
- return e.setParseAction(lambda x: klass(*x))
+ if cls.preamble:
+ e = pp.Literal(cls.preamble).suppress() + e
+ return e.setParseAction(lambda x: cls(*x))
def values(self, settings):
return self.value
@@ -406,11 +404,11 @@ class Value(_Component):
self.value = value
@classmethod
- def expr(klass):
+ def expr(cls):
e = (TokValue | TokNakedValue)
- if klass.preamble:
- e = pp.Literal(klass.preamble).suppress() + e
- return e.setParseAction(lambda x: klass(*x))
+ if cls.preamble:
+ e = pp.Literal(cls.preamble).suppress() + e
+ return e.setParseAction(lambda x: cls(*x))
def values(self, settings):
return [self.value.get_generator(settings)]
@@ -474,15 +472,15 @@ class Boolean(_Component):
self.value = value
@classmethod
- def expr(klass):
+ def expr(cls):
e = pp.Optional(pp.Literal("-"), default=True)
- e += pp.Literal(klass.name).suppress()
+ e += pp.Literal(cls.name).suppress()
def parse(s, loc, toks):
val = True
if toks[0] == "-":
val = False
- return klass(val)
+ return cls(val)
return e.setParseAction(parse)
@@ -507,13 +505,13 @@ class IntField(_Component):
)
@classmethod
- def expr(klass):
- parts = [pp.CaselessLiteral(i) for i in klass.names.keys()]
+ def expr(cls):
+ parts = [pp.CaselessLiteral(i) for i in cls.names.keys()]
m = pp.MatchFirst(parts)
spec = m | v_integer.copy()
- spec = spec.setParseAction(lambda x: klass(*x))
- if klass.preamble:
- spec = pp.Literal(klass.preamble).suppress() + spec
+ spec = spec.setParseAction(lambda x: cls(*x))
+ if cls.preamble:
+ spec = pp.Literal(cls.preamble).suppress() + spec
return spec
def values(self, settings):
@@ -544,10 +542,10 @@ class NestedMessage(Token):
raise exceptions.ParseException(v.msg, v.line, v.col)
@classmethod
- def expr(klass):
- e = pp.Literal(klass.preamble).suppress()
+ def expr(cls):
+ e = pp.Literal(cls.preamble).suppress()
e = e + TokValueLiteral.expr()
- return e.setParseAction(lambda x: klass(*x))
+ return e.setParseAction(lambda x: cls(*x))
def values(self, settings):
return [
diff --git a/libpathod/language/generators.py b/libpathod/language/generators.py
index 0da0cb4d..d351e790 100644
--- a/libpathod/language/generators.py
+++ b/libpathod/language/generators.py
@@ -16,7 +16,7 @@ DATATYPES = dict(
)
-class TransformGenerator:
+class TransformGenerator(object):
"""
Perform a byte-by-byte transform another generator - that is, for each
input byte, the transformation must produce one output byte.
@@ -44,7 +44,7 @@ class TransformGenerator:
return "'transform(%s)'" % self.gen
-class RandomGenerator:
+class RandomGenerator(object):
def __init__(self, dtype, length):
self.dtype = dtype
self.length = length
@@ -64,7 +64,7 @@ class RandomGenerator:
return "%s random from %s" % (self.length, self.dtype)
-class FileGenerator:
+class FileGenerator(object):
def __init__(self, path):
self.path = path
self.fp = file(path, "rb")
diff --git a/libpathod/language/http.py b/libpathod/language/http.py
index 115f8069..3979a1ee 100644
--- a/libpathod/language/http.py
+++ b/libpathod/language/http.py
@@ -226,8 +226,8 @@ class Response(_HTTPMessage):
)
@classmethod
- def expr(klass):
- parts = [i.expr() for i in klass.comps]
+ def expr(cls):
+ parts = [i.expr() for i in cls.comps]
atom = pp.MatchFirst(parts)
resp = pp.And(
[
@@ -242,7 +242,7 @@ class Response(_HTTPMessage):
pp.ZeroOrMore(base.Sep + atom)
]
)
- resp = resp.setParseAction(klass)
+ resp = resp.setParseAction(cls)
return resp
def spec(self):
@@ -342,8 +342,8 @@ class Request(_HTTPMessage):
)
@classmethod
- def expr(klass):
- parts = [i.expr() for i in klass.comps]
+ def expr(cls):
+ parts = [i.expr() for i in cls.comps]
atom = pp.MatchFirst(parts)
resp = pp.And(
[
@@ -360,7 +360,7 @@ class Request(_HTTPMessage):
pp.ZeroOrMore(base.Sep + atom)
]
)
- resp = resp.setParseAction(klass)
+ resp = resp.setParseAction(cls)
return resp
def spec(self):
diff --git a/libpathod/language/http2.py b/libpathod/language/http2.py
index dec2d5fe..b13d50de 100644
--- a/libpathod/language/http2.py
+++ b/libpathod/language/http2.py
@@ -1,15 +1,20 @@
-import os
-import netlib.http2
import pyparsing as pp
-from . import base, generators, actions, message
+from . import base, actions, message
"""
Normal HTTP requests:
<method>:<path>:<header>:<body>
e.g.:
GET:/
- GET:/:foo=bar
- POST:/:foo=bar:'content body payload'
+ GET:/:h"foo"="bar"
+ POST:/:h"foo"="bar":b'content body payload'
+
+ Normal HTTP responses:
+ <code>:<header>:<body>
+ e.g.:
+ 200
+ 302:h"foo"="bar"
+ 404:h"foo"="bar":b'content body payload'
Individual HTTP/2 frames:
h2f:<payload_length>:<type>:<flags>:<stream_id>:<payload>
@@ -94,8 +99,8 @@ class Request(message.Message):
return []
@classmethod
- def expr(klass):
- parts = [i.expr() for i in klass.comps]
+ def expr(cls):
+ parts = [i.expr() for i in cls.comps]
atom = pp.MatchFirst(parts)
resp = pp.And(
[
@@ -105,7 +110,7 @@ class Request(message.Message):
pp.ZeroOrMore(base.Sep + atom)
]
)
- resp = resp.setParseAction(klass)
+ resp = resp.setParseAction(cls)
return resp
def resolve(self, settings, msg=None):
@@ -164,8 +169,8 @@ class Response(message.Message):
return self
@classmethod
- def expr(klass):
- parts = [i.expr() for i in klass.comps]
+ def expr(cls):
+ parts = [i.expr() for i in cls.comps]
atom = pp.MatchFirst(parts)
resp = pp.And(
[
@@ -173,7 +178,7 @@ class Response(message.Message):
pp.ZeroOrMore(base.Sep + atom)
]
)
- resp = resp.setParseAction(klass)
+ resp = resp.setParseAction(cls)
return resp
def values(self, settings):
@@ -196,6 +201,7 @@ class Response(message.Message):
def spec(self):
return ":".join([i.spec() for i in self.tokens])
+
def make_error_response(reason, body=None):
tokens = [
Code("800"),
@@ -203,5 +209,6 @@ def make_error_response(reason, body=None):
]
return Response(tokens)
+
# class Frame(message.Message):
# pass
diff --git a/libpathod/language/message.py b/libpathod/language/message.py
index 8c58f021..33124856 100644
--- a/libpathod/language/message.py
+++ b/libpathod/language/message.py
@@ -66,7 +66,7 @@ class Message(object):
return l
@classmethod
- def expr(klass): # pragma: no cover
+ def expr(cls): # pragma: no cover
pass
def log(self, settings):
diff --git a/libpathod/language/websockets.py b/libpathod/language/websockets.py
index 51c1b3ee..18a20025 100644
--- a/libpathod/language/websockets.py
+++ b/libpathod/language/websockets.py
@@ -150,8 +150,8 @@ class WebsocketFrame(message.Message):
return self.tok(Length)
@classmethod
- def expr(klass):
- parts = [i.expr() for i in klass.components]
+ def expr(cls):
+ parts = [i.expr() for i in cls.components]
atom = pp.MatchFirst(parts)
resp = pp.And(
[
@@ -160,7 +160,7 @@ class WebsocketFrame(message.Message):
pp.ZeroOrMore(base.Sep + atom)
]
)
- resp = resp.setParseAction(klass)
+ resp = resp.setParseAction(cls)
return resp
@property
diff --git a/libpathod/log.py b/libpathod/log.py
index 523f431c..7355cbd0 100644
--- a/libpathod/log.py
+++ b/libpathod/log.py
@@ -18,7 +18,7 @@ def write(fp, lines):
fp.flush()
-class Log:
+class Log(object):
def __init__(self, fp, hex, rfile, wfile):
self.lines = []
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py
index c42cc82a..b2a8ec22 100644
--- a/libpathod/pathoc.py
+++ b/libpathod/pathoc.py
@@ -25,7 +25,7 @@ class PathocError(Exception):
pass
-class SSLInfo:
+class SSLInfo(object):
def __init__(self, certchain, cipher, alp):
self.certchain, self.cipher, self.alp = certchain, cipher, alp
@@ -65,7 +65,7 @@ class SSLInfo:
return "\n".join(parts)
-class Response:
+class Response(object):
def __init__(
self,
httpversion,
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 212abbdc..240df7bd 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -4,7 +4,6 @@ import os
import sys
import threading
import urllib
-import re
import time
from netlib import tcp, http, http2, wsgi, certutils, websockets, odict
@@ -29,7 +28,7 @@ class PathodError(Exception):
pass
-class SSLOptions:
+class SSLOptions(object):
def __init__(
self,
confdir=CONFDIR,
@@ -241,7 +240,7 @@ class PathodHandler(tcp.BaseHandler):
return req['next_handle']
if 'errors' in req:
return None, req['errors']
- if not 'method' in req or not 'path' in req:
+ if 'method' not in req or 'path' not in req:
return None, None
method = req['method']
path = req['path']
@@ -443,11 +442,11 @@ class PathodHandler(tcp.BaseHandler):
# moment because JSON encoding can't handle binary data, and I don't
# want to base64 everything.
if self.server.logreq:
- bytes = self.rfile.get_log().encode("string_escape")
- log["request_bytes"] = bytes
+ encoded_bytes = self.rfile.get_log().encode("string_escape")
+ log["request_bytes"] = encoded_bytes
if self.server.logresp:
- bytes = self.wfile.get_log().encode("string_escape")
- log["response_bytes"] = bytes
+ encoded_bytes = self.wfile.get_log().encode("string_escape")
+ log["response_bytes"] = encoded_bytes
self.server.add_log(log)
diff --git a/libpathod/pathod_cmdline.py b/libpathod/pathod_cmdline.py
index 4343401f..e5fa0bcd 100644
--- a/libpathod/pathod_cmdline.py
+++ b/libpathod/pathod_cmdline.py
@@ -4,8 +4,7 @@ import argparse
import os
import os.path
import re
-from netlib import http_uastrings
-from . import pathoc, pathod, version, utils, language
+from . import pathod, version, utils, language
def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
diff --git a/libpathod/utils.py b/libpathod/utils.py
index 481c5137..ac21dd13 100644
--- a/libpathod/utils.py
+++ b/libpathod/utils.py
@@ -20,7 +20,7 @@ SIZE_UNITS = dict(
)
-class MemBool:
+class MemBool(object):
"""
Truth-checking with a memory, for use in chained if statements.
"""
@@ -51,7 +51,7 @@ def parse_anchor_spec(s):
"""
Return a tuple, or None on error.
"""
- if not "=" in s:
+ if "=" not in s:
return None
return tuple(s.split("=", 1))
@@ -83,7 +83,7 @@ def escape_unprintables(s):
return s
-class Data:
+class Data(object):
def __init__(self, name):
m = __import__(name)
dirname, _ = os.path.split(m.__file__)