mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
More refactoring in create_collection for DAV
This commit is contained in:
parent
4cfca383d9
commit
6ed02b9a3e
1 changed files with 26 additions and 19 deletions
|
|
@ -322,8 +322,20 @@ class DavStorage(Storage):
|
||||||
return c
|
return c
|
||||||
|
|
||||||
home = d.find_home()
|
home = d.find_home()
|
||||||
collection_url = '{}/{}'.format(home.rstrip('/'), collection)
|
url = '{}/{}'.format(home.rstrip('/'), collection)
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = cls._create_collection_impl(d, url, kwargs)
|
||||||
|
except HTTPError as e:
|
||||||
|
raise NotImplementedError(e)
|
||||||
|
else:
|
||||||
|
rv = dict(kwargs)
|
||||||
|
rv['collection'] = collection
|
||||||
|
rv['url'] = url
|
||||||
|
return rv
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create_collection_impl(cls, d, url, kwargs):
|
||||||
data = '''<?xml version="1.0" encoding="utf-8" ?>
|
data = '''<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<D:mkcol xmlns:D="DAV:" xmlns:C="{}">
|
<D:mkcol xmlns:D="DAV:" xmlns:C="{}">
|
||||||
<D:set>
|
<D:set>
|
||||||
|
|
@ -337,18 +349,13 @@ class DavStorage(Storage):
|
||||||
</D:mkcol>
|
</D:mkcol>
|
||||||
'''.format(cls._dav_namespace, cls._dav_resourcetype)
|
'''.format(cls._dav_namespace, cls._dav_resourcetype)
|
||||||
|
|
||||||
headers = d.session.get_default_headers()
|
response = d.session.request(
|
||||||
|
'MKCOL',
|
||||||
try:
|
url,
|
||||||
response = d.session.request('MKCOL', collection_url, data=data,
|
data=data,
|
||||||
headers=headers)
|
headers=d.session.get_default_headers(),
|
||||||
except HTTPError as e:
|
)
|
||||||
raise NotImplementedError(e)
|
return response.url
|
||||||
else:
|
|
||||||
rv = dict(kwargs)
|
|
||||||
rv['collection'] = collection
|
|
||||||
rv['url'] = response.url
|
|
||||||
return rv
|
|
||||||
|
|
||||||
def _normalize_href(self, *args, **kwargs):
|
def _normalize_href(self, *args, **kwargs):
|
||||||
return _normalize_href(self.session.url, *args, **kwargs)
|
return _normalize_href(self.session.url, *args, **kwargs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue