Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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])
base_href, resource, depth):
# TODO(jelmer): Verify that depth == "0"
# TODO(jelmer): Verify that resource is an the right resource type
requested = None
hrefs = []
for el in body:
if el.tag in ('{DAV:}prop', '{DAV:}allprop', '{DAV:}propname'):
requested = el
elif el.tag == '{DAV:}href':
hrefs.append(webdav.read_href_element(el))
else:
raise webdav.BadRequestError(
'Unknown tag %s in report %s' % (el.tag, self.name))
for (href, resource) in resources_by_hrefs(hrefs):
if resource is None:
yield webdav.Status(href, '404 Not Found', propstat=[])
else:
propstat = 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])
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
elif el.tag == '{DAV:}limit':
limit = el.text
elif el.tag == '{DAV:}prop':
requested = list(el)
else:
raise webdav.BadRequestError('unknown tag %s' % el.tag)
# TODO(jelmer): Implement sync_level infinite
if sync_level not in ("1", ):
raise webdav.BadRequestError(
"sync level %r unsupported" % sync_level)
new_token = resource.get_sync_token()
try:
diff_iter = resource.iter_differences_since(old_token, new_token)
except NotImplementedError:
yield webdav.Status(
href, '403 Forbidden',
error=ET.Element('{DAV:}sync-traversal-supported'))
return
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')
diff_iter = itertools.islice(diff_iter, nresults)
async for href, resource in traverse_resource(
base_resource, base_href, depth):
propstat = []
if requested is None or requested.tag == '{DAV:}allprop':
propstat = get_all_properties(
href, resource, app.properties, environ)
elif requested.tag == '{DAV:}prop':
propstat = get_properties(
href, resource, app.properties, environ, requested)
elif requested.tag == '{DAV:}propname':
propstat = get_property_names(
href, resource, app.properties, environ, requested)
else:
raise BadRequestError(
'Expected prop/allprop/propname tag, got ' + requested.tag)
yield Status(href, '200 OK', propstat=[s async for s in propstat])
# By my reading of the WebDAV RFC, it should be legal to return
def _send_dav_responses(responses, out_encoding):
if isinstance(responses, Status):
try:
(body, body_type) = responses.get_single_body(
out_encoding)
except NeedsMultiStatus:
responses = [responses]
else:
return Response(status=responses.status, headers={
'Content-Type': body_type,
'Content-Length': str(sum(map(len, body)))},
body=body)
ret = ET.Element('{DAV:}multistatus')
for response in responses:
ret.append(response.aselement())
return _send_xml_response('207 Multi-Status', ret, out_encoding)
'Tag %s without valid href', prop_child.tag)
continue
child_resource = dict(child_resources).get(child_href)
if child_resource is None:
# FIXME: What to do if the referenced href is invalid?
# For now, let's just keep the unresolved href around
new_prop.append(prop_child)
else:
async for response in self._populate(
prop, resources_by_hrefs, properties,
child_href, child_resource, environ):
new_prop.append(response.aselement())
propstat = PropStatus(propstat.statuscode,
propstat.responsedescription, prop=new_prop)
ret.append(propstat)
yield Status(href, '200 OK', propstat=ret)
webdav.ensure_trailing_slash(href), name)
if new_resource is None:
yield webdav.Status(subhref, status='404 Not Found')
else:
propstat = []
for prop in requested:
if old_resource is not None:
old_propstat = webdav.get_property_from_element(
href, old_resource, properties, environ, prop)
else:
old_propstat = None
new_propstat = webdav.get_property_from_element(
href, new_resource, properties, environ, prop)
if old_propstat != new_propstat:
propstat.append(new_propstat)
yield webdav.Status(subhref, propstat=propstat)
yield SyncToken(new_token)