Example #1
0
 def report(self, environ, body, resources_by_hrefs, properties, base_href,
            base_resource, depth):
     # TODO(jelmer): Verify that resource is an addressbook
     requested = None
     filter_el = None
     tztext = None
     for el in body:
         if el.tag in ('{DAV:}prop', '{DAV:}propname', '{DAV:}allprop'):
             requested = el
         elif el.tag == '{urn:ietf:params:xml:ns:caldav}filter':
             filter_el = el
         elif el.tag == '{urn:ietf:params:xml:ns:caldav}timezone':
             tztext = el.text
         else:
             raise webdav.BadRequestError('Unknown tag %s in report %s' %
                                          (el.tag, self.name))
     if tztext is not None:
         tz = get_pytz_from_text(tztext)
     else:
         tz = get_calendar_timezone(base_resource)
     tzify = lambda dt: as_tz_aware_ts(dt, tz)
     for (href,
          resource) in webdav.traverse_resource(base_resource, base_href,
                                                depth):
         if not apply_filter(filter_el, resource, tzify):
             continue
         propstat = davcommon.get_properties_with_data(
             self.data_property, href, resource, properties, environ,
             requested)
         yield webdav.Status(href, '200 OK', propstat=list(propstat))
Example #2
0
    async def report(
        self,
        environ,
        body,
        resources_by_hrefs,
        properties,
        base_href,
        base_resource,
        depth,
    ):
        # TODO(jelmer): Verify that resource is a calendar
        requested = None
        filter_el = None
        tztext = None
        for el in body:
            if el.tag in ("{DAV:}prop", "{DAV:}propname", "{DAV:}allprop"):
                requested = el
            elif el.tag == "{urn:ietf:params:xml:ns:caldav}filter":
                filter_el = el
            elif el.tag == "{urn:ietf:params:xml:ns:caldav}timezone":
                tztext = el.text
            else:
                raise webdav.BadRequestError("Unknown tag %s in report %s" %
                                             (el.tag, self.name))
        if tztext is not None:
            tz = get_pytz_from_text(tztext)
        else:
            tz = get_calendar_timezone(base_resource)

        def filter_fn(cls):
            return parse_filter(filter_el, cls(tz))

        def members(collection):
            return itertools.chain(
                collection.calendar_query(filter_fn),
                collection.subcollections(),
            )

        async for (href,
                   resource) in webdav.traverse_resource(base_resource,
                                                         base_href,
                                                         depth,
                                                         members=members):
            # Ideally traverse_resource would only return the right things.
            if getattr(resource, "content_type", None) == "text/calendar":
                propstat = davcommon.get_properties_with_data(
                    self.data_property,
                    href,
                    resource,
                    properties,
                    environ,
                    requested,
                )
                yield webdav.Status(href,
                                    "200 OK",
                                    propstat=[s async for s in propstat])
Example #3
0
    async def report(
        self,
        environ,
        body,
        resources_by_hrefs,
        properties,
        base_href,
        base_resource,
        depth,
    ):
        requested = None
        filter_el = None
        limit = None
        for el in body:
            if el.tag in ("{DAV:}prop", "{DAV:}allprop", "{DAV:}propname"):
                requested = el
            elif el.tag == ("{%s}filter" % NAMESPACE):
                filter_el = el
            elif el.tag == ("{%s}limit" % NAMESPACE):
                limit = el
            else:
                raise webdav.BadRequestError("Unknown tag %s in report %s" %
                                             (el.tag, self.name))
        if limit is not None:
            try:
                [nresults_el] = list(limit)
            except ValueError:
                raise webdav.BadRequestError(
                    "Invalid number of subelements in limit")
            try:
                nresults = int(nresults_el.text)
            except ValueError:
                raise webdav.BadRequestError("nresults not a number")
        else:
            nresults = None

        i = 0
        async for (href, resource) in webdav.traverse_resource(
                base_resource, base_href, depth):
            if not apply_filter(filter_el, resource):
                continue
            if nresults is not None and i >= nresults:
                break
            propstat = davcommon.get_properties_with_data(
                self.data_property,
                href,
                resource,
                properties,
                environ,
                requested,
            )
            yield webdav.Status(href,
                                "200 OK",
                                propstat=[s async for s in propstat])
            i += 1