Class RecordParser
source code
object --+
|
RecordParser
A helper class which allows you to easily parse protocols which are
delimited by a sequence of bytes, or fixed size records.
Instances of this class take as input Buffer instances containing raw
bytes, and output records. For example, if I had a simple ASCII text
protocol delimited by '\n' and the input was the following:
buffer1:HELLO\nHOW ARE Y buffer2:OU?\nI AM buffer3: DOING OK
buffer4:\n
Then the output would be:
buffer1:HELLO buffer2:HOW ARE YOU? buffer3:I AM DOING OK
Instances of this class can be changed between delimited mode and
fixed size record mode on the fly as individual records are read, this
allows you to parse protocols where, for example, the first 5 records
might all be fixed size (of potentially different sizes), followed by
some delimited records, followed by more fixed size records.
Instances of this class can't currently be used for protocols where
the text is encoded with something other than a 1-1 byte-char mapping.
TODO extend this class to cope with arbitrary character encodings.
|
|
|
|
|
input(self,
data)
This method is called to provide the parser with data. |
source code
|
|
|
|
|
|
|
new_delimited(delim,
handler)
Create a new RecordParser instance, initially in delimited mode, and
where the delimiter can be represented by a delimiter string endcoded
in latin-1 . |
source code
|
|
|
new_fixed(size,
handler)
Create a new RecordParser instance, initially in fixed size mode. |
source code
|
|
- Overrides:
object.__init__
- (inherited documentation)
|
This method is called to provide the parser with data.
- Parameters:
data - Input buffer to the parser.
|
new_delimited(delim,
handler)
Static Method
| source code
|
Create a new RecordParser instance, initially in delimited mode, and
where the delimiter can be represented by a delimiter string endcoded in
latin-1 . Don't use this if your String contains other than latin-1
characters.
Keyword arguments:
- Parameters:
delim - The delimiter string.
handler - the output handler
- Returns:
- a new RecordParser
|
Create a new RecordParser instance, initially in fixed size mode.
Keyword arguments:
- Parameters:
size - the initial record size.
handler - the output handler
- Returns:
- a new RecordParser
|
Flip the parser into delimited mode. This method can be called
multiple times with different values of delim while data is being
parsed.
Keyword arguments:
- Parameters:
delim - the delimiter string.
|
Flip the parser into fixed size mode. This method can be called
multiple times with different values of size while data is being
parsed.
Keyword arguments:
- Parameters:
|