Work around Google Contacts discovery bug (#564)

* Work around Google Contacts discovery bug

* fixup

* changelog
This commit is contained in:
Markus Unterwaditzer 2017-02-27 16:06:28 +01:00 committed by GitHub
parent 96e7c4da37
commit ded1feb05a
3 changed files with 23 additions and 7 deletions

View file

@ -15,6 +15,7 @@ Version 0.15
- Deprecated syntax for configuration values is now completely rejected. All
values now have to be valid JSON.
- A few UX improvements for Google storages, see :gh:`549` and :gh:`552`.
- Fix collection discovery for :storage:`google_contacts`, see :gh:`564`.
Version 0.14.1
==============

View file

@ -201,6 +201,23 @@ class Discover(object):
dav_logger.debug('Given URL is not a homeset URL')
return self._find_collections_impl(self.find_home())
def _check_collection_resource_type(self, response):
if self._resourcetype is None:
return True
props = _merge_xml(response.findall(
'{DAV:}propstat/{DAV:}prop'
))
if not props:
dav_logger.debug('Skipping, missing <prop>: %s', response)
return False
if props.find('{DAV:}resourcetype/' + self._resourcetype) \
is None:
dav_logger.debug('Skipping, not of resource type %s: %s',
self._resourcetype, response)
return False
return True
def _find_collections_impl(self, url):
headers = self.session.get_default_headers()
headers['Depth'] = '1'
@ -209,13 +226,7 @@ class Discover(object):
root = _parse_xml(r.content)
done = set()
for response in root.findall('{DAV:}response'):
props = _merge_xml(response.findall('{DAV:}propstat/{DAV:}prop'))
if not props:
dav_logger.debug('Skipping, missing <prop>: %s', response)
continue
if props.find('{DAV:}resourcetype/' + self._resourcetype) is None:
dav_logger.debug('Skipping, not of resource type %s: %s',
self._resourcetype, response)
if not self._check_collection_resource_type(response):
continue
href = response.find('{DAV:}href')

View file

@ -164,6 +164,10 @@ class GoogleContactsStorage(dav.CardDAVStorage):
url = 'https://www.googleapis.com/.well-known/carddav'
scope = ['https://www.googleapis.com/auth/carddav']
class discovery_class(dav.CardDAVStorage.discovery_class):
# Google CardDAV doesn't return any resourcetype prop.
_resourcetype = None
storage_name = 'google_contacts'
def __init__(self, token_file, client_id, client_secret, **kwargs):