def _singular_property(self, name, value_type, value=None, property_obj=None, enumerated_values=None): """Sets or gets the value of a method which exists once per Component. This is a constructor method for properties without a strictly defined object.""" # Depending on the property name, this routine will either # operate on the VCALENDAR container or on the inner VEVENT, # VTODO, or VJOURNAL if name in ['METHOD', 'PRODID', 'CALSCALE', 'VERSION']: comp = self else: comp = self.inner_component() curr_properties = comp.properties(name) # Get the value if value == None: if not curr_properties: return None elif len(curr_properties) == 1: return curr_properties[0] else: raise ValueError, "too many properties of type %s" % propType # Set the value else: # Check if value is in enumerated_values if enumerated_values: value = string.upper(value) if value not in enumerated_values: raise ValueError, "%s is not one of %s" \ % (value, enumerated_values) # Create the new property if property_obj: if not isinstance(value, property_obj): # Create a special property_obj property if property_obj == Time: p = Time(value, name) ## p.value_type(value_type) elif property_obj == Duration: p = Duration(value) else: p = property_obj() ## p.value_type(value_type) p.value(value) else: p = value # value is already a property_obj else: # Create a generic property p = Property(name) ## p.value_type(value_type) p.value(value) if len(curr_properties) == 1: comp.remove_property(curr_properties[0]) elif curr_properties: raise ValueError, "too many properties of type %s" % propType comp.add_property(p)
def _singular_property(self, name, value_type, value=None, property_obj=None, enumerated_values=None): """Sets or gets the value of a method which exists once per Component. This is a constructor method for properties without a strictly defined object.""" # Depending on the property name, this routine will either # operate on the VCALENDAR container or on the inner VEVENT, # VTODO, or VJOURNAL if name in ["METHOD", "PRODID", "CALSCALE", "VERSION"]: comp = self else: comp = self.inner_component() curr_properties = comp.properties(name) # Get the value if value == None: if len(curr_properties) == 0: return None elif len(curr_properties) == 1: return curr_properties[0] else: raise ValueError, "too many properties of type %s" % propType # Set the value else: # Check if value is in enumerated_values if enumerated_values: value = string.upper(value) if value not in enumerated_values: raise ValueError, "%s is not one of %s" % (value, enumerated_values) # Create the new property if property_obj: if not isinstance(value, property_obj): # Create a special property_obj property if property_obj == Time: p = Time(value, name) ## p.value_type(value_type) elif property_obj == Duration: p = Duration(value) else: p = property_obj() ## p.value_type(value_type) p.value(value) else: p = value # value is already a property_obj else: # Create a generic property p = Property(name) ## p.value_type(value_type) p.value(value) if len(curr_properties) == 1: comp.remove_property(curr_properties[0]) elif len(curr_properties) > 1: raise ValueError, "too many properties of type %s" % propType comp.add_property(p)
#!/usr/bin/env python