Logo Search packages:      
Sourcecode: calendarserver version File versions  Download package

def twistedcaldav::ical::Component::validateComponentsForCalDAV (   self,
  method 
)

@param method:     True if METHOD property is allowed, False otherwise.
@raise ValueError: if the given calendar component is not valid for
    use as a X{CalDAV} resource.

Definition at line 832 of file ical.py.

00832                                                  :
        """
        @param method:     True if METHOD property is allowed, False otherwise.
        @raise ValueError: if the given calendar component is not valid for
            use as a X{CalDAV} resource.
        """
        #
        # Must not contain more than one type of iCalendar component, except for
        # the required timezone components, and component UIDs must match
        #
        ctype         = None
        component_id  = None
        timezone_refs = set()
        timezones     = set()
        
        for subcomponent in self.subcomponents():
            # Disallowed in CalDAV-Access-08, section 4.1
            if not method and subcomponent.hasProperty("METHOD"):
                raise ValueError("METHOD property is not allowed in CalDAV iCalendar data")
        
            if subcomponent.name() == "VTIMEZONE":
                timezones.add(subcomponent.propertyValue("TZID"))
            else:
                if ctype is None:
                    ctype = subcomponent.name()
                else:
                    if ctype != subcomponent.name():
                        raise ValueError("Calendar resources may not contain more than one type of calendar " +
                                         "component (%s and %s found)" % (ctype, subcomponent.name()))
        
                if ctype not in allowedComponents:
                    raise ValueError("Component type: %s not allowed" % (ctype,))
                    
                uid = subcomponent.propertyValue("UID")
                if uid is None:
                    raise ValueError("All components must have UIDs")
                    
                if component_id is None:
                    component_id = uid
                else:
                    if component_id != uid:
                        raise ValueError("Calendar resources may not contain components with different UIDs " +
                                         "(%s and %s found)" % (component_id, subcomponent.propertyValue("UID")))
                    elif subcomponent.propertyValue("Recurrence-ID") is None:
                        raise ValueError("Calendar resources may not contain components with the same UIDs and no Recurrence-IDs" +
                                         "(%s and %s found)" % (component_id, subcomponent.propertyValue("UID")))
        
                timezone_refs.update(subcomponent.timezoneIDs())
        
        #
        # Make sure required timezone components are present
        #
        for timezone_ref in timezone_refs:
            if timezone_ref not in timezones:
                raise ValueError("Timezone ID %s is referenced but not defined" % (timezone_ref,))
        
        #
        # FIXME:
        #   This test is not part of the spec; it appears to be legal (but
        #   goofy?) to have extra timezone components.
        #
        for timezone in timezones:
            if timezone not in timezone_refs:
                #raise ValueError(
                log.msg(
                    "Timezone %s is not referenced by any non-timezone component" % (timezone,)
                )

    def transformAllFromNative(self):


Generated by  Doxygen 1.6.0   Back to index