mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
First version of autodiscovery support in dav
This commit is contained in:
parent
51aaba1965
commit
9646fda248
3 changed files with 25 additions and 0 deletions
|
|
@ -26,6 +26,10 @@ class DavStorage(Storage):
|
||||||
get_multi_template = None
|
get_multi_template = None
|
||||||
# The LXML query for extracting results in get_multi
|
# The LXML query for extracting results in get_multi
|
||||||
get_multi_data_query = None
|
get_multi_data_query = None
|
||||||
|
# The leif class to use for autodiscovery
|
||||||
|
# This should be the class *name* (i.e. "module attribute name") instead of
|
||||||
|
# the class, because leif is an optional dependency
|
||||||
|
leif_class = None
|
||||||
|
|
||||||
_session = None
|
_session = None
|
||||||
_repr_attributes = ('url', 'username')
|
_repr_attributes = ('url', 'username')
|
||||||
|
|
@ -74,6 +78,25 @@ class DavStorage(Storage):
|
||||||
if self.dav_header not in response.headers.get('DAV', ''):
|
if self.dav_header not in response.headers.get('DAV', ''):
|
||||||
raise exceptions.StorageError('URL is not a collection')
|
raise exceptions.StorageError('URL is not a collection')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def discover(cls, url, **kwargs):
|
||||||
|
if kwargs.pop('collection', None) is not None:
|
||||||
|
raise TypeError('collection argument must not be given.')
|
||||||
|
from leif import leif
|
||||||
|
d = getattr(leif, cls.leif_class)(
|
||||||
|
url,
|
||||||
|
user=kwargs.get('username', None),
|
||||||
|
password=kwargs.get('password', None),
|
||||||
|
ssl_verify=kwargs.get('verify', True)
|
||||||
|
)
|
||||||
|
for c in d.discover():
|
||||||
|
collection = c['href']
|
||||||
|
if collection.startswith(url):
|
||||||
|
collection = collection[len(url):]
|
||||||
|
s = cls(url=url, collection=collection, **kwargs)
|
||||||
|
s.displayname = c['displayname']
|
||||||
|
yield s
|
||||||
|
|
||||||
def _normalize_href(self, href):
|
def _normalize_href(self, href):
|
||||||
'''Normalize the href to be a path only relative to hostname and
|
'''Normalize the href to be a path only relative to hostname and
|
||||||
schema.'''
|
schema.'''
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ class CaldavStorage(DavStorage):
|
||||||
fileext = '.ics'
|
fileext = '.ics'
|
||||||
item_mimetype = 'text/calendar'
|
item_mimetype = 'text/calendar'
|
||||||
dav_header = 'calendar-access'
|
dav_header = 'calendar-access'
|
||||||
|
leif_class = 'CalDiscover'
|
||||||
|
|
||||||
start_date = None
|
start_date = None
|
||||||
end_date = None
|
end_date = None
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class CarddavStorage(DavStorage):
|
||||||
fileext = '.vcf'
|
fileext = '.vcf'
|
||||||
item_mimetype = 'text/vcard'
|
item_mimetype = 'text/vcard'
|
||||||
dav_header = 'addressbook'
|
dav_header = 'addressbook'
|
||||||
|
leif_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:D="DAV:"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue