From 2656ac7a92f88ccea776e993ca9eb06b52689273 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 12 May 2014 20:16:17 +0200 Subject: [PATCH] Small refactoring for http storage --- tests/storage/test_http.py | 4 ++-- vdirsyncer/storage/http.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/storage/test_http.py b/tests/storage/test_http.py index 0ca581a..76d54ca 100644 --- a/tests/storage/test_http.py +++ b/tests/storage/test_http.py @@ -107,7 +107,7 @@ def test_list(monkeypatch): for href, etag in s.list(): item, etag2 = s.get(href) - assert item.uid is None + assert item.uid is not None assert etag2 == etag found_items[item.raw.strip()] = href @@ -116,6 +116,6 @@ def test_list(monkeypatch): for href, etag in s.list(): item, etag2 = s.get(href) - assert item.uid is None + assert item.uid is not None assert etag2 == etag assert found_items[item.raw.strip()] == href diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index 396994e..a5cc2e4 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -153,13 +153,13 @@ class HttpStorage(Storage): self._items.clear() for i, item in enumerate(split_collection(r.text.splitlines())): item = Item(u'\n'.join(item), needs_uid=False) + etag = hashlib.sha256(item.raw.encode('utf-8')).hexdigest() if item.uid is None: - item.uid = i - self._items[item.uid] = item + item.uid = etag + self._items[item.uid] = item, etag - for uid, item in self._items.items(): - yield uid, hashlib.sha256(item.raw.encode('utf-8')).hexdigest() + for href, (item, etag) in self._items.items(): + yield href, etag def get(self, href): - x = self._items[href] - return x, hashlib.sha256(x.raw.encode('utf-8')).hexdigest() + return self._items[href]