Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
icalendar.parser.Parameters Class Reference
Inheritance diagram for icalendar.parser.Parameters:
Inheritance graph
[legend]
Collaboration diagram for icalendar.parser.Parameters:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def params
def __repr__
 Later, when I get more time...
def __str__
def from_string
def __getitem__
def __setitem__
def __delitem__
def __contains__
def get
def setdefault
def pop
def popitem
def has_key
def update
def copy
def clear

Static Public Attributes

tuple from_string = staticmethod(from_string)

Detailed Description

Parser and generator of Property parameter strings. It knows nothing of
datatypes. It's main concern is textual structure.


Simple parameter:value pair
>>> p = Parameters(parameter1='Value1')
>>> str(p)
'PARAMETER1=Value1'


keys are converted to upper
>>> p.keys()
['PARAMETER1']


Parameters are case insensitive
>>> p['parameter1']
'Value1'
>>> p['PARAMETER1']
'Value1'


Parameter with list of values must be seperated by comma
>>> p = Parameters({'parameter1':['Value1', 'Value2']})
>>> str(p)
'PARAMETER1=Value1,Value2'


Multiple parameters must be seperated by a semicolon
>>> p = Parameters({'RSVP':'TRUE', 'ROLE':'REQ-PARTICIPANT'})
>>> str(p)
'ROLE=REQ-PARTICIPANT;RSVP=TRUE'


Parameter values containing ',;:' must be double quoted
>>> p = Parameters({'ALTREP':'http://www.wiz.org'})
>>> str(p)
'ALTREP="http://www.wiz.org"'


list items must be quoted seperately
>>> p = Parameters({'MEMBER':['MAILTO:projectA@host.com', 'MAILTO:projectB@host.com', ]})
>>> str(p)
'MEMBER="MAILTO:projectA@host.com","MAILTO:projectB@host.com"'

Now the whole sheebang
>>> p = Parameters({'parameter1':'Value1', 'parameter2':['Value2', 'Value3'],\
                      'ALTREP':['http://www.wiz.org', 'value4']})
>>> str(p)
'ALTREP="http://www.wiz.org",value4;PARAMETER1=Value1;PARAMETER2=Value2,Value3'

We can also parse parameter strings
>>> Parameters.from_string('PARAMETER1=Value 1;param2=Value 2')
Parameters({'PARAMETER1': 'Value 1', 'PARAM2': 'Value 2'})

Including empty strings
>>> Parameters.from_string('param=')
Parameters({'PARAM': ''})

We can also parse parameter strings
>>> Parameters.from_string('MEMBER="MAILTO:projectA@host.com","MAILTO:projectB@host.com"')
Parameters({'MEMBER': ['MAILTO:projectA@host.com', 'MAILTO:projectB@host.com']})

We can also parse parameter strings
>>> Parameters.from_string('ALTREP="http://www.wiz.org",value4;PARAMETER1=Value1;PARAMETER2=Value2,Value3')
Parameters({'PARAMETER1': 'Value1', 'ALTREP': ['http://www.wiz.org', 'value4'], 'PARAMETER2': ['Value2', 'Value3']})

Definition at line 97 of file parser.py.


Member Function Documentation

def icalendar.caselessdict.CaselessDict.__contains__ (   self,
  item 
) [inherited]

Definition at line 61 of file caselessdict.py.

00061 
00062     def __contains__(self, item):
00063         return dict.__contains__(self, item.upper())

def icalendar.caselessdict.CaselessDict.__delitem__ (   self,
  key 
) [inherited]

Definition at line 58 of file caselessdict.py.

00058 
00059     def __delitem__(self, key):
00060         dict.__delitem__(self, key.upper())

def icalendar.caselessdict.CaselessDict.__getitem__ (   self,
  key 
) [inherited]

Definition at line 52 of file caselessdict.py.

00052 
00053     def __getitem__(self, key):
00054         return dict.__getitem__(self, key.upper())

Here is the caller graph for this function:

Later, when I get more time...

need to finish this off now. The last majot thing missing. def _encode(self, name, value, cond=1):

internal, for conditional convertion of values.

if cond: klass = types_factory.for_property(name) return klass(value) return value

def add(self, name, value, encode=0): "Add a parameter value and optionally encode it." if encode: value = self._encode(name, value, encode) self[name] = value

def decoded(self, name): "returns a decoded value, or list of same"

Reimplemented from icalendar.caselessdict.CaselessDict.

Definition at line 192 of file parser.py.

00192 
00193     def __repr__(self):
00194         return 'Parameters(' + dict.__repr__(self) + ')'
00195 

def icalendar.caselessdict.CaselessDict.__setitem__ (   self,
  key,
  value 
) [inherited]

Definition at line 55 of file caselessdict.py.

00055 
00056     def __setitem__(self, key, value):
00057         dict.__setitem__(self, key.upper(), value)

Here is the caller graph for this function:

Definition at line 196 of file parser.py.

00196 
00197     def __str__(self):
00198         result = []
00199         items = self.items()
00200         items.sort() # To make doctests work
00201         for key, value in items:
00202             value = paramVal(value)
00203             result.append('%s=%s' % (key.upper(), value))
00204         return ';'.join(result)
00205 

Here is the call graph for this function:

def icalendar.caselessdict.CaselessDict.clear (   self) [inherited]

Definition at line 89 of file caselessdict.py.

00089 
00090     def clear(self):
00091         dict.clear(self)

Here is the caller graph for this function:

def icalendar.caselessdict.CaselessDict.copy (   self) [inherited]

Definition at line 86 of file caselessdict.py.

00086 
00087     def copy(self):
00088         return CaselessDict(dict.copy(self))

def icalendar.parser.Parameters.from_string (   st,
  strict = False 
)

Definition at line 206 of file parser.py.

00206 
00207     def from_string(st, strict=False):
00208         "Parses the parameter format from ical text format"
00209         try:
00210             # parse into strings
00211             result = Parameters()
00212             for param in q_split(st, ';'):
00213                 key, val =  q_split(param, '=')
00214                 validate_token(key)
00215                 param_values = [v for v in q_split(val, ',')]
00216                 # Property parameter values that are not in quoted
00217                 # strings are case insensitive.
00218                 vals = []
00219                 for v in param_values:
00220                     if v.startswith('"') and v.endswith('"'):
00221                         v = v.strip('"')
00222                         validate_param_value(v, quoted=True)
00223                         vals.append(v)
00224                     else:
00225                         validate_param_value(v, quoted=False)
00226                         if strict:
00227                             vals.append(v.upper())
00228                         else:
00229                             vals.append(v)
00230                 if not vals:
00231                     result[key] = val
00232                 else:
00233                     if len(vals) == 1:
00234                         result[key] = vals[0]
00235                     else:
00236                         result[key] = vals
00237             return result
00238         except:
            raise ValueError, 'Not a valid parameter string'

Here is the call graph for this function:

def icalendar.caselessdict.CaselessDict.get (   self,
  key,
  default = None 
) [inherited]

Definition at line 64 of file caselessdict.py.

00064 
00065     def get(self, key, default=None):
00066         return dict.get(self, key.upper(), default)

Here is the caller graph for this function:

def icalendar.caselessdict.CaselessDict.has_key (   self,
  key 
) [inherited]

Definition at line 76 of file caselessdict.py.

00076 
00077     def has_key(self, key):
00078         return dict.has_key(self, key.upper())

Here is the caller graph for this function:

in rfc2445 keys are called parameters, so this is to be consitent with
the naming conventions

Definition at line 168 of file parser.py.

00168 
00169     def params(self):
00170         """
00171         in rfc2445 keys are called parameters, so this is to be consitent with
00172         the naming conventions
00173         """
00174         return self.keys()

Here is the call graph for this function:

def icalendar.caselessdict.CaselessDict.pop (   self,
  key,
  default = None 
) [inherited]

Definition at line 70 of file caselessdict.py.

00070 
00071     def pop(self, key, default=None):
00072         return dict.pop(self, key.upper(), default)

Here is the caller graph for this function:

def icalendar.caselessdict.CaselessDict.popitem (   self) [inherited]

Definition at line 73 of file caselessdict.py.

00073 
00074     def popitem(self):
00075         return dict.popitem(self, key.upper())

def icalendar.caselessdict.CaselessDict.setdefault (   self,
  key,
  value = None 
) [inherited]

Definition at line 67 of file caselessdict.py.

00067 
00068     def setdefault(self, key, value=None):
00069         return dict.setdefault(self, key.upper(), value)

def icalendar.caselessdict.CaselessDict.update (   self,
  indict 
) [inherited]
Multiple keys where key1.upper() == key2.upper() will be lost.

Definition at line 79 of file caselessdict.py.

00079 
00080     def update(self, indict):
00081         """
00082         Multiple keys where key1.upper() == key2.upper() will be lost.
00083         """
00084         for entry in indict:
00085             self[entry] = indict[entry]

Here is the caller graph for this function:


Member Data Documentation

tuple icalendar.parser.Parameters.from_string = staticmethod(from_string) [static]

Definition at line 239 of file parser.py.


The documentation for this class was generated from the following file: