From 091d90011b285ad66fcc1a252389ed386fb72480 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 23 Jul 2012 17:19:25 +1200 Subject: [PATCH] Unify offset specifications, and document them. --- libpathod/rparse.py | 29 +-- libpathod/templates/docs_lang.html | 333 ++++++++++++++++------------- 2 files changed, 197 insertions(+), 165 deletions(-) diff --git a/libpathod/rparse.py b/libpathod/rparse.py index f81bb1ed4..bdce0dd79 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -96,12 +96,8 @@ DATATYPES = dict( ascii_uppercase = string.ascii_uppercase, digits = string.digits, hexdigits = string.hexdigits, - letters = string.letters, - lowercase = string.lowercase, octdigits = string.octdigits, - printable = string.printable, punctuation = string.punctuation, - uppercase = string.uppercase, whitespace = string.whitespace, ascii = string.printable, bytes = "".join(chr(i) for i in range(256)) @@ -288,6 +284,15 @@ NakedValue = pp.MatchFirst( ) +Offset = pp.MatchFirst( + [ + v_integer, + pp.Literal("r"), + pp.Literal("a") + ] + ) + + class ShortcutContentType: def __init__(self, value): self.value = value @@ -402,13 +407,7 @@ class PauseAt: ] ) e += pp.Literal(",").suppress() - e += pp.MatchFirst( - [ - v_integer, - pp.Literal("r"), - pp.Literal("a"), - ] - ) + e += Offset return e.setParseAction(lambda x: klass(*x)) def accept(self, settings, r): @@ -441,13 +440,7 @@ class InjectAt: @classmethod def expr(klass): e = pp.Literal("i").suppress() - e = e + pp.MatchFirst( - [ - v_integer, - pp.Literal("r"), - pp.Literal("a") - ] - ) + e += Offset e += pp.Literal(",").suppress() e += Value return e.setParseAction(lambda x: klass(*x)) diff --git a/libpathod/templates/docs_lang.html b/libpathod/templates/docs_lang.html index 66b2ca306..6f5f4748d 100644 --- a/libpathod/templates/docs_lang.html +++ b/libpathod/templates/docs_lang.html @@ -9,6 +9,7 @@ +
@@ -17,204 +18,242 @@
code[MESSAGE]:[colon-separated list of features]

- - - - - - - + + + + +
- hKEY=VALUE + hVALUE=VALUE - Set a header. Both KEY and VALUE are full Value Specifiers. + Set a header.
- bVALUE + bVALUE - Set the body. VALUE is a Value - Specifier. When the body is set, pathod will + Set the body. When the body is set, pathod will automatically set the appropriate Content-Length header.
- cVALUE + cVALUE - A shortcut for setting the Content-Type header. Equivalent to: - -
h"Content-Type"=VALUE
- + A shortcut for setting the Content-Type header. Equivalent to + h"Content-Type"=VALUE
- iOFFSET,VALUE + iOFFSET,VALUE - Inject the specified value at the offset. OFFSET can be an - integer, or "r" to generate a random offset or "a" for an - offset just after all data has been sent. + Inject the specified value at the offset.
- lVALUE + lVALUE - A shortcut for setting the Location header. Equivalent to: - -
h"Location"=VALUE
- -
- dOFFSET - - Disconnect after OFFSET bytes. The offset can also be "r", in which case pathod - will disconnect at a random point in the response. + A shortcut for setting the Location header. Equivalent to + h"Location"=VALUE
- pSECONDS,OFFSET + dOFFSET - Pause for SECONDS seconds after OFFSET bytes. SECONDS can also be "f" to pause - forever. OFFSET can also be "r" to generate a random offset, or "a" for an - offset just after all data has been sent. + Disconnect after OFFSET bytes. +
+ pSECONDS,OFFSET + + Pause for SECONDS seconds after OFFSET bytes. SECONDS can + be an integer or "f" to pause forever.
+
- +
+ +
- +
+ -
+./path/to/spec
- - - - - -

VALUEs

- -

Literals

- -

Literal values are specified as a quoted strings:

- -
"foo"
- -

Either single or double quotes are accepted, and quotes can be escaped with - backslashes within the string:

- -
'fo\'o'
- -

Literal values can contain Python-style backslash escape sequences:

- -
'foo\r\nbar'
- - -

Files

- -

You can load a value from a specified file path. To do so, you have to specify - a _staticdir_ option to pathod on the command-line, like so:

- -
pathod -d ~/myassets
- -

All paths are relative paths under this directory. File loads are indicated by - starting the value specifier with the left angle bracket: - -

<my/path

- -

The path value can also be a quoted string, with the same syntax as literals:

- -
<"my/path"
- - -

Generated values

- -

An @-symbol lead-in specifies that generated data should be used. There are two - components to a generator specification - a size, and a data type. By default - pathod assumes a data type of "bytes".

- -

Here's a value specifier for generating 100 bytes: - -

@100

- -

You can use standard suffixes to indicate larger values. Here, for instance, is - a specifier for generating 100 megabytes:

- -
@100m
- -

Data is generated and served efficiently - if you really want to send a - terabyte of data to a client, pathod can do it. The supported suffixes are:

- - - - - - - - - - - - - - - - - - - - -
b 1024**0 (bytes)
k 1024**1 (kilobytes)
m 1024**2 (megabytes)
g 1024**3 (gigabytes)
t 1024**4 (terabytes)
- -

Data types are separated from the size specification by a comma. This - specification generates 100mb of ASCII:

- -
@100m,ascii
- -

Supported data types are:

- - - +
+./path/to/spec
+ +
+ + + +

OFFSET

+ +

Offsets are calculated relative to the base message, before any + injections or other transforms are applied. They have 3 flavors:

+ + + + +

VALUE

+ +

Literals

+ +

Literal values are specified as a quoted strings:

+ +
"foo"
+ +

Either single or double quotes are accepted, and quotes can be escaped with + backslashes within the string:

+ +
'fo\'o'
+ +

Literal values can contain Python-style backslash escape sequences:

+ +
'foo\r\nbar'
+ + +

Files

+ +

You can load a value from a specified file path. To do so, you have to specify + a _staticdir_ option to pathod on the command-line, like so:

+ +
pathod -d ~/myassets
+ +

All paths are relative paths under this directory. File loads are indicated by + starting the value specifier with the left angle bracket: + +

<my/path

+ +

The path value can also be a quoted string, with the same syntax as literals:

+ +
<"my/path"
+ + +

Generated values

+ +

An @-symbol lead-in specifies that generated data should be used. There are two + components to a generator specification - a size, and a data type. By default + pathod assumes a data type of "bytes".

+ +

Here's a value specifier for generating 100 bytes: + +

@100

+ +

You can use standard suffixes to indicate larger values. Here, for instance, is + a specifier for generating 100 megabytes:

+ +
@100m
+ +

Data is generated and served efficiently - if you really want to send a + terabyte of data to a client, pathod can do it. The supported suffixes are:

+ + + + + + + + + + + + + + + + + + + + +
b 1024**0 (bytes)
k 1024**1 (kilobytes)
m 1024**2 (megabytes)
g 1024**3 (gigabytes)
t 1024**4 (terabytes)
+ +

Data types are separated from the size specification by a comma. This + specification generates 100mb of ASCII:

+ +
@100m,ascii
+ +

Supported data types are:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
asciiAll ASCII characters
ascii_lettersA-Za-z
ascii_lowercasea-z
ascii_uppercaseA-Z
bytesAll 256 byte values
digits0-9
hexdigits0-f
octdigits0-8
punctuation +
!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~
+
whitespace +
\t\n\x0b\x0c\r and space
+
+
+ {% endblock %}