Package vobject :: Module vobject
[show private | hide private]
[frames | no frames]

Module vobject.vobject

vobject module for reading vCard and vCalendar files.
Classes
Component A complex property that can contain multiple ContentLines.
ContentLine Holds one content line for formats like vCard and vCalendar.
Stack  
VBase Base class for ContentLine and Component.

Exceptions
NativeError  
ParseError  
ValidateError  
VObjectError  

Function Summary
  backslashEscape(s)
  defaultSerialize(obj, buf, lineLength)
Encode and fold obj and its children, write to buf or return a string.
  dquoteEscape(param)
Return param, or "param" if ',' or ';' or ':' is in param.
  getBehavior(name, id)
Return a matching behavior if it exists, or None.
  getLogicalLines(fp, allowQP)
Iterate through a stream, yielding one logical line at a time.
  newFromBehavior(name, id)
Given a name, return a behaviored ContentLine or Component.
  parseLine(line)
  parseParams(string)
  readComponents(streamOrString, validate, transform)
Generate one Component at a time from a stream.
  readOne(stream, validate, transform)
Return the first component from stream.
  registerBehavior(behavior, name, default, id)
Register the given behavior.
  textLineToContentLine(text, n)

Variable Summary
unicode CR = u'\r'
unicode CRLF = u'\r\n'
bool DEBUG = False
Formatter formatter = <logging.Formatter instance at 0x4023610c>
StreamHandler handler = <logging.StreamHandler instance at 0x402360cc>
unicode LF = u'\n'
SRE_Pattern line_re = ^(([a-zA-Z0-9-]+)\.)?([a-zA-Z0-9-]+)((?:;(?:[a...
Logger logger = <logging.Logger instance at 0x4023608c>
SRE_Pattern logical_lines_re = ((?:[^\r\n]|(?:\r\n|\r|\n|$)[\t ])*(?...
SRE_Pattern param_values_re = "([^"]*)"|([^";:,]+)
SRE_Pattern params_re = ;([a-zA-Z0-9-]+)(?:=((?:(?:"[^"]*"|[^";:,]*)...
dict patterns = {'param_value_grouped': '\n" ( [^"] * )" | ( ...
unicode SPACE = u' '
unicode SPACEORTAB = u' \t'
unicode TAB = u'\t'
str testLines = '\nLine 0 text\n , Line 0 continued.\nLine 1...
str testVCalendar = '\nBEGIN:VCALENDAR\nBEGIN:VEVENT\nSUMMAR...
SRE_Pattern wrap_re = ((?:\r\n|\r|\n|$)[\t ]|(?:\r\n|\r|\n|$))
dict __behaviorRegistry = {'REQUEST-STATUS': [('', <class 'vo...

Function Details

defaultSerialize(obj, buf, lineLength)

Encode and fold obj and its children, write to buf or return a string.

dquoteEscape(param)

Return param, or "param" if ',' or ';' or ':' is in param.

getBehavior(name, id=None)

Return a matching behavior if it exists, or None.

If id is None, return the default for name.

getLogicalLines(fp, allowQP=True)

Iterate through a stream, yielding one logical line at a time.

Because many applications still use vCard 2.1, we have to deal with the quoted-printable encoding for long lines, as well as the vCard 3.0 and vCalendar line folding technique, a whitespace character at the start of the line.

Quoted-printable data will be decoded in the Behavior decoding phase.
>>> import StringIO
>>> f=StringIO.StringIO(testLines)
>>> for n, l in enumerate(getLogicalLines(f)):
...     print "Line %s: %s" % (n, l[0])
...

Line 0: Line 0 text, Line 0 continued.
Line 1: Line 1;encoding=quoted-printable:this is an evil=
 evil=
 format.
Line 2: Line 2 is a new line, it does not start with whitespace.

newFromBehavior(name, id=None)

Given a name, return a behaviored ContentLine or Component.

parseLine(line)

>>> parseLine("BLAH:")
('BLAH', [], '', None)

>>> parseLine("RDATE:VALUE=DATE:19970304,19970504,19970704,19970904")
('RDATE', [], 'VALUE=DATE:19970304,19970504,19970704,19970904', None)

>>> parseLine('DESCRIPTION;ALTREP="http://www.wiz.org":The Fall 98 Wild Wizards Conference - - Las Vegas, NV, USA')
('DESCRIPTION', [['ALTREP', 'http://www.wiz.org']], 'The Fall 98 Wild Wizards Conference - - Las Vegas, NV, USA', None)

>>> parseLine("EMAIL;PREF;INTERNET:john@nowhere.com")
('EMAIL', [['PREF'], ['INTERNET']], 'john@nowhere.com', None)

>>> parseLine('EMAIL;TYPE="blah",hah;INTERNET="DIGI",DERIDOO:john@nowhere.com')
('EMAIL', [['TYPE', 'blah', 'hah'], ['INTERNET', 'DIGI', 'DERIDOO']], 'john@nowhere.com', None)

>>> parseLine('item1.ADR;type=HOME;type=pref:;;Reeperbahn 116;Hamburg;;20359;')
('ADR', [['type', 'HOME'], ['type', 'pref']], ';;Reeperbahn 116;Hamburg;;20359;', 'item1')

>>> parseLine(":")
Traceback (most recent call last):

...

ParseError: 'Failed to parse line: :'

parseParams(string)

>>> parseParams(';ALTREP="http://www.wiz.org"')
[['ALTREP', 'http://www.wiz.org']]

>>> parseParams('')
[]

>>> parseParams(';ALTREP="http://www.wiz.org;;",Blah,Foo;NEXT=Nope;BAR')
[['ALTREP', 'http://www.wiz.org;;', 'Blah', 'Foo'], ['NEXT', 'Nope'], ['BAR']]

readComponents(streamOrString, validate=False, transform=True)

Generate one Component at a time from a stream.
>>> import StringIO
>>> f = StringIO.StringIO(testVCalendar)
>>> cal=readComponents(f).next()
>>> cal
<VCALENDAR| [<VEVENT| [<SUMMARY{u'BLAH': [u'hi!']}Bastille Day Party>]>]>

>>> cal.vevent[0].summary[0]
<SUMMARY{u'BLAH': [u'hi!']}Bastille Day Party>

readOne(stream, validate=False, transform=True)

Return the first component from stream.

registerBehavior(behavior, name=None, default=False, id=None)

Register the given behavior.

If default is True (or if this is the first version registered with this name), the version will be the default if no id is given.

Variable Details

CR

Type:
unicode
Value:
u'\r'                                                                  

CRLF

Type:
unicode
Value:
u'\r\n'                                                                

DEBUG

Type:
bool
Value:
False                                                                  

formatter

Type:
Formatter
Value:
<logging.Formatter instance at 0x4023610c>                             

handler

Type:
StreamHandler
Value:
<logging.StreamHandler instance at 0x402360cc>                         

LF

Type:
unicode
Value:
u'\n'                                                                  

line_re

Type:
SRE_Pattern
Value:
^(([a-zA-Z0-9-]+)\.)?([a-zA-Z0-9-]+)((?:;(?:[a-zA-Z0-9-]+)(?:(?:=(?:"[\
^"]*"|[^";:,]*))?(?:,(?:"[^"]*"|[^";:,]*))*)*)*):(.*)$                 

logger

Type:
Logger
Value:
<logging.Logger instance at 0x4023608c>                                

logical_lines_re

Type:
SRE_Pattern
Value:
((?:[^\r\n]|(?:\r\n|\r|\n|$)[\t ])*(?:\r\n|\r|\n|$))                   

param_values_re

Type:
SRE_Pattern
Value:
"([^"]*)"|([^";:,]+)                                                   

params_re

Type:
SRE_Pattern
Value:
;([a-zA-Z0-9-]+)(?:=((?:(?:"[^"]*"|[^";:,]*))?(?:,(?:"[^"]*"|[^";:,]*)\
)*))?                                                                  

patterns

Type:
dict
Value:
{'line': '\n^ ((?P<group> [a-zA-Z0-9\\-]+)\\.)?(?P<name> [a-zA-Z0-9\\-\
]+) # name group\n  (?P<params> (?: \n; (?: [a-zA-Z0-9\\-]+ )         \
            # parameter name\n(?:\n    (?: = (?:  "[^"] * " | [^";:,] \
*  ) )?   # 0 or more parameter values, multiple \n    (?: , (?:  "[^"\
] * " | [^";:,] *  ) )*   # parameters are comma separated\n)*        \
                 \n )* )               # params group (may be empty)\n\
: (?P<value> .* )$                             # value group\n',
 'lineend': '(?:\\r\\n|\\r|\\n|$)',
...                                                                    

SPACE

Type:
unicode
Value:
u' '                                                                   

SPACEORTAB

Type:
unicode
Value:
u' \t'                                                                 

TAB

Type:
unicode
Value:
u'\t'                                                                  

testLines

Type:
str
Value:
'''
Line 0 text
 , Line 0 continued.
Line 1;encoding=quoted-printable:this is an evil=
 evil=
 format.
Line 2 is a new line, it does not start with whitespace.
'''                                                                    

testVCalendar

Type:
str
Value:
'''
BEGIN:VCALENDAR
BEGIN:VEVENT
SUMMARY;blah=hi!:Bastille Day Party
END:VEVENT
END:VCALENDAR'''                                                       

wrap_re

Type:
SRE_Pattern
Value:
((?:\r\n|\r|\n|$)[\t ]|(?:\r\n|\r|\n|$))                               

__behaviorRegistry

Type:
dict
Value:
{'ACTION': [('', <class 'vobject.icalendar.TextBehavior'>)],
 'ADR': [('', <class 'vobject.vcard.AddressBehavior'>)],
 'CALSCALE': [('', <class 'vobject.icalendar.TextBehavior'>)],
 'CATEGORIES': [('', <class 'vobject.icalendar.MultiTextBehavior'>)],
 'CLASS': [('', <class 'vobject.icalendar.TextBehavior'>)],
 'COMMENT': [('', <class 'vobject.icalendar.TextBehavior'>)],
 'COMPLETED': [('', <class 'vobject.icalendar.UTCDateTimeBehavior'>)],
 'CONTACT': [('', <class 'vobject.icalendar.TextBehavior'>)],
...                                                                    

Generated by Epydoc 2.1 on Fri Dec 14 17:25:16 2007 http://epydoc.sf.net