Code Repositories xandikos / 1a3c125
Refactor handling of properties. Jelmer Vernooń≥ 2 years ago
1 changed file(s) with 49 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
889889 """
890890 for propreq in list(requested):
891891 yield get_property(href, resource, properties, propreq.tag)
892
893
894 def get_property_names(href, resource, properties, requested):
895 """Get a set of property names.
896
897 :param href: Resource Href
898 :param resource: Resource object
899 :param properties: Dictionary of properties
900 :param requested: XML {DAV:}prop element with properties to look up
901 :return: Iterator over PropStatus items
902 """
903 for name, prop in properties.items():
904 if prop.is_set(href, resource):
905 yield PropStatus('200 OK', None, ET.Element(name))
906
907
908 def get_all_properties(href, resource, properties):
909 """Get all properties.
910
911 :param href: Resource Href
912 :param resource: Resource object
913 :param properties: Dictionary of properties
914 :param requested: XML {DAV:}prop element with properties to look up
915 :return: Iterator over PropStatus items
916 """
917 for name in properties:
918 ps = get_property(href, resource, properties, name)
919 if ps.statuscode == '200 OK':
920 yield ps
892921
893922
894923 def ensure_trailing_slash(href):
14191448 'CONTENT_TYPE' not in environ and
14201449 environ.get('CONTENT_LENGTH') == '0'
14211450 ):
1422 requested = ET.Element('{DAV:}allprop')
1451 requested = None
14231452 else:
14241453 et = _readXmlBody(environ, '{DAV:}propfind')
14251454 try:
14271456 except ValueError:
14281457 raise BadRequestError(
14291458 'Received more than one element in propfind.')
1430 if requested.tag == '{DAV:}prop':
1431 ret = []
1432 for href, resource in traverse_resource(
1433 base_resource, base_href, depth):
1459 ret = []
1460 for href, resource in traverse_resource(
1461 base_resource, base_href, depth):
1462 propstat = []
1463 if requested is None or requested.tag == '{DAV:}allprop':
1464 propstat = get_all_properties(
1465 href, resource, app.properties)
1466 elif requested.tag == '{DAV:}prop':
14341467 propstat = get_properties(
14351468 href, resource, app.properties, requested)
1436 ret.append(Status(href, '200 OK', propstat=list(propstat)))
1437 # By my reading of the WebDAV RFC, it should be legal to return
1438 # '200 OK' here if Depth=0, but the RFC is not super clear and
1439 # some clients don't seem to like it .
1440 return ret
1441 elif requested.tag == '{DAV:}allprop':
1442 ret = []
1443 for href, resource in traverse_resource(
1444 base_resource, base_href, depth):
1445 propstat = []
1446 for name in app.properties:
1447 ps = get_property(href, resource, app.properties, name)
1448 if ps.statuscode == '200 OK':
1449 propstat.append(ps)
1450 ret.append(Status(href, '200 OK', propstat=propstat))
1451 return ret
1452 elif requested.tag == '{DAV:}propname':
1453 ret = []
1454 for href, resource in traverse_resource(
1455 base_resource, base_href, depth):
1456 propstat = []
1457 for name, prop in app.properties.items():
1458 if prop.is_set(href, resource):
1459 propstat.append(
1460 PropStatus('200 OK', None, ET.Element(name)))
1461 ret.append(Status(href, '200 OK', propstat=propstat))
1462 return ret
1463 else:
1464 raise BadRequestError('Expected prop/allprop/propname tag, got ' +
1465 requested.tag)
1469 elif requested.tag == '{DAV:}propname':
1470 propstat = get_property_names(
1471 href, resource, app.properties, requested)
1472 else:
1473 raise BadRequestError(
1474 'Expected prop/allprop/propname tag, got ' + requested.tag)
1475 ret.append(Status(href, '200 OK', propstat=list(propstat)))
1476 # By my reading of the WebDAV RFC, it should be legal to return
1477 # '200 OK' here if Depth=0, but the RFC is not super clear and
1478 # some clients don't seem to like it .
1479 return ret
14661480
14671481
14681482 class ProppatchMethod(Method):