| |
- __builtin__.object
-
- MailLikeRecord
- MailLikeRecords
class MailLikeRecord(__builtin__.object) |
|
this class holds the data of a single record.
This class contains the parser routines to parse
a single record in the maillike format.
A maillike record consists of field names and
field values. A field name is a alphanumeric
sequence of characters at the start of the line
that is immediately followed by a colon and optional
spaces. Everything that follows including following lines
is regarded as field value until a new line starts with
a field name. A colon may be escaped with "\" in order
to be able to have words followed by colons in the
field value part. Here is an example of such a text:
FIELD1: value 1
FIELD2: value 2
this\: is still the value
of FIELD2
Here is a simple example:
>>> txt='''
... FIELD1: value 1
... FIELD2: value 2
... this\: is still the value
... of FIELD2
... '''
>>> r=MailLikeRecord(txt)
>>> print r
FIELD1: value 1
FIELD2: value 2
this\: is still the value
of FIELD2
<BLANKLINE>
>>> r.keys()
['FIELD1', 'FIELD2']
>>> for f,v in r.items():
... print f,"->",repr(v)
...
FIELD1 -> 'value 1'
FIELD2 -> 'value 2\nthis: is still the value\nof FIELD2'
>>> r["FIELD1"]
'value 1'
>>> r["FIELD2"]
'value 2\nthis: is still the value\nof FIELD2'
>>> r.has_key("FIELD1")
True
>>> r.has_key("FIELD7")
False |
|
Methods defined here:
- __contains__(self, field)
- returns True, if the field is present.
- __getitem__(self, field)
- returns a value for a given field.
- __init__(self, text='', linelist=None)
- initializes the object.
parameters:
text -- an optional string that contains
data in the maillike format.
linelist -- an optional list of strings that is
used to initialize the object
returns:
a MailLikeRecord object
- __repr__(self)
- __str__(self)
- prints the object in the maillike format.
- has_key(self, field)
- returns True, if the field is present.
- items(self)
- returns an iterator over keys and values.
The field order is the same order as in the
parsed text that was used to create the object.
- keys(self)
- returns a list of keys in the order they were found.
- parse_lines(self, lines)
- parse a list of lines in maillike format.
parameters:
lines -- a list of lines to parse
returns:
a tuple consisting of a field-list and
a dictionary mapping field names to field
values.
- parse_text(self, text)
- parse a maillike text.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class MailLikeRecords(__builtin__.object) |
|
this class holds the data of a many records.
This class contains the parser to parse a list of
record in the maillike format. Records are separated
by lines that consist of two percent characters ("%%").
Here is an example:
>>> r='''
... %%
... VERSION: 2009-03-30T12:16:58
... ACTION: added
... FROM: pfeiffer@aragon.acc.bessy.de
... BRANCH: mars17
... TAG: mars17-2009-03-30 6
... LOG: a small change in the main panel
... %%
... VERSION: 2009-03-30T12:20:20
... ACTION: added
... FROM: pfeiffer@aragon.acc.bessy.de
... BRANCH: mars17
... TAG: mars17-2009-03-30 7
... LOG: another small change in the main panel
... '''
>>> rcs= MailLikeRecords(r)
>>> print rcs
VERSION: 2009-03-30T12:16:58
ACTION: added
FROM: pfeiffer@aragon.acc.bessy.de
BRANCH: mars17
TAG: mars17-2009-03-30 6
LOG: a small change in the main panel
%%
VERSION: 2009-03-30T12:20:20
ACTION: added
FROM: pfeiffer@aragon.acc.bessy.de
BRANCH: mars17
TAG: mars17-2009-03-30 7
LOG: another small change in the main panel
<BLANKLINE>
>>> for r in rcs:
... print "-" * 10
... for k,v in r.items():
... print k,"->",repr(v)
...
----------
VERSION -> '2009-03-30T12:16:58'
ACTION -> 'added'
FROM -> 'pfeiffer@aragon.acc.bessy.de'
BRANCH -> 'mars17'
TAG -> 'mars17-2009-03-30 6'
LOG -> 'a small change in the main panel'
----------
VERSION -> '2009-03-30T12:20:20'
ACTION -> 'added'
FROM -> 'pfeiffer@aragon.acc.bessy.de'
BRANCH -> 'mars17'
TAG -> 'mars17-2009-03-30 7'
LOG -> 'another small change in the main panel' |
|
Methods defined here:
- __get_item__(self, index)
- returns an item at a given index.
- __init__(self, text='')
- initializes the object.
parameters:
text -- the text to parse
returns:
the MailLikeRecords object
- __iter__(self)
- returns the list of MailLikeRecord records.
- __len__(self)
- returns the number of items.
- __repr__(self)
- __str__(self)
- print contents in maillike format.
- append(self, record)
- append a single record to the record-list.
- parse_text(self, text)
- parse a maillike text.
parameters:
parameters:
text -- the text to parse
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |