From bfc889d29afdd902b5df30336ff73e484a3592fc Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 18 Jun 2015 18:05:09 +0200 Subject: [PATCH] fix prospector code smells --- .landscape.yml | 3 +++ libpathod/app.py | 17 +++++++++-------- libpathod/language/__init__.py | 2 +- libpathod/language/actions.py | 4 ++-- libpathod/language/base.py | 16 ++++++++-------- libpathod/language/http2.py | 2 +- libpathod/pathoc.py | 6 +++--- libpathod/pathoc_cmdline.py | 3 +-- libpathod/pathod.py | 8 ++++---- libpathod/pathod_cmdline.py | 4 ++-- 10 files changed, 34 insertions(+), 31 deletions(-) diff --git a/.landscape.yml b/.landscape.yml index 5926e7bf6..ccaa5fc36 100644 --- a/.landscape.yml +++ b/.landscape.yml @@ -1,5 +1,8 @@ max-line-length: 120 pylint: + options: + dummy-variables-rgx: _$|.+_$|dummy_.+ + disable: - missing-docstring - protected-access diff --git a/libpathod/app.py b/libpathod/app.py index 5bf331ac6..cd7a8bd61 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -10,6 +10,7 @@ logging.basicConfig(level="DEBUG") EXAMPLE_HOST = "example.com" EXAMPLE_WEBSOCKET_KEY = "examplekey" +# pylint: disable=unused-variable def make_app(noapi, debug): app = Flask(__name__) @@ -145,24 +146,24 @@ def make_app(noapi, debug): s = cStringIO.StringIO() - set = copy.copy(app.config["pathod"].settings) - set.request_host = EXAMPLE_HOST - set.websocket_key = EXAMPLE_WEBSOCKET_KEY + settings = copy.copy(app.config["pathod"].settings) + settings.request_host = EXAMPLE_HOST + settings.websocket_key = EXAMPLE_WEBSOCKET_KEY safe = r.preview_safe() err, safe = app.config["pathod"].check_policy( safe, - set + settings ) if err: args["error"] = err return render(template, False, **args) if is_request: - set.request_host = EXAMPLE_HOST - language.serve(safe, s, set) + settings.request_host = EXAMPLE_HOST + language.serve(safe, s, settings) else: - set.websocket_key = EXAMPLE_WEBSOCKET_KEY - language.serve(safe, s, set) + settings.websocket_key = EXAMPLE_WEBSOCKET_KEY + language.serve(safe, s, settings) args["output"] = utils.escape_unprintables(s.getvalue()) return render(template, False, **args) diff --git a/libpathod/language/__init__.py b/libpathod/language/__init__.py index 10050bf82..4b06f7e41 100644 --- a/libpathod/language/__init__.py +++ b/libpathod/language/__init__.py @@ -13,7 +13,7 @@ assert Settings # prevent pyflakes from messing with this def expand(msg): times = getattr(msg, "times", None) if times: - for j in xrange(int(times.value)): + for j_ in xrange(int(times.value)): yield msg.strike_token("times") else: yield msg diff --git a/libpathod/language/actions.py b/libpathod/language/actions.py index f825d0ccf..7bb610051 100644 --- a/libpathod/language/actions.py +++ b/libpathod/language/actions.py @@ -71,7 +71,7 @@ class PauseAt(_Action): def intermediate(self, settings): return (self.offset, "pause", self.seconds) - def freeze(self, settings): + def freeze(self, settings_): return self @@ -91,7 +91,7 @@ class DisconnectAt(_Action): def intermediate(self, settings): return (self.offset, "disconnect") - def freeze(self, settings): + def freeze(self, settings_): return self diff --git a/libpathod/language/base.py b/libpathod/language/base.py index 726580fc4..1f42f65e8 100644 --- a/libpathod/language/base.py +++ b/libpathod/language/base.py @@ -86,7 +86,7 @@ class Token(object): """ return self.__class__.__name__.lower() - def resolve(self, settings, msg): + def resolve(self, settings_, msg_): """ Resolves this token to ready it for transmission. This means that the calculated offsets of actions are fixed. @@ -104,10 +104,10 @@ class _TokValueLiteral(Token): def __init__(self, val): self.val = val.decode("string_escape") - def get_generator(self, settings): + def get_generator(self, settings_): return self.val - def freeze(self, settings): + def freeze(self, settings_): return self @@ -150,7 +150,7 @@ class TokValueGenerate(Token): def bytes(self): return self.usize * utils.SIZE_UNITS[self.unit] - def get_generator(self, settings): + def get_generator(self, settings_): return generators.RandomGenerator(self.datatype, self.bytes()) def freeze(self, settings): @@ -194,7 +194,7 @@ class TokValueFile(Token): e = e + v_naked_literal return e.setParseAction(lambda x: cls(*x)) - def freeze(self, settings): + def freeze(self, settings_): return self def get_generator(self, settings): @@ -310,7 +310,7 @@ class CaselessLiteral(_Component): def spec(self): return self.TOK - def freeze(self, settings): + def freeze(self, settings_): return self @@ -390,7 +390,7 @@ class Integer(_Component): def spec(self): return "%s%s" % (self.preamble, self.value) - def freeze(self, settings): + def freeze(self, settings_): return self @@ -476,7 +476,7 @@ class Boolean(_Component): e = pp.Optional(pp.Literal("-"), default=True) e += pp.Literal(cls.name).suppress() - def parse(s, loc, toks): + def parse(s_, loc_, toks): val = True if toks[0] == "-": val = False diff --git a/libpathod/language/http2.py b/libpathod/language/http2.py index b13d50de6..86e040566 100644 --- a/libpathod/language/http2.py +++ b/libpathod/language/http2.py @@ -1,5 +1,5 @@ import pyparsing as pp -from . import base, actions, message +from . import base, message """ Normal HTTP requests: diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index b2a8ec224..6b040214c 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -123,7 +123,7 @@ class WebsocketFrameReader(threading.Thread): while True: if self.ws_read_limit == 0: return - r, _, x = select.select([self.rfile], [], [], 0.05) + r, _, _ = select.select([self.rfile], [], [], 0.05) delta = time.time() - starttime if not r and self.timeout and delta > self.timeout: return @@ -501,11 +501,11 @@ def main(args): # pragma: nocover if ret and args.oneshot: return # We consume the queue when we can, so it doesn't build up. - for i in p.wait(timeout=0, finish=False): + for i_ in p.wait(timeout=0, finish=False): pass except (http.HttpError, tcp.NetLibError) as v: break - for i in p.wait(timeout=0.01, finish=True): + for i_ in p.wait(timeout=0.01, finish=True): pass except KeyboardInterrupt: pass diff --git a/libpathod/pathoc_cmdline.py b/libpathod/pathoc_cmdline.py index 1d0df3b55..3722c7dce 100644 --- a/libpathod/pathoc_cmdline.py +++ b/libpathod/pathoc_cmdline.py @@ -3,9 +3,8 @@ import sys import argparse import os import os.path -import re from netlib import http_uastrings -from . import pathoc, pathod, version, utils, language +from . import pathoc, version, utils, language def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 001ab085e..695f62a53 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -171,7 +171,7 @@ class PathodHandler(tcp.BaseHandler): self.wfile.flush() if not self.server.ssloptions.not_after_connect: try: - cert, key, chain_file = self.server.ssloptions.get_cert( + cert, key, chain_file_ = self.server.ssloptions.get_cert( connect[0] ) self.convert_to_ssl( @@ -310,7 +310,7 @@ class PathodHandler(tcp.BaseHandler): anchor_gen = iter([self.make_http_error_response( "Spec Error", "HTTP/2 only supports request/response with the craft anchor point: %s" % - self.server.craftanchor + self.server.craftanchor )]) @@ -576,9 +576,9 @@ class Pathod(tcp.TCPServer): with lock: self.log = [] - def log_by_id(self, id): + def log_by_id(self, identifier): for i in self.log: - if i["id"] == id: + if i["id"] == identifier: return i def get_log(self): diff --git a/libpathod/pathod_cmdline.py b/libpathod/pathod_cmdline.py index e5fa0bcd8..1e3516ec2 100644 --- a/libpathod/pathod_cmdline.py +++ b/libpathod/pathod_cmdline.py @@ -4,10 +4,10 @@ import argparse import os import os.path import re -from . import pathod, version, utils, language +from . import pathod, version, utils -def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr): +def args_pathod(argv, stdout_=sys.stdout, stderr_=sys.stderr): parser = argparse.ArgumentParser( description='A pathological HTTP/S daemon.' )