Whitespace, small fixes.

This commit is contained in:
Aldo Cortesi 2015-04-20 08:56:47 +12:00
parent 3891fe5638
commit be450cf9db
7 changed files with 45 additions and 40 deletions

View File

@ -4,8 +4,8 @@ import os
import os.path
import sys
import re
from . import pathoc, pathod, version, utils, language
from netlib import http_uastrings
from . import pathoc, pathod, version, utils, language
def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):

View File

@ -51,7 +51,7 @@ def send_chunk(fp, val, blocksize, start, end):
return end-start
def write_values(fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE):
def write_values(fp, vals, actions, sofar=0, blocksize=BLOCKSIZE):
"""
vals: A list of values, which may be strings or Value objects.
@ -235,7 +235,7 @@ class _Token(object):
"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
@classmethod
def expr(klass): # pragma: no cover
"""
A parse expression.
@ -709,7 +709,7 @@ class _Action(_Token):
pass
@abc.abstractmethod
def intermediate(self): # pragma: no cover
def intermediate(self, settings): # pragma: no cover
pass
@ -791,6 +791,7 @@ class InjectAt(_Action):
class _Message(object):
__metaclass__ = abc.ABCMeta
version = "HTTP/1.1"
logattrs = []
def __init__(self, tokens):
self.tokens = tokens
@ -873,7 +874,7 @@ class _Message(object):
def preamble(self, settings): # pragma: no cover
pass
@abc.abstractmethod
@classmethod
def expr(klass): # pragma: no cover
pass

View File

@ -116,6 +116,7 @@ class Pathoc(tcp.TCPClient):
self.clientcert = clientcert
self.sslversion = utils.SSLVERSIONS[sslversion]
self.ciphers = ciphers
self.sslinfo = None
self.showreq = showreq
self.showresp = showresp
@ -187,6 +188,8 @@ class Pathoc(tcp.TCPClient):
r: A language.Request object, or a string representing one request.
Returns True if we have a non-ignored response.
May raise http.HTTPError, tcp.NetLibError
"""
if isinstance(r, basestring):
r = language.parse_requests(r)[0]
@ -203,7 +206,6 @@ class Pathoc(tcp.TCPClient):
self.address.host
)
self.wfile.flush()
resp = list(http.read_response(self.rfile, r.method.string(), None))
resp.append(self.sslinfo)
resp = Response(*resp)
@ -224,22 +226,25 @@ class Pathoc(tcp.TCPClient):
finally:
if req:
if self.ignorecodes and resp and resp.status_code in self.ignorecodes:
return None
resp = None
else:
if self.explain:
print >> self.fp, ">> Spec:", r.spec()
if self.explain:
print >> self.fp, ">> Spec:", r.spec()
if self.showreq:
self._show(
self.fp, ">> Request", self.wfile.get_log(), self.hexdump
)
if self.showreq:
self._show(
self.fp, ">> Request", self.wfile.get_log(), self.hexdump
)
if self.showsummary and resp:
self._show_summary(self.fp, resp)
if self.showresp:
self._show(
self.fp, "<< Response", self.rfile.get_log(), self.hexdump
)
if self.showsummary and resp:
self._show_summary(self.fp, resp)
if self.showresp:
self._show(
self.fp,
"<< Response",
self.rfile.get_log(),
self.hexdump
)
return resp
@ -310,7 +315,7 @@ def main(args): # pragma: nocover
sys.stdout.flush()
if ret and args.oneshot:
return
except (http.HttpError, tcp.NetlibError), v:
except (http.HttpError, tcp.NetLibError), v:
pass
except KeyboardInterrupt:
pass

View File

@ -233,7 +233,7 @@ class PathodHandler(tcp.BaseHandler):
def handle(self):
if self.server.ssl:
try:
cert, key, chain_file = self.server.ssloptions.get_cert(None)
cert, key, _ = self.server.ssloptions.get_cert(None)
self.convert_to_ssl(
cert, key,
handle_sni=self.handle_sni,
@ -276,7 +276,6 @@ class Pathod(tcp.TCPServer):
def __init__(
self,
addr,
confdir=CONFDIR,
ssl=False,
ssloptions=None,
craftanchor="/p/",

View File

@ -18,10 +18,10 @@ class _TestDaemon:
@classmethod
def setUpAll(self):
self.d = test.Daemon(
ssl=self.ssl,
ssloptions=self.ssloptions,
staticdir=tutils.test_data.path("data"),
anchors=[
ssl = self.ssl,
ssloptions = self.ssloptions,
staticdir = tutils.test_data.path("data"),
anchors = [
(re.compile("/anchor/.*"), language.parse_response("202"))
]
)

View File

@ -3,7 +3,7 @@ from netlib import tcp, http
import tutils
class TestPathod:
class TestPathod(object):
def test_logging(self):
p = pathod.Pathod(("127.0.0.1", 0))
assert len(p.get_log()) == 0

View File

@ -7,7 +7,7 @@ from libpathod import utils, test, pathoc, pathod, language
import requests
class DaemonTests:
class DaemonTests(object):
noweb = False
noapi = False
nohang = False
@ -17,24 +17,24 @@ class DaemonTests:
ssloptions = None
@classmethod
def setUpAll(self):
opts = self.ssloptions or {}
self.confdir = tempfile.mkdtemp()
opts["confdir"] = self.confdir
def setUpAll(klass):
opts = klass.ssloptions or {}
klass.confdir = tempfile.mkdtemp()
opts["confdir"] = klass.confdir
so = pathod.SSLOptions(**opts)
self.d = test.Daemon(
klass.d = test.Daemon(
staticdir=test_data.path("data"),
anchors=[
(re.compile("/anchor/.*"), language.parse_response("202:da"))
],
ssl = self.ssl,
ssl = klass.ssl,
ssloptions = so,
sizelimit=1*1024*1024,
noweb = self.noweb,
noapi = self.noapi,
nohang = self.nohang,
timeout = self.timeout,
hexdump = self.hexdump,
noweb = klass.noweb,
noapi = klass.noapi,
nohang = klass.nohang,
timeout = klass.timeout,
hexdump = klass.hexdump,
logreq = True,
logresp = True,
explain = True