HTTP and websocket requests now have an xN clause to repeat

This commit is contained in:
Aldo Cortesi 2015-05-17 15:49:16 +12:00
parent d80fbc2410
commit abe1f09f2c
6 changed files with 38 additions and 1 deletions

View File

@ -31,7 +31,7 @@ def parse_requests(s):
except UnicodeError:
raise exceptions.ParseException("Spec must be valid ASCII.", 0, 0)
try:
return pp.OneOrMore(
reqs = pp.OneOrMore(
pp.Or(
[
websockets.WebsocketFrame.expr(),
@ -41,6 +41,14 @@ def parse_requests(s):
).parseString(s, parseAll=True)
except pp.ParseException, v:
raise exceptions.ParseException(v.msg, v.line, v.col)
expanded = []
for i in reqs:
if i.times:
for j in range(int(i.times.value)):
expanded.append(i.copy())
else:
expanded.append(i)
return expanded
def serve(msg, fp, settings):

View File

@ -32,6 +32,10 @@ class Body(base.Value):
preamble = "b"
class Times(base.Integer):
preamble = "x"
class Method(base.OptionsOrValue):
options = [
"GET",
@ -284,6 +288,7 @@ class Request(_HTTPMessage):
ShortcutUserAgent,
Raw,
PathodResponse,
Times,
actions.PauseAt,
actions.DisconnectAt,
@ -303,6 +308,10 @@ class Request(_HTTPMessage):
def path(self):
return self.tok(Path)
@property
def times(self):
return self.tok(Times)
@property
def pathodspec(self):
return self.tok(PathodResponse)

View File

@ -22,6 +22,9 @@ class Message(object):
track.add(i.unique_name)
self.tokens = tokens
def copy(self):
return self.__class__(self.tokens[:])
def toks(self, klass):
"""
Fetch all tokens that are instances of klass

View File

@ -144,6 +144,10 @@ class WebsocketFrame(message.Message):
def knone(self):
return self.tok(KeyNone)
@property
def times(self):
return self.tok(Times)
@property
def toklength(self):
return self.tok(Length)

View File

@ -103,5 +103,12 @@
</td>
</tr>
<tr>
<td> x<a href="#valuespec">INTEGER</a> </td>
<td>
Repeat this message N times.
</td>
</tr>
</tbody>
</table>

View File

@ -105,6 +105,12 @@
</td>
</tr>
<tr>
<td> x<a href="#valuespec">INTEGER</a> </td>
<td>
Repeat this message N times.
</td>
</tr>
</tbody>
</table>