コード例 #1
0
    def test_vcalendar_no_effect(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        no_effect = CalendarData(CalendarComponent(name="VCALENDAR"))
        for item in (
                data,
                Component.fromString(data),
        ):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)),
                             data)

        no_effect = CalendarData(
            CalendarComponent(AllComponents(),
                              AllProperties(),
                              name="VCALENDAR"))
        for item in (
                data,
                Component.fromString(data),
        ):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)),
                             data)
コード例 #2
0
    def test_vevent_no_comp(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Test
TRIGGER;RELATED=START:-PT10M
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData(
            CalendarComponent(CalendarComponent(AllProperties(),
                                                name="VEVENT"),
                              AllProperties(),
                              name="VCALENDAR"))
        for item in (
                data,
                Component.fromString(data),
        ):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)),
                             result)
コード例 #3
0
    def compFilter(self, comp, component):
        """
        Returns a calendar component object containing the data in the given
        component which is specified by this CalendarComponent.
        """
        if comp.type != component.name():
            raise ValueError(
                "%s of type %r can't get data from component of type %r" %
                (comp.sname(), comp.type, component.name()))

        result = Component(comp.type)

        xml_components = comp.components
        xml_properties = comp.properties

        # Empty element means do all properties and components
        if xml_components is None and xml_properties is None:
            xml_components = AllComponents()
            xml_properties = AllProperties()

        if xml_components is not None:
            if xml_components == AllComponents():
                for ical_subcomponent in component.subcomponents():
                    result.addComponent(ical_subcomponent)
            else:
                for xml_subcomponent in xml_components:
                    for ical_subcomponent in component.subcomponents():
                        if ical_subcomponent.name() == xml_subcomponent.type:
                            result.addComponent(
                                self.compFilter(xml_subcomponent,
                                                ical_subcomponent))

        if xml_properties is not None:
            if xml_properties == AllProperties():
                for ical_property in component.properties():
                    result.addProperty(ical_property)
            else:
                for xml_property in xml_properties:
                    name = xml_property.property_name
                    for ical_property in component.properties(name):
                        result.addProperty(ical_property)

        return result
コード例 #4
0
    def filter(self, ical):
        """
        Filter the supplied iCalendar object using the request information.

        @param ical: iCalendar object
        @type ical: L{Component} or C{str}

        @return: L{Component} for the filtered calendar data
        """

        if self.isowner or self.accessRestriction == Component.ACCESS_PUBLIC or not self.accessRestriction:
            # No need to filter for the owner or public event
            return ical

        elif self.accessRestriction == Component.ACCESS_PRIVATE:
            # We should never get here because ACCESS_PRIVATE is protected via an ACL
            raise HTTPError(
                StatusResponse(responsecode.FORBIDDEN, "Access Denied"))

        elif self.accessRestriction == Component.ACCESS_PUBLIC:
            return ical
        elif self.accessRestriction in (Component.ACCESS_CONFIDENTIAL,
                                        Component.ACCESS_RESTRICTED):
            # Create a CALDAV:calendar-data element with the appropriate iCalendar Component/Property
            # filter in place for the access restriction in use

            extra_access = ()
            if self.accessRestriction == Component.ACCESS_RESTRICTED:
                extra_access = (
                    Property(name="SUMMARY"),
                    Property(name="LOCATION"),
                )

            calendardata = CalendarData(
                CalendarComponent(

                    # VCALENDAR properties
                    Property(name="PRODID"),
                    Property(name="VERSION"),
                    Property(name="CALSCALE"),
                    Property(name=Component.ACCESS_PROPERTY),

                    # VEVENT
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="TRANSP"),
                                      Property(name="DTSTART"),
                                      Property(name="DTEND"),
                                      Property(name="DURATION"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VEVENT"}),

                    # VTODO
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="DTSTART"),
                                      Property(name="COMPLETED"),
                                      Property(name="DUE"),
                                      Property(name="DURATION"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VTODO"}),

                    # VJOURNAL
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="TRANSP"),
                                      Property(name="DTSTART"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VJOURNAL"}),

                    # VFREEBUSY
                    CalendarComponent(Property(name="UID"),
                                      Property(name="DTSTAMP"),
                                      Property(name="DTSTART"),
                                      Property(name="DTEND"),
                                      Property(name="DURATION"),
                                      Property(name="FREEBUSY"), *extra_access,
                                      **{"name": "VFREEBUSY"}),

                    # VTIMEZONE
                    CalendarComponent(
                        AllProperties(),
                        AllComponents(),
                        name="VTIMEZONE",
                    ),
                    name="VCALENDAR",
                ), )

            # Now "filter" the resource calendar data through the CALDAV:calendar-data element
            return CalendarDataFilter(calendardata).filter(ical)
        else:
            # Unknown access restriction
            raise HTTPError(
                StatusResponse(responsecode.FORBIDDEN, "Access Denied"))