Skip to content
This repository has been archived by the owner on Jun 1, 2018. It is now read-only.

Commit

Permalink
Add coding style check, reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
cortesi committed May 30, 2015
1 parent 904760c commit 4ed5043
Show file tree
Hide file tree
Showing 31 changed files with 242 additions and 145 deletions.
20 changes: 20 additions & 0 deletions check_coding_style.sh
@@ -0,0 +1,20 @@
#!/bin/bash

autopep8 -i -r -a -a .
if [[ -n "$(git status -s)" ]]; then
echo "autopep8 yielded the following changes:"
git status -s
git --no-pager diff
exit 1
fi

autoflake -i -r --remove-all-unused-imports --remove-unused-variables .
if [[ -n "$(git status -s)" ]]; then
echo "autoflake yielded the following changes:"
git status -s
git --no-pager diff
exit 1
fi

echo "Coding style seems to be ok."
exit 0
1 change: 1 addition & 0 deletions examples/test_context.py
@@ -1,6 +1,7 @@
import requests
from libpathod import test


def test_simple():
"""
Testing the requests module with
Expand Down
2 changes: 2 additions & 0 deletions examples/test_setup.py
@@ -1,12 +1,14 @@
import requests
from libpathod import test


class Test:
"""
Testing the requests module with
a pathod instance started for
each test.
"""

def setUp(self):
self.d = test.Daemon()

Expand Down
5 changes: 3 additions & 2 deletions examples/test_setupall.py
@@ -1,10 +1,11 @@
import requests
from libpathod import test


class Test:
"""
Testing the requests module with
a single pathod instance started
Testing the requests module with
a single pathod instance started
for the test suite.
"""
@classmethod
Expand Down
1 change: 0 additions & 1 deletion libpathod/__init__.py
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion libpathod/app.py
Expand Up @@ -138,7 +138,7 @@ def _preview(is_request):
r = language.parse_requests(spec)[0]
else:
r = language.parse_response(spec)
except language.ParseException, v:
except language.ParseException as v:
args["syntaxerror"] = str(v)
args["marked"] = v.marked()
return render(template, False, **args)
Expand Down
57 changes: 36 additions & 21 deletions libpathod/cmdline.py
Expand Up @@ -163,16 +163,22 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
try:
args.ignorecodes = [int(i) for i in args.ignorecodes.split(",") if i]
except ValueError:
return parser.error("Invalid return code specification: %s"%args.ignorecodes)
return parser.error(
"Invalid return code specification: %s" %
args.ignorecodes)

if args.connect_to:
parts = args.connect_to.split(":")
if len(parts) != 2:
return parser.error("Invalid CONNECT specification: %s"%args.connect_to)
return parser.error(
"Invalid CONNECT specification: %s" %
args.connect_to)
try:
parts[1] = int(parts[1])
except ValueError:
return parser.error("Invalid CONNECT specification: %s"%args.connect_to)
return parser.error(
"Invalid CONNECT specification: %s" %
args.connect_to)
args.connect_to = parts
else:
args.connect_to = None
Expand All @@ -184,15 +190,15 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
r = data
try:
reqs.extend(language.parse_requests(r))
except language.ParseException, v:
print >> stderr, "Error parsing request spec: %s"%v.msg
except language.ParseException as v:
print >> stderr, "Error parsing request spec: %s" % v.msg
print >> stderr, v.marked()
sys.exit(1)
args.requests = reqs
return args


def go_pathoc(): # pragma: nocover
def go_pathoc(): # pragma: nocover
args = args_pathoc(sys.argv)
pathoc.main(args)

Expand Down Expand Up @@ -254,9 +260,11 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
help="Connection timeout"
)
parser.add_argument(
"--limit-size", dest='sizelimit', default=None, type=str,
help='Size limit of served responses. Understands size suffixes, i.e. 100k.'
)
"--limit-size",
dest='sizelimit',
default=None,
type=str,
help='Size limit of served responses. Understands size suffixes, i.e. 100k.')
parser.add_argument(
"--noapi", dest='noapi', default=False, action="store_true",
help='Disable API.'
Expand All @@ -270,9 +278,11 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
help='Disable both web interface and API.'
)
parser.add_argument(
"--nocraft", dest='nocraft', default=False, action="store_true",
help='Disable response crafting. If anchors are specified, they still work.'
)
"--nocraft",
dest='nocraft',
default=False,
action="store_true",
help='Disable response crafting. If anchors are specified, they still work.')
parser.add_argument(
"--webdebug", dest='webdebug', default=False, action="store_true",
help='Debugging mode for the web app (dev only).'
Expand All @@ -286,9 +296,12 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
help='Run in HTTPS mode.'
)
group.add_argument(
"--cn", dest="cn", type=str, default=None,
help="CN for generated SSL certs. Default: %s"%pathod.DEFAULT_CERT_DOMAIN
)
"--cn",
dest="cn",
type=str,
default=None,
help="CN for generated SSL certs. Default: %s" %
pathod.DEFAULT_CERT_DOMAIN)
group.add_argument(
"-C", dest='ssl_not_after_connect', default=False, action="store_true",
help="Don't expect SSL after a CONNECT request."
Expand Down Expand Up @@ -358,23 +371,25 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
parts = ["*", parts[0]]
parts[1] = os.path.expanduser(parts[1])
if not os.path.isfile(parts[1]):
return parser.error("Certificate file does not exist: %s"%parts[1])
return parser.error(
"Certificate file does not exist: %s" %
parts[1])
certs.append(parts)
args.ssl_certs = certs

alst = []
for i in args.anchors:
parts = utils.parse_anchor_spec(i)
if not parts:
return parser.error("Invalid anchor specification: %s"%i)
return parser.error("Invalid anchor specification: %s" % i)
alst.append(parts)
args.anchors = alst

sizelimit = None
if args.sizelimit:
try:
sizelimit = utils.parse_size(args.sizelimit)
except ValueError, v:
except ValueError as v:
return parser.error(v)
args.sizelimit = sizelimit

Expand All @@ -385,8 +400,8 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
spec = data
try:
req = language.parse_response(spec)
except language.ParseException, v:
print >> stderr, "Error parsing anchor spec: %s"%v.msg
except language.ParseException as v:
print >> stderr, "Error parsing anchor spec: %s" % v.msg
print >> stderr, v.marked()
sys.exit(1)
try:
Expand All @@ -398,6 +413,6 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
return args


def go_pathod(): # pragma: nocover
def go_pathod(): # pragma: nocover
args = args_pathod(sys.argv)
pathod.main(args)
7 changes: 3 additions & 4 deletions libpathod/language/__init__.py
Expand Up @@ -18,7 +18,7 @@ def parse_response(s):
raise exceptions.ParseException("Spec must be valid ASCII.", 0, 0)
try:
return http.Response.expr().parseString(s, parseAll=True)[0]
except pp.ParseException, v:
except pp.ParseException as v:
raise exceptions.ParseException(v.msg, v.line, v.col)


Expand All @@ -39,7 +39,7 @@ def parse_requests(s):
]
)
).parseString(s, parseAll=True)
except pp.ParseException, v:
except pp.ParseException as v:
raise exceptions.ParseException(v.msg, v.line, v.col)
expanded = []
for i in reqs:
Expand Down Expand Up @@ -67,8 +67,7 @@ def serve(msg, fp, settings):
vals = msg.values(settings)
vals.reverse()

actions = msg.actions[:]
actions.sort()
actions = sorted(msg.actions[:])
actions.reverse()
actions = [i.intermediate(settings) for i in actions]

Expand Down
11 changes: 6 additions & 5 deletions libpathod/language/actions.py
Expand Up @@ -13,6 +13,7 @@ class _Action(base.Token):
actions have one thing in common: an offset that specifies where the
action should take place.
"""

def __init__(self, offset):
self.offset = offset

Expand All @@ -36,11 +37,11 @@ def __repr__(self):
return self.spec()

@abc.abstractmethod
def spec(self): # pragma: no cover
def spec(self): # pragma: no cover
pass

@abc.abstractmethod
def intermediate(self, settings): # pragma: no cover
def intermediate(self, settings): # pragma: no cover
pass


Expand All @@ -65,7 +66,7 @@ def expr(klass):
return e.setParseAction(lambda x: klass(*x))

def spec(self):
return "p%s,%s"%(self.offset, self.seconds)
return "p%s,%s" % (self.offset, self.seconds)

def intermediate(self, settings):
return (self.offset, "pause", self.seconds)
Expand All @@ -85,7 +86,7 @@ def expr(klass):
return e.setParseAction(lambda x: klass(*x))

def spec(self):
return "d%s"%self.offset
return "d%s" % self.offset

def intermediate(self, settings):
return (self.offset, "disconnect")
Expand All @@ -110,7 +111,7 @@ def expr(klass):
return e.setParseAction(lambda x: klass(*x))

def spec(self):
return "i%s,%s"%(self.offset, self.value.spec())
return "i%s,%s" % (self.offset, self.value.spec())

def intermediate(self, settings):
return (
Expand Down

0 comments on commit 4ed5043

Please sign in to comment.