Merge branch 'dav_default_ns'

This commit is contained in:
Hugo Osvaldo Barrera 2021-04-07 09:10:53 +02:00
commit f549b1d706
2 changed files with 75 additions and 75 deletions

View file

@ -7,23 +7,23 @@ from vdirsyncer.storage.dav import _parse_xml
def test_xml_utilities(): def test_xml_utilities():
x = _parse_xml(b'''<?xml version="1.0" encoding="UTF-8" ?> x = _parse_xml(b'''<?xml version="1.0" encoding="UTF-8" ?>
<D:multistatus xmlns:D="DAV:"> <multistatus xmlns="DAV:">
<D:response> <response>
<D:propstat> <propstat>
<D:status>HTTP/1.1 404 Not Found</D:status> <status>HTTP/1.1 404 Not Found</status>
<D:prop> <prop>
<D:getcontenttype/> <getcontenttype/>
</D:prop> </prop>
</D:propstat> </propstat>
<D:propstat> <propstat>
<D:prop> <prop>
<D:resourcetype> <resourcetype>
<D:collection/> <collection/>
</D:resourcetype> </resourcetype>
</D:prop> </prop>
</D:propstat> </propstat>
</D:response> </response>
</D:multistatus> </multistatus>
''') ''')
response = x.find('{DAV:}response') response = x.find('{DAV:}response')

View file

@ -150,11 +150,11 @@ class Discover:
_homeset_tag = None _homeset_tag = None
_well_known_uri = None _well_known_uri = None
_collection_xml = b""" _collection_xml = b"""
<d:propfind xmlns:d="DAV:"> <propfind xmlns="DAV:">
<d:prop> <prop>
<d:resourcetype /> <resourcetype />
</d:prop> </prop>
</d:propfind> </propfind>
""" """
def __init__(self, session, kwargs): def __init__(self, session, kwargs):
@ -180,11 +180,11 @@ class Discover:
headers = self.session.get_default_headers() headers = self.session.get_default_headers()
headers['Depth'] = '0' headers['Depth'] = '0'
body = b""" body = b"""
<d:propfind xmlns:d="DAV:"> <propfind xmlns="DAV:">
<d:prop> <prop>
<d:current-user-principal /> <current-user-principal />
</d:prop> </prop>
</d:propfind> </propfind>
""" """
response = self.session.request('PROPFIND', url, headers=headers, response = self.session.request('PROPFIND', url, headers=headers,
@ -300,16 +300,16 @@ class Discover:
def _create_collection_impl(self, url): def _create_collection_impl(self, url):
data = '''<?xml version="1.0" encoding="utf-8" ?> data = '''<?xml version="1.0" encoding="utf-8" ?>
<D:mkcol xmlns:D="DAV:"> <mkcol xmlns="DAV:">
<D:set> <set>
<D:prop> <prop>
<D:resourcetype> <resourcetype>
<D:collection/> <collection/>
{} {}
</D:resourcetype> </resourcetype>
</D:prop> </prop>
</D:set> </set>
</D:mkcol> </mkcol>
'''.format( '''.format(
etree.tostring(etree.Element(self._resourcetype), etree.tostring(etree.Element(self._resourcetype),
encoding='unicode') encoding='unicode')
@ -328,11 +328,11 @@ class CalDiscover(Discover):
_namespace = 'urn:ietf:params:xml:ns:caldav' _namespace = 'urn:ietf:params:xml:ns:caldav'
_resourcetype = '{%s}calendar' % _namespace _resourcetype = '{%s}calendar' % _namespace
_homeset_xml = b""" _homeset_xml = b"""
<d:propfind xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"> <propfind xmlns="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:prop> <prop>
<c:calendar-home-set /> <c:calendar-home-set />
</d:prop> </prop>
</d:propfind> </propfind>
""" """
_homeset_tag = '{%s}calendar-home-set' % _namespace _homeset_tag = '{%s}calendar-home-set' % _namespace
_well_known_uri = '/.well-known/caldav' _well_known_uri = '/.well-known/caldav'
@ -342,11 +342,11 @@ class CardDiscover(Discover):
_namespace = 'urn:ietf:params:xml:ns:carddav' _namespace = 'urn:ietf:params:xml:ns:carddav'
_resourcetype = '{%s}addressbook' % _namespace _resourcetype = '{%s}addressbook' % _namespace
_homeset_xml = b""" _homeset_xml = b"""
<d:propfind xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> <propfind xmlns="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
<d:prop> <prop>
<c:addressbook-home-set /> <c:addressbook-home-set />
</d:prop> </prop>
</d:propfind> </propfind>
""" """
_homeset_tag = '{%s}addressbook-home-set' % _namespace _homeset_tag = '{%s}addressbook-home-set' % _namespace
_well_known_uri = '/.well-known/carddav' _well_known_uri = '/.well-known/carddav'
@ -463,7 +463,7 @@ class DAVStorage(Storage):
for href in hrefs: for href in hrefs:
if href != self._normalize_href(href): if href != self._normalize_href(href):
raise exceptions.NotFoundError(href) raise exceptions.NotFoundError(href)
href_xml.append(f'<D:href>{href}</D:href>') href_xml.append(f'<href>{href}</href>')
if not href_xml: if not href_xml:
return () return ()
@ -620,13 +620,13 @@ class DAVStorage(Storage):
headers['Depth'] = '1' headers['Depth'] = '1'
data = b'''<?xml version="1.0" encoding="utf-8" ?> data = b'''<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:"> <propfind xmlns="DAV:">
<D:prop> <prop>
<D:resourcetype/> <resourcetype/>
<D:getcontenttype/> <getcontenttype/>
<D:getetag/> <getetag/>
</D:prop> </prop>
</D:propfind> </propfind>
''' '''
# We use a PROPFIND request instead of addressbook-query due to issues # We use a PROPFIND request instead of addressbook-query due to issues
@ -647,11 +647,11 @@ class DAVStorage(Storage):
xpath = f'{{{namespace}}}{tagname}' xpath = f'{{{namespace}}}{tagname}'
data = '''<?xml version="1.0" encoding="utf-8" ?> data = '''<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:"> <propfind xmlns="DAV:">
<D:prop> <prop>
{} {}
</D:prop> </prop>
</D:propfind> </propfind>
'''.format( '''.format(
etree.tostring(etree.Element(xpath), encoding='unicode') etree.tostring(etree.Element(xpath), encoding='unicode')
).encode('utf-8') ).encode('utf-8')
@ -683,13 +683,13 @@ class DAVStorage(Storage):
element.text = normalize_meta_value(value) element.text = normalize_meta_value(value)
data = '''<?xml version="1.0" encoding="utf-8" ?> data = '''<?xml version="1.0" encoding="utf-8" ?>
<D:propertyupdate xmlns:D="DAV:"> <propertyupdate xmlns="DAV:">
<D:set> <set>
<D:prop> <prop>
{} {}
</D:prop> </prop>
</D:set> </set>
</D:propertyupdate> </propertyupdate>
'''.format(etree.tostring(element, encoding='unicode')).encode('utf-8') '''.format(etree.tostring(element, encoding='unicode')).encode('utf-8')
self.session.request( self.session.request(
@ -714,12 +714,12 @@ class CalDAVStorage(DAVStorage):
end_date = None end_date = None
get_multi_template = '''<?xml version="1.0" encoding="utf-8" ?> get_multi_template = '''<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-multiget xmlns:D="DAV:" <C:calendar-multiget xmlns="DAV:"
xmlns:C="urn:ietf:params:xml:ns:caldav"> xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop> <prop>
<D:getetag/> <getetag/>
<C:calendar-data/> <C:calendar-data/>
</D:prop> </prop>
{hrefs} {hrefs}
</C:calendar-multiget>''' </C:calendar-multiget>'''
@ -796,12 +796,12 @@ class CalDAVStorage(DAVStorage):
yield from DAVStorage.list(self) yield from DAVStorage.list(self)
data = '''<?xml version="1.0" encoding="utf-8" ?> data = '''<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" <C:calendar-query xmlns="DAV:"
xmlns:C="urn:ietf:params:xml:ns:caldav"> xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop> <prop>
<D:getcontenttype/> <getcontenttype/>
<D:getetag/> <getetag/>
</D:prop> </prop>
<C:filter> <C:filter>
{caldavfilter} {caldavfilter}
</C:filter> </C:filter>
@ -833,12 +833,12 @@ class CardDAVStorage(DAVStorage):
discovery_class = CardDiscover discovery_class = CardDiscover
get_multi_template = '''<?xml version="1.0" encoding="utf-8" ?> get_multi_template = '''<?xml version="1.0" encoding="utf-8" ?>
<C:addressbook-multiget xmlns:D="DAV:" <C:addressbook-multiget xmlns="DAV:"
xmlns:C="urn:ietf:params:xml:ns:carddav"> xmlns:C="urn:ietf:params:xml:ns:carddav">
<D:prop> <prop>
<D:getetag/> <getetag/>
<C:address-data/> <C:address-data/>
</D:prop> </prop>
{hrefs} {hrefs}
</C:addressbook-multiget>''' </C:addressbook-multiget>'''