From abe1f09f2c7eebfccfbf86ca0b16ec6d1711627b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 17 May 2015 15:49:16 +1200 Subject: [PATCH] HTTP and websocket requests now have an xN clause to repeat --- libpathod/language/__init__.py | 10 +++++++++- libpathod/language/http.py | 9 +++++++++ libpathod/language/message.py | 3 +++ libpathod/language/websockets.py | 4 ++++ libpathod/templates/docs_lang_requests.html | 7 +++++++ libpathod/templates/docs_lang_websockets.html | 6 ++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libpathod/language/__init__.py b/libpathod/language/__init__.py index 36ec19e22..3b7529f06 100644 --- a/libpathod/language/__init__.py +++ b/libpathod/language/__init__.py @@ -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): diff --git a/libpathod/language/http.py b/libpathod/language/http.py index daee7e54a..543cfee3c 100644 --- a/libpathod/language/http.py +++ b/libpathod/language/http.py @@ -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) diff --git a/libpathod/language/message.py b/libpathod/language/message.py index dbc0cfddf..e3c7ed9e4 100644 --- a/libpathod/language/message.py +++ b/libpathod/language/message.py @@ -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 diff --git a/libpathod/language/websockets.py b/libpathod/language/websockets.py index 12b59bc67..ed5596ceb 100644 --- a/libpathod/language/websockets.py +++ b/libpathod/language/websockets.py @@ -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) diff --git a/libpathod/templates/docs_lang_requests.html b/libpathod/templates/docs_lang_requests.html index 72391587d..fe73f0af0 100644 --- a/libpathod/templates/docs_lang_requests.html +++ b/libpathod/templates/docs_lang_requests.html @@ -103,5 +103,12 @@ + + + xINTEGER + + Repeat this message N times. + + diff --git a/libpathod/templates/docs_lang_websockets.html b/libpathod/templates/docs_lang_websockets.html index 8cd176fc3..3233577f5 100644 --- a/libpathod/templates/docs_lang_websockets.html +++ b/libpathod/templates/docs_lang_websockets.html @@ -105,6 +105,12 @@ + + xINTEGER + + Repeat this message N times. + +