diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-04 21:39:27 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-04 21:39:27 +0000 |
commit | fec6336699f34758d3e6cb41b2edf902fedb9035 (patch) | |
tree | 8256c1dbf3ca7c9e58a3dbecf07cf826fb2e0ce2 /src/python/Component.py | |
parent | 7dbffd7e2b0067e834801617c5c486e3177f6709 (diff) | |
download | libical-master.tar.gz |
libical-1.0HEADlibical-1.0master
Diffstat (limited to 'src/python/Component.py')
-rw-r--r-- | src/python/Component.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/python/Component.py b/src/python/Component.py index 9cdcd0d..8f24f54 100644 --- a/src/python/Component.py +++ b/src/python/Component.py @@ -37,10 +37,25 @@ import string WrapperNULL = None -class Component: +# Swig objects are natively unhashable, so we hash on the pointer val. +class SwigRefHash(dict): + def __getitem__(self, k): + return dict.__getitem__(self, int(k)) + + def __setitem__(self, k, v): + return dict.__setitem__(self, int(k), v) + + def __delitem__(self, k): + dict.__delitem__(self, int(k)) + + def has_key(self, k): + return dict.has_key(self, int(k)) + +class Component(object): def __init__(self,ref=None,kind=None): + self._ref = None if ref != None: self._ref = ref elif kind != None: @@ -54,8 +69,8 @@ class Component: else: raise "Could not construct component of kind" + kind - self.cached_props = {} - self.cached_comps = {} + self.cached_props = SwigRefHash() + self.cached_comps = SwigRefHash() def __del__(self): if self._ref != None and icalcomponent_get_parent(self._ref) != WrapperNULL: @@ -73,7 +88,7 @@ class Component: d = {} d['value'] = icalproperty_get_value_as_string(p) - d['name'] = icalproperty_get_name(p) + d['name'] = icalproperty_get_property_name(p) propkind = icalproperty_string_to_kind(d['name']) kind = icalproperty_kind_to_value_kind(propkind) @@ -81,6 +96,7 @@ class Component: d['ref'] = p + #~ print p, Property(ref=p).name() if not self.cached_props.has_key(p): if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE': @@ -176,7 +192,7 @@ class Component: comps.append(comp) c = icalcomponent_get_next_component(self._ref,kind); - return comps + return ComponentCollection(self, comps) def inner_component(self): @@ -213,6 +229,10 @@ class Component: return icalcomponent_as_ical_string(self._ref) + def name(self): + k = icalcomponent_isa(self._ref) + return icalcomponent_kind_to_string(k) + def ref(self): """ Return the internal reference to the libical icalproperty """ return self._ref @@ -514,7 +534,7 @@ class GenericComponent(Component): for alarm in values: self.add_component(alarm) else: - return ComponentCollection(self, self.components('VALARM')) + return self.components('VALARM') #### # Methods that deal with Properties that can occur multiple times are |