From 6ed02b9a3ea7ef79532f5a0000bc3773a2117f4f Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Tue, 19 May 2015 13:40:34 +0200 Subject: [PATCH] More refactoring in create_collection for DAV --- vdirsyncer/storage/dav.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index 17f22f5..a5136ed 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -322,34 +322,41 @@ class DavStorage(Storage): return c home = d.find_home() - collection_url = '{}/{}'.format(home.rstrip('/'), collection) - - data = ''' - - - - - - - - - - - '''.format(cls._dav_namespace, cls._dav_resourcetype) - - headers = d.session.get_default_headers() + url = '{}/{}'.format(home.rstrip('/'), collection) try: - response = d.session.request('MKCOL', collection_url, data=data, - headers=headers) + url = cls._create_collection_impl(d, url, kwargs) except HTTPError as e: raise NotImplementedError(e) else: rv = dict(kwargs) rv['collection'] = collection - rv['url'] = response.url + rv['url'] = url return rv + @classmethod + def _create_collection_impl(cls, d, url, kwargs): + data = ''' + + + + + + + + + + + '''.format(cls._dav_namespace, cls._dav_resourcetype) + + response = d.session.request( + 'MKCOL', + url, + data=data, + headers=d.session.get_default_headers(), + ) + return response.url + def _normalize_href(self, *args, **kwargs): return _normalize_href(self.session.url, *args, **kwargs)