Back to index

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

List of all members.

Public Member Functions

def from_string
def set
def add
def decoded
def get_inline
 Inline values.
def set_inline
def add_component
 Handling of components.
def walk
def property_items
 Generation.
def __repr__
def content_lines
def as_string
def __str__
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

Public Attributes

 subcomponents

Static Public Attributes

string name = 'VCALENDAR'
tuple required = ('prodid', 'version', )
tuple singletons = ('prodid', 'version', )
tuple multiple = ('calscale', 'method', )
tuple exclusive = ()
tuple inclusive = ()
tuple from_string = staticmethod(from_string)

Detailed Description

This is the base object for an iCalendar file.

Setting up a minimal calendar component looks like this
>>> cal = Calendar()

Som properties are required to be compliant
>>> cal['prodid'] = '-//My calendar product//mxm.dk//'
>>> cal['version'] = '2.0'

We also need at least one subcomponent for a calendar to be compliant
>>> from datetime import datetime
>>> event = Event()
>>> event['summary'] = 'Python meeting about calendaring'
>>> event['uid'] = '42'
>>> event.set('dtstart', datetime(2005,4,4,8,0,0))
>>> cal.add_component(event)
>>> cal.subcomponents[0].as_string()
'BEGIN:VEVENT\\r\\nDTSTART:20050404T080000\\r\\nSUMMARY:Python meeting about calendaring\\r\\nUID:42\\r\\nEND:VEVENT\\r\\n'

Write to disc
>>> import tempfile, os
>>> directory = tempfile.mkdtemp()
>>> open(os.path.join(directory, 'test.ics'), 'wb').write(cal.as_string())

Definition at line 497 of file cal.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:

def icalendar.cal.Component.__repr__ (   self) [inherited]

Reimplemented from icalendar.caselessdict.CaselessDict.

Definition at line 378 of file cal.py.

00378 
00379     def __repr__(self):
00380         return '%s(' % self.name + dict.__repr__(self) + ')'
00381 
00382 #    def content_line(self, name):
00383 #        "Returns property as content line"
00384 #        value = self[name]
00385 #        params = getattr(value, 'params', Parameters())
00386 #        return Contentline.from_parts((name, params, value))

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:

def icalendar.cal.Component.__str__ (   self) [inherited]

Definition at line 401 of file cal.py.

00401 
00402     def __str__(self):
00403         "Returns rendered iCalendar"
00404         return self.as_string()
00405 
00406 

Here is the call graph for this function:

def icalendar.cal.Component.add (   self,
  name,
  value,
  encode = 1 
) [inherited]

Definition at line 222 of file cal.py.

00222 
00223     def add(self, name, value, encode=1):
00224         "If property exists append, else create and set it"
00225         if name in self:
00226             oldval = self[name]
00227             value = self._encode(name, value, encode)
00228             if type(oldval) == ListType:
00229                 oldval.append(value)
00230             else:
00231                 self.set(name, [oldval, value], encode=0)
00232         else:
00233             self.set(name, value, encode)
00234 

Here is the call graph for this function:

Here is the caller graph for this function:

def icalendar.cal.Component.add_component (   self,
  component 
) [inherited]

Handling of components.

Definition at line 282 of file cal.py.

00282 
00283     def add_component(self, component):
00284         "add a subcomponent to this component"
00285         self.subcomponents.append(component)
00286 

Here is the caller graph for this function:

def icalendar.cal.Component.as_string (   self) [inherited]

Definition at line 397 of file cal.py.

00397 
00398     def as_string(self):
00399         return str(self.content_lines())
00400 

Here is the call graph for this function:

Here is the caller 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.cal.Component.content_lines (   self) [inherited]

Definition at line 387 of file cal.py.

00387 
00388     def content_lines(self):
00389         "Converts the Component and subcomponents into content lines"
00390         contentlines = Contentlines()
00391         for name, values in self.property_items():
00392             params = getattr(values, 'params', Parameters())
00393             contentlines.append(Contentline.from_parts((name, params, values)))
00394         contentlines.append('') # remember the empty string in the end
00395         return contentlines
00396 

Here is the call graph for this function:

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.cal.Component.decoded (   self,
  name,
  default = _marker 
) [inherited]

Definition at line 241 of file cal.py.

00241 
00242     def decoded(self, name, default=_marker):
00243         "Returns decoded value of property"
00244         if name in self:
00245             value = self[name]
00246             if type(value) == ListType:
00247                 return [self._decode(name, v) for v in value]
00248             return self._decode(name, value)
00249         else:
00250             if default is _marker:
00251                 raise KeyError, name
00252             else:
00253                 return default
00254 

Here is the call graph for this function:

def icalendar.cal.Component.from_string (   st,
  multiple = False 
) [inherited]
Populates the component recursively from a string

Definition at line 333 of file cal.py.

00333 
00334     def from_string(st, multiple=False):
00335         """
00336         Populates the component recursively from a string
00337         """
00338         stack = [] # a stack of components
00339         comps = []
00340         for line in Contentlines.from_string(st): # raw parsing
00341             if not line:
00342                 continue
00343             name, params, vals = line.parts()
00344             uname = name.upper()
00345             # check for start of component
00346             if uname == 'BEGIN':
00347                 # try and create one of the components defined in the spec,
00348                 # otherwise get a general Components for robustness.
00349                 component_name = vals.upper()
00350                 component_class = component_factory.get(component_name, Component)
00351                 component = component_class()
00352                 if not getattr(component, 'name', ''): # for undefined components
00353                     component.name = component_name
00354                 stack.append(component)
00355             # check for end of event
00356             elif uname == 'END':
00357                 # we are done adding properties to this component
00358                 # so pop it from the stack and add it to the new top.
00359                 component = stack.pop()
00360                 if not stack: # we are at the end
00361                     comps.append(component)
00362                 else:
00363                     stack[-1].add_component(component)
00364             # we are adding properties to the current top of the stack
00365             else:
00366                 factory = types_factory.for_property(name)
00367                 vals = factory(factory.from_ical(vals))
00368                 vals.params = params
00369                 stack[-1].add(name, vals, encode=0)
00370         if multiple:
00371             return comps
00372         if not len(comps) == 1:
00373             raise ValueError('Found multiple components where '
00374                              'only one is allowed')
        return comps[0]

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.cal.Component.get_inline (   self,
  name,
  decode = 1 
) [inherited]

Inline values.

A few properties have multiple values inlined in in one property line. These methods are used for splitting and joining these.

Returns a list of values (split on comma).

Definition at line 259 of file cal.py.

00259 
00260     def get_inline(self, name, decode=1):
00261         """
00262         Returns a list of values (split on comma).
00263         """
00264         vals = [v.strip('" ') for v in q_split(self[name])]
00265         if decode:
00266             return [self._decode(name, val) for val in vals]
00267         return vals
00268 

Here is the call 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:

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.cal.Component.property_items (   self) [inherited]

Generation.

Returns properties in this component and subcomponents as:
[(name, value), ...]

Definition at line 309 of file cal.py.

00309 
00310     def property_items(self):
00311         """
00312         Returns properties in this component and subcomponents as:
00313         [(name, value), ...]
00314         """
00315         vText = types_factory['text']
00316         properties = [('BEGIN', vText(self.name).ical())]
00317         property_names = self.keys()
00318         property_names.sort()
00319         for name in property_names:
00320             values = self[name]
00321             if type(values) == ListType:
00322                 # normally one property is one line
00323                 for value in values:
00324                     properties.append((name, value))
00325             else:
00326                 properties.append((name, values))
00327         # recursion is fun!
00328         for subcomponent in self.subcomponents:
00329             properties += subcomponent.property_items()
00330         properties.append(('END', vText(self.name).ical()))
00331         return properties
00332 

Here is the call graph for this function:

Here is the caller graph for this function:

def icalendar.cal.Component.set (   self,
  name,
  value,
  encode = 1 
) [inherited]

Definition at line 215 of file cal.py.

00215 
00216     def set(self, name, value, encode=1):
00217         if type(value) == ListType:
00218             self[name] = [self._encode(name, v, encode) for v in value]
00219         else:
00220             self[name] = self._encode(name, value, encode)
00221 

Here is the call graph for this function:

Here is the caller graph for this function:

def icalendar.cal.Component.set_inline (   self,
  name,
  values,
  encode = 1 
) [inherited]
Converts a list of values into comma seperated string and sets value to
that.

Definition at line 269 of file cal.py.

00269 
00270     def set_inline(self, name, values, encode=1):
00271         """
00272         Converts a list of values into comma seperated string and sets value to
00273         that.
00274         """
00275         if encode:
00276             values = [self._encode(name, value, 1) for value in values]
00277         self[name] = types_factory['inline'](q_join(values))
00278 

Here is the call graph for this function:

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:

def icalendar.cal.Component.walk (   self,
  name = None 
) [inherited]
Recursively traverses component and subcomponents. Returns sequence of
same. If name is passed, only components with name will be returned.

Definition at line 297 of file cal.py.

00297 
00298     def walk(self, name=None):
00299         """
00300         Recursively traverses component and subcomponents. Returns sequence of
00301         same. If name is passed, only components with name will be returned.
00302         """
00303         if not name is None:
00304             name = name.upper()
00305         return self._walk(name)

Here is the call graph for this function:


Member Data Documentation

tuple icalendar.cal.Component.exclusive = () [static, inherited]

Reimplemented in icalendar.cal.Todo, and icalendar.cal.Event.

Definition at line 178 of file cal.py.

tuple icalendar.cal.Component.from_string = staticmethod(from_string) [static, inherited]

Definition at line 375 of file cal.py.

tuple icalendar.cal.Component.inclusive = () [static, inherited]

Reimplemented in icalendar.cal.Alarm.

Definition at line 179 of file cal.py.

tuple icalendar.cal.Calendar.multiple = ('calscale', 'method', ) [static]

Reimplemented from icalendar.cal.Component.

Definition at line 527 of file cal.py.

string icalendar.cal.Calendar.name = 'VCALENDAR' [static]

Reimplemented from icalendar.cal.Component.

Definition at line 524 of file cal.py.

tuple icalendar.cal.Calendar.required = ('prodid', 'version', ) [static]

Reimplemented from icalendar.cal.Component.

Definition at line 525 of file cal.py.

tuple icalendar.cal.Calendar.singletons = ('prodid', 'version', ) [static]

Reimplemented from icalendar.cal.Component.

Definition at line 526 of file cal.py.

Definition at line 185 of file cal.py.


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