aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/language
diff options
context:
space:
mode:
Diffstat (limited to 'libpathod/language')
-rw-r--r--libpathod/language/__init__.py8
-rw-r--r--libpathod/language/actions.py2
-rw-r--r--libpathod/language/base.py28
-rw-r--r--libpathod/language/exceptions.py1
-rw-r--r--libpathod/language/generators.py23
-rw-r--r--libpathod/language/websockets.py3
6 files changed, 44 insertions, 21 deletions
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