Skip to content

Commit 989568d

Browse files
committed
Abstract listing compat hacks
1 parent ec93bc9 commit 989568d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

vdirsyncer/storage/remotestorage.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
def _ensure_slash(dir):
2121
return dir.rstrip('/') + '/'
2222

23+
def _iter_listing(json):
24+
new_listing = '@context' in json # draft-02 and beyond
25+
if new_listing:
26+
json = json['items']
27+
for name, info in utils.compat.iteritems(json):
28+
if not new_listing:
29+
info = {'ETag': info}
30+
yield name, info
31+
2332

2433
class Session(object):
2534
def __init__(self, account, fileext, verify=True, verify_fingerprint=None,
@@ -140,7 +149,7 @@ def discover(cls, **base_args):
140149
except exceptions.NotFoundError:
141150
return
142151

143-
for name, info in utils.compat.iteritems(r.json()['items']):
152+
for name, info in _iter_listing(r.json()):
144153
if not name.endswith('/'):
145154
continue # not a folder
146155

@@ -162,20 +171,11 @@ def list(self):
162171
except exceptions.NotFoundError:
163172
return
164173

165-
j = r.json()
166-
new_listing = '@context' in j # draft-02 and beyond
167-
if new_listing:
168-
j = j['items']
169-
170-
for name, info in utils.compat.iteritems(j):
171-
if new_listing:
172-
etag = info['ETag']
173-
else:
174-
etag = info
175-
174+
for name, info in _iter_listing(r.json()):
176175
if not name.endswith(self.fileext):
177176
continue
178177

178+
etag = info['ETag']
179179
etag = '"' + etag + '"'
180180
yield name, etag
181181

0 commit comments

Comments
 (0)