Exemple #1
0
    async def report(self, environ, body, resources_by_hrefs,
                     properties, base_href, base_resource, depth):
        requested = None
        for el in body:
            if el.tag == '{urn:ietf:params:xml:ns:caldav}time-range':
                requested = el
            else:
                raise AssertionError("unexpected XML element")
        tz = get_calendar_timezone(base_resource)

        def tzify(dt):
            return as_tz_aware_ts(dt, tz).astimezone(pytz.utc)
        (start, end) = _parse_time_range(requested)
        assert start.tzinfo
        assert end.tzinfo
        ret = ICalendar()
        ret['VERSION'] = '2.0'
        ret['PRODID'] = PRODID
        fb = FreeBusy()
        fb['DTSTAMP'] = vDDDTypes(tzify(datetime.datetime.now()))
        fb['DTSTART'] = vDDDTypes(start)
        fb['DTEND'] = vDDDTypes(end)
        fb['FREEBUSY'] = [item async for item in iter_freebusy(
            webdav.traverse_resource(base_resource, base_href, depth),
            start, end, tzify)]
        ret.add_component(fb)
        return webdav.Response(status='200 OK', body=[ret.to_ical()])
Exemple #2
0
def extract_from_calendar(incal, requested):
    """Extract requested components/properties from calendar.

    :param incal: Calendar to filter
    :param requested: <calendar-data> element with requested
        components/properties
    """
    for tag in requested:
        if tag.tag == ('{%s}comp' % NAMESPACE):
            if incal.name == tag.get('name'):
                c = ICalendar()
                _extract_from_component(incal, c, tag)
                incal = c
        elif tag.tag == ('{%s}expand' % NAMESPACE):
            (start, end) = _parse_time_range(tag)
            incal = expand_calendar_rrule(incal, start, end)
        elif tag.tag == ('{%s}limit-recurrence-set' % NAMESPACE):
            # TODO(jelmer): https://github.com/jelmer/xandikos/issues/103
            raise NotImplementedError(
                'limit-recurrence-set is not yet implemented')
        elif tag.tag == ('{%s}limit-freebusy-set' % NAMESPACE):
            # TODO(jelmer): https://github.com/jelmer/xandikos/issues/104
            raise NotImplementedError(
                'limit-freebusy-set is not yet implemented')
        else:
            raise AssertionError('invalid element %r' % tag)
    return incal
Exemple #3
0
 def extractEqual(self, incal_str, outcal_str):
     incal = ICalendar.from_ical(incal_str)
     expected_outcal = ICalendar.from_ical(outcal_str)
     outcal = ICalendar()
     caldav.extract_from_calendar(incal, outcal, self.requested)
     self.assertEqual(expected_outcal.to_ical().decode(),
                      outcal.to_ical().decode(),
                      ET.tostring(self.requested))
Exemple #4
0
 def extractEqual(self, incal_str, outcal_str):
     incal = ICalendar.from_ical(incal_str)
     expected_outcal = ICalendar.from_ical(outcal_str)
     outcal = ICalendar()
     outcal = caldav.extract_from_calendar(incal, self.requested)
     self.maxDiff = None
     self.assertMultiLineEqual(
         expected_outcal.to_ical().decode(),
         outcal.to_ical().decode(),
         ET.tostring(self.requested),
     )
Exemple #5
0
 def get_value_ext(self, base_href, resource, el, environ, requested):
     if len(requested) == 0:
         serialized_cal = b''.join(resource.get_body())
     else:
         c = ICalendar()
         calendar = calendar_from_resource(resource)
         if calendar is None:
             raise KeyError
         extract_from_calendar(calendar, c, requested)
         serialized_cal = c.to_ical()
     # TODO(jelmer): Don't hardcode encoding
     el.text = serialized_cal.decode('utf-8')