mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Simplify code
This commit is contained in:
parent
2a80dfae30
commit
3258a59e99
1 changed files with 14 additions and 18 deletions
|
|
@ -64,8 +64,7 @@ def _fuzzy_matches_mimetype(strict, weak):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _catch_generator_exceptions(rv=None):
|
def _catch_generator_exceptions(f):
|
||||||
def wrapper(f):
|
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
|
@ -74,10 +73,7 @@ def _catch_generator_exceptions(rv=None):
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
dav_logger.debug(traceback.format_exc())
|
dav_logger.debug(traceback.format_exc())
|
||||||
for x in rv:
|
|
||||||
yield x
|
|
||||||
return inner
|
return inner
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class Discover(object):
|
class Discover(object):
|
||||||
|
|
@ -97,7 +93,7 @@ class Discover(object):
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
self.session = session
|
self.session = session
|
||||||
|
|
||||||
@_catch_generator_exceptions(rv=())
|
@_catch_generator_exceptions
|
||||||
def _find_principal(self, url):
|
def _find_principal(self, url):
|
||||||
"""tries to find the principal URL of the user
|
"""tries to find the principal URL of the user
|
||||||
:returns: iterable (but should be only of element) of urls
|
:returns: iterable (but should be only of element) of urls
|
||||||
|
|
@ -122,7 +118,7 @@ class Discover(object):
|
||||||
if principal.tag.endswith('href'):
|
if principal.tag.endswith('href'):
|
||||||
yield principal.text
|
yield principal.text
|
||||||
|
|
||||||
@_catch_generator_exceptions(rv=())
|
@_catch_generator_exceptions
|
||||||
def _find_dav(self):
|
def _find_dav(self):
|
||||||
response = self.session.request('GET', self._well_known_uri)
|
response = self.session.request('GET', self._well_known_uri)
|
||||||
yield response.url
|
yield response.url
|
||||||
|
|
@ -150,7 +146,7 @@ class Discover(object):
|
||||||
done.add(href)
|
done.add(href)
|
||||||
yield collection
|
yield collection
|
||||||
|
|
||||||
@_catch_generator_exceptions(rv=())
|
@_catch_generator_exceptions
|
||||||
def _find_homes(self, principal):
|
def _find_homes(self, principal):
|
||||||
headers = self.session.get_default_headers()
|
headers = self.session.get_default_headers()
|
||||||
headers['Depth'] = 0
|
headers['Depth'] = 0
|
||||||
|
|
@ -164,7 +160,7 @@ class Discover(object):
|
||||||
if homeset.tag.endswith('href'):
|
if homeset.tag.endswith('href'):
|
||||||
yield homeset.text
|
yield homeset.text
|
||||||
|
|
||||||
@_catch_generator_exceptions(rv=())
|
@_catch_generator_exceptions
|
||||||
def _find_collections(self, home):
|
def _find_collections(self, home):
|
||||||
"""find all CalDAV collections under `home`"""
|
"""find all CalDAV collections under `home`"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue