Improve variable names
This commit is contained in:
parent
d31eaf79ec
commit
7642d72919
@ -40,18 +40,18 @@ def xml_propfind(base_prefix, path, xml_request, allowed_items, user,
|
|||||||
"""
|
"""
|
||||||
# A client may choose not to submit a request body. An empty PROPFIND
|
# A client may choose not to submit a request body. An empty PROPFIND
|
||||||
# request body MUST be treated as if it were an 'allprop' request.
|
# request body MUST be treated as if it were an 'allprop' request.
|
||||||
top_tag = (xml_request[0] if xml_request is not None else
|
top_element = (xml_request[0] if xml_request is not None else
|
||||||
ET.Element(xmlutils.make_clark("D:allprop")))
|
ET.Element(xmlutils.make_clark("D:allprop")))
|
||||||
|
|
||||||
props = ()
|
props = ()
|
||||||
allprop = False
|
allprop = False
|
||||||
propname = False
|
propname = False
|
||||||
if top_tag.tag == xmlutils.make_clark("D:allprop"):
|
if top_element.tag == xmlutils.make_clark("D:allprop"):
|
||||||
allprop = True
|
allprop = True
|
||||||
elif top_tag.tag == xmlutils.make_clark("D:propname"):
|
elif top_element.tag == xmlutils.make_clark("D:propname"):
|
||||||
propname = True
|
propname = True
|
||||||
elif top_tag.tag == xmlutils.make_clark("D:prop"):
|
elif top_element.tag == xmlutils.make_clark("D:prop"):
|
||||||
props = [prop.tag for prop in top_tag]
|
props = [prop.tag for prop in top_element]
|
||||||
|
|
||||||
if xmlutils.make_clark("D:current-user-principal") in props and not user:
|
if xmlutils.make_clark("D:current-user-principal") in props and not user:
|
||||||
# Ask for authentication
|
# Ask for authentication
|
||||||
@ -152,17 +152,17 @@ def xml_propfind_response(base_prefix, path, item, props, user, encoding,
|
|||||||
else:
|
else:
|
||||||
is404 = True
|
is404 = True
|
||||||
elif tag == xmlutils.make_clark("D:principal-collection-set"):
|
elif tag == xmlutils.make_clark("D:principal-collection-set"):
|
||||||
tag = ET.Element(xmlutils.make_clark("D:href"))
|
child_element = ET.Element(xmlutils.make_clark("D:href"))
|
||||||
tag.text = xmlutils.make_href(base_prefix, "/")
|
child_element.text = xmlutils.make_href(base_prefix, "/")
|
||||||
element.append(tag)
|
element.append(child_element)
|
||||||
elif (tag in (xmlutils.make_clark("C:calendar-user-address-set"),
|
elif (tag in (xmlutils.make_clark("C:calendar-user-address-set"),
|
||||||
xmlutils.make_clark("D:principal-URL"),
|
xmlutils.make_clark("D:principal-URL"),
|
||||||
xmlutils.make_clark("CR:addressbook-home-set"),
|
xmlutils.make_clark("CR:addressbook-home-set"),
|
||||||
xmlutils.make_clark("C:calendar-home-set")) and
|
xmlutils.make_clark("C:calendar-home-set")) and
|
||||||
collection.is_principal and is_collection):
|
collection.is_principal and is_collection):
|
||||||
tag = ET.Element(xmlutils.make_clark("D:href"))
|
child_element = ET.Element(xmlutils.make_clark("D:href"))
|
||||||
tag.text = xmlutils.make_href(base_prefix, path)
|
child_element.text = xmlutils.make_href(base_prefix, path)
|
||||||
element.append(tag)
|
element.append(child_element)
|
||||||
elif tag == xmlutils.make_clark("C:supported-calendar-component-set"):
|
elif tag == xmlutils.make_clark("C:supported-calendar-component-set"):
|
||||||
human_tag = xmlutils.make_human_tag(tag)
|
human_tag = xmlutils.make_human_tag(tag)
|
||||||
if is_collection and is_leaf:
|
if is_collection and is_leaf:
|
||||||
@ -179,9 +179,10 @@ def xml_propfind_response(base_prefix, path, item, props, user, encoding,
|
|||||||
is404 = True
|
is404 = True
|
||||||
elif tag == xmlutils.make_clark("D:current-user-principal"):
|
elif tag == xmlutils.make_clark("D:current-user-principal"):
|
||||||
if user:
|
if user:
|
||||||
tag = ET.Element(xmlutils.make_clark("D:href"))
|
child_element = ET.Element(xmlutils.make_clark("D:href"))
|
||||||
tag.text = xmlutils.make_href(base_prefix, "/%s/" % user)
|
child_element.text = xmlutils.make_href(
|
||||||
element.append(tag)
|
base_prefix, "/%s/" % user)
|
||||||
|
element.append(child_element)
|
||||||
else:
|
else:
|
||||||
element.append(ET.Element(
|
element.append(ET.Element(
|
||||||
xmlutils.make_clark("D:unauthenticated")))
|
xmlutils.make_clark("D:unauthenticated")))
|
||||||
@ -213,9 +214,10 @@ def xml_propfind_response(base_prefix, path, item, props, user, encoding,
|
|||||||
for human_tag in reports:
|
for human_tag in reports:
|
||||||
supported_report = ET.Element(
|
supported_report = ET.Element(
|
||||||
xmlutils.make_clark("D:supported-report"))
|
xmlutils.make_clark("D:supported-report"))
|
||||||
report_tag = ET.Element(xmlutils.make_clark("D:report"))
|
report_element = ET.Element(xmlutils.make_clark("D:report"))
|
||||||
report_tag.append(ET.Element(xmlutils.make_clark(human_tag)))
|
report_element.append(
|
||||||
supported_report.append(report_tag)
|
ET.Element(xmlutils.make_clark(human_tag)))
|
||||||
|
supported_report.append(report_element)
|
||||||
element.append(supported_report)
|
element.append(supported_report)
|
||||||
elif tag == xmlutils.make_clark("D:getcontentlength"):
|
elif tag == xmlutils.make_clark("D:getcontentlength"):
|
||||||
if not is_collection or is_leaf:
|
if not is_collection or is_leaf:
|
||||||
@ -225,10 +227,10 @@ def xml_propfind_response(base_prefix, path, item, props, user, encoding,
|
|||||||
elif tag == xmlutils.make_clark("D:owner"):
|
elif tag == xmlutils.make_clark("D:owner"):
|
||||||
# return empty elment, if no owner available (rfc3744-5.1)
|
# return empty elment, if no owner available (rfc3744-5.1)
|
||||||
if collection.owner:
|
if collection.owner:
|
||||||
tag = ET.Element(xmlutils.make_clark("D:href"))
|
child_element = ET.Element(xmlutils.make_clark("D:href"))
|
||||||
tag.text = xmlutils.make_href(
|
child_element.text = xmlutils.make_href(
|
||||||
base_prefix, "/%s/" % collection.owner)
|
base_prefix, "/%s/" % collection.owner)
|
||||||
element.append(tag)
|
element.append(child_element)
|
||||||
elif is_collection:
|
elif is_collection:
|
||||||
if tag == xmlutils.make_clark("D:getcontenttype"):
|
if tag == xmlutils.make_clark("D:getcontenttype"):
|
||||||
if is_leaf:
|
if is_leaf:
|
||||||
@ -237,18 +239,20 @@ def xml_propfind_response(base_prefix, path, item, props, user, encoding,
|
|||||||
is404 = True
|
is404 = True
|
||||||
elif tag == xmlutils.make_clark("D:resourcetype"):
|
elif tag == xmlutils.make_clark("D:resourcetype"):
|
||||||
if item.is_principal:
|
if item.is_principal:
|
||||||
tag = ET.Element(xmlutils.make_clark("D:principal"))
|
child_element = ET.Element(
|
||||||
element.append(tag)
|
xmlutils.make_clark("D:principal"))
|
||||||
|
element.append(child_element)
|
||||||
if is_leaf:
|
if is_leaf:
|
||||||
if item.get_meta("tag") == "VADDRESSBOOK":
|
if item.get_meta("tag") == "VADDRESSBOOK":
|
||||||
tag = ET.Element(
|
child_element = ET.Element(
|
||||||
xmlutils.make_clark("CR:addressbook"))
|
xmlutils.make_clark("CR:addressbook"))
|
||||||
element.append(tag)
|
element.append(child_element)
|
||||||
elif item.get_meta("tag") == "VCALENDAR":
|
elif item.get_meta("tag") == "VCALENDAR":
|
||||||
tag = ET.Element(xmlutils.make_clark("C:calendar"))
|
child_element = ET.Element(
|
||||||
element.append(tag)
|
xmlutils.make_clark("C:calendar"))
|
||||||
tag = ET.Element(xmlutils.make_clark("D:collection"))
|
element.append(child_element)
|
||||||
element.append(tag)
|
child_element = ET.Element(xmlutils.make_clark("D:collection"))
|
||||||
|
element.append(child_element)
|
||||||
elif tag == xmlutils.make_clark("RADICALE:displayname"):
|
elif tag == xmlutils.make_clark("RADICALE:displayname"):
|
||||||
# Only for internal use by the web interface
|
# Only for internal use by the web interface
|
||||||
displayname = item.get_meta("D:displayname")
|
displayname = item.get_meta("D:displayname")
|
||||||
|
@ -104,8 +104,8 @@ def xml_report(base_prefix, path, xml_request, collection, encoding,
|
|||||||
else:
|
else:
|
||||||
hreferences = (path,)
|
hreferences = (path,)
|
||||||
filters = (
|
filters = (
|
||||||
root.findall("./%s" % xmlutils.make_clark("C:filter")) +
|
root.findall(xmlutils.make_clark("C:filter")) +
|
||||||
root.findall("./%s" % xmlutils.make_clark("CR:filter")))
|
root.findall(xmlutils.make_clark("CR:filter")))
|
||||||
|
|
||||||
def retrieve_items(collection, hreferences, multistatus):
|
def retrieve_items(collection, hreferences, multistatus):
|
||||||
"""Retrieves all items that are referenced in ``hreferences`` from
|
"""Retrieves all items that are referenced in ``hreferences`` from
|
||||||
@ -231,9 +231,9 @@ def xml_item_response(base_prefix, href, found_props=(), not_found_props=(),
|
|||||||
found_item=True):
|
found_item=True):
|
||||||
response = ET.Element(xmlutils.make_clark("D:response"))
|
response = ET.Element(xmlutils.make_clark("D:response"))
|
||||||
|
|
||||||
href_tag = ET.Element(xmlutils.make_clark("D:href"))
|
href_element = ET.Element(xmlutils.make_clark("D:href"))
|
||||||
href_tag.text = xmlutils.make_href(base_prefix, href)
|
href_element.text = xmlutils.make_href(base_prefix, href)
|
||||||
response.append(href_tag)
|
response.append(href_element)
|
||||||
|
|
||||||
if found_item:
|
if found_item:
|
||||||
for code, props in ((200, found_props), (404, not_found_props)):
|
for code, props in ((200, found_props), (404, not_found_props)):
|
||||||
@ -241,10 +241,10 @@ def xml_item_response(base_prefix, href, found_props=(), not_found_props=(),
|
|||||||
propstat = ET.Element(xmlutils.make_clark("D:propstat"))
|
propstat = ET.Element(xmlutils.make_clark("D:propstat"))
|
||||||
status = ET.Element(xmlutils.make_clark("D:status"))
|
status = ET.Element(xmlutils.make_clark("D:status"))
|
||||||
status.text = xmlutils.make_response(code)
|
status.text = xmlutils.make_response(code)
|
||||||
prop_tag = ET.Element(xmlutils.make_clark("D:prop"))
|
prop_element = ET.Element(xmlutils.make_clark("D:prop"))
|
||||||
for prop in props:
|
for prop in props:
|
||||||
prop_tag.append(prop)
|
prop_element.append(prop)
|
||||||
propstat.append(prop_tag)
|
propstat.append(prop_element)
|
||||||
propstat.append(status)
|
propstat.append(status)
|
||||||
response.append(propstat)
|
response.append(propstat)
|
||||||
else:
|
else:
|
||||||
|
@ -76,11 +76,11 @@ class BaseTest:
|
|||||||
status = propstat.find(xmlutils.make_clark("D:status"))
|
status = propstat.find(xmlutils.make_clark("D:status"))
|
||||||
assert status.text.startswith("HTTP/1.1 ")
|
assert status.text.startswith("HTTP/1.1 ")
|
||||||
status_code = int(status.text.split(" ")[1])
|
status_code = int(status.text.split(" ")[1])
|
||||||
for prop in propstat.findall(xmlutils.make_clark("D:prop")):
|
for element in propstat.findall(
|
||||||
for element in prop:
|
"./%s/*" % xmlutils.make_clark("D:prop")):
|
||||||
human_tag = xmlutils.make_human_tag(element.tag)
|
human_tag = xmlutils.make_human_tag(element.tag)
|
||||||
assert human_tag not in prop_respones
|
assert human_tag not in prop_respones
|
||||||
prop_respones[human_tag] = (status_code, element)
|
prop_respones[human_tag] = (status_code, element)
|
||||||
status = response.find(xmlutils.make_clark("D:status"))
|
status = response.find(xmlutils.make_clark("D:status"))
|
||||||
if status is not None:
|
if status is not None:
|
||||||
assert not prop_respones
|
assert not prop_respones
|
||||||
|
Loading…
Reference in New Issue
Block a user