mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Small refactoring for http storage
This commit is contained in:
parent
f565cd43a9
commit
2656ac7a92
2 changed files with 8 additions and 8 deletions
|
|
@ -107,7 +107,7 @@ def test_list(monkeypatch):
|
||||||
|
|
||||||
for href, etag in s.list():
|
for href, etag in s.list():
|
||||||
item, etag2 = s.get(href)
|
item, etag2 = s.get(href)
|
||||||
assert item.uid is None
|
assert item.uid is not None
|
||||||
assert etag2 == etag
|
assert etag2 == etag
|
||||||
found_items[item.raw.strip()] = href
|
found_items[item.raw.strip()] = href
|
||||||
|
|
||||||
|
|
@ -116,6 +116,6 @@ def test_list(monkeypatch):
|
||||||
|
|
||||||
for href, etag in s.list():
|
for href, etag in s.list():
|
||||||
item, etag2 = s.get(href)
|
item, etag2 = s.get(href)
|
||||||
assert item.uid is None
|
assert item.uid is not None
|
||||||
assert etag2 == etag
|
assert etag2 == etag
|
||||||
assert found_items[item.raw.strip()] == href
|
assert found_items[item.raw.strip()] == href
|
||||||
|
|
|
||||||
|
|
@ -153,13 +153,13 @@ class HttpStorage(Storage):
|
||||||
self._items.clear()
|
self._items.clear()
|
||||||
for i, item in enumerate(split_collection(r.text.splitlines())):
|
for i, item in enumerate(split_collection(r.text.splitlines())):
|
||||||
item = Item(u'\n'.join(item), needs_uid=False)
|
item = Item(u'\n'.join(item), needs_uid=False)
|
||||||
|
etag = hashlib.sha256(item.raw.encode('utf-8')).hexdigest()
|
||||||
if item.uid is None:
|
if item.uid is None:
|
||||||
item.uid = i
|
item.uid = etag
|
||||||
self._items[item.uid] = item
|
self._items[item.uid] = item, etag
|
||||||
|
|
||||||
for uid, item in self._items.items():
|
for href, (item, etag) in self._items.items():
|
||||||
yield uid, hashlib.sha256(item.raw.encode('utf-8')).hexdigest()
|
yield href, etag
|
||||||
|
|
||||||
def get(self, href):
|
def get(self, href):
|
||||||
x = self._items[href]
|
return self._items[href]
|
||||||
return x, hashlib.sha256(x.raw.encode('utf-8')).hexdigest()
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue