本文整理汇总了Python中vdirsyncer.storage.memory.MemoryStorage.get方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryStorage.get方法的具体用法?Python MemoryStorage.get怎么用?Python MemoryStorage.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vdirsyncer.storage.memory.MemoryStorage
的用法示例。
在下文中一共展示了MemoryStorage.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_already_synced
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_already_synced():
a = MemoryStorage(fileext='.a')
b = MemoryStorage(fileext='.b')
item = Item(u'UID:1')
a.upload(item)
b.upload(item)
status = {
'1': ({
'href': '1.a',
'hash': item.hash,
'etag': a.get('1.a')[1]
}, {
'href': '1.b',
'hash': item.hash,
'etag': b.get('1.b')[1]
})
}
old_status = deepcopy(status)
a.update = b.update = a.upload = b.upload = \
lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')
for _ in (1, 2):
sync(a, b, status)
assert status == old_status
assert items(a) == items(b) == {item.raw}
示例2: test_no_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_no_uids():
a = MemoryStorage()
b = MemoryStorage()
href_a, _ = a.upload(Item(u'ASDF'))
href_b, _ = b.upload(Item(u'FOOBAR'))
status = {}
sync(a, b, status)
a_items = set(a.get(href)[0].raw for href, etag in a.list())
b_items = set(b.get(href)[0].raw for href, etag in b.list())
assert a_items == b_items == {u'ASDF', u'FOOBAR'}
示例3: test_repair_unsafe_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_unsafe_uids(uid):
s = MemoryStorage()
item = Item(u'BEGIN:VCARD\nUID:123\nEND:VCARD').with_uid(uid)
href, etag = s.upload(item)
assert s.get(href)[0].uid == uid
assert not href_safe(uid)
repair_storage(s, repair_unsafe_uid=True)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例4: test_repair_unsafe_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_unsafe_uids(uid):
assert not href_safe(uid)
s = MemoryStorage()
href, etag = s.upload(Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid)))
assert s.get(href)[0].uid == uid
repair_storage(s)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例5: test_repair_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_uids():
s = MemoryStorage()
s.items = {
'one': ('asdf', Item(u'BEGIN:VCARD\nFN:Hans\nUID:asdf\nEND:VCARD')),
'two': ('asdf', Item(u'BEGIN:VCARD\nFN:Peppi\nUID:asdf\nEND:VCARD'))
}
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 == uid2
repair_storage(s)
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 != uid2
示例6: test_repair_unsafe_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_unsafe_uids(uid):
s = MemoryStorage()
item = Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid))
print(repr(item.raw))
href, etag = s.upload(item)
assert s.get(href)[0].uid == uid
assert not href_safe(uid)
repair_storage(s, repair_unsafe_uid=True)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例7: test_missing_status_and_different_items
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_missing_status_and_different_items():
a = MemoryStorage()
b = MemoryStorage()
status = {}
item1 = Item(u'UID:1\nhaha')
item2 = Item(u'UID:1\nhoho')
a.upload(item1)
b.upload(item2)
with pytest.raises(SyncConflict):
sync(a, b, status)
assert not status
sync(a, b, status, conflict_resolution='a wins')
assert_item_equals(item1, b.get('1.txt')[0])
assert_item_equals(item1, a.get('1.txt')[0])
示例8: test_repair_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_uids():
s = MemoryStorage()
s.upload(Item(u'BEGIN:VCARD\nEND:VCARD'))
repair_storage(s)
uid, = [s.get(href)[0].uid for href, etag in s.list()]
s.upload(Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid)))
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 == uid2
repair_storage(s)
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 != uid2
示例9: test_already_synced
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_already_synced():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
a.upload(item)
b.upload(item)
status = {
'1': ('1.txt', a.get('1.txt')[1], '1.txt', b.get('1.txt')[1])
}
old_status = dict(status)
a.update = b.update = a.upload = b.upload = \
lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')
for i in (1, 2):
sync(a, b, status)
assert status == old_status
assert a.has('1.txt') and b.has('1.txt')
示例10: test_deletion
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_deletion():
a = MemoryStorage(fileext=".a")
b = MemoryStorage(fileext=".b")
status = {}
item = Item(u"UID:1")
a.upload(item)
a.upload(Item(u"UID:2"))
sync(a, b, status)
b.delete("1.b", b.get("1.b")[1])
sync(a, b, status)
assert not a.has("1.a") and not b.has("1.b")
a.upload(item)
sync(a, b, status)
assert a.has("1.a") and b.has("1.b")
a.delete("1.a", a.get("1.a")[1])
sync(a, b, status)
assert not a.has("1.a") and not b.has("1.b")
示例11: test_deletion
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_deletion():
a = MemoryStorage()
b = MemoryStorage()
status = {}
item = Item(u'UID:1')
a.upload(item)
a.upload(Item(u'UID:2'))
sync(a, b, status)
b.delete('1.txt', b.get('1.txt')[1])
sync(a, b, status)
assert not a.has('1.txt') and not b.has('1.txt')
a.upload(item)
sync(a, b, status)
assert a.has('1.txt') and b.has('1.txt')
a.delete('1.txt', a.get('1.txt')[1])
sync(a, b, status)
assert not a.has('1.txt') and not b.has('1.txt')
示例12: test_repair_uids
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_repair_uids(uid):
s = MemoryStorage()
s.items = {
'one': (
'asdf',
Item(u'BEGIN:VCARD\nFN:Hans\nUID:{}\nEND:VCARD'.format(uid))
),
'two': (
'asdf',
Item(u'BEGIN:VCARD\nFN:Peppi\nUID:{}\nEND:VCARD'.format(uid))
)
}
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 == uid2
repair_storage(s, repair_unsafe_uid=False)
uid1, uid2 = [s.get(href)[0].uid for href, etag in s.list()]
assert uid1 != uid2
示例13: test_conflict_resolution_both_etags_new
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_conflict_resolution_both_etags_new(winning_storage):
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
href_a, etag_a = a.upload(item)
href_b, etag_b = b.upload(item)
status = {}
sync(a, b, status)
assert status
a.update(href_a, Item(u'UID:1\nitem a'), etag_a)
b.update(href_b, Item(u'UID:1\nitem b'), etag_b)
with pytest.raises(SyncConflict):
sync(a, b, status)
sync(a, b, status, conflict_resolution='{} wins'.format(winning_storage))
item_a, _ = a.get(href_a)
item_b, _ = b.get(href_b)
assert_item_equals(item_a, item_b)
n = normalize_item(item_a)
assert u'UID:1' in n
assert u'item {}'.format(winning_storage) in n
示例14: test_deletion
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_deletion():
a = MemoryStorage(fileext='.a')
b = MemoryStorage(fileext='.b')
status = {}
item = Item(u'UID:1')
a.upload(item)
item2 = Item(u'UID:2')
a.upload(item2)
sync(a, b, status)
b.delete('1.b', b.get('1.b')[1])
sync(a, b, status)
assert items(a) == items(b) == {item2.raw}
a.upload(item)
sync(a, b, status)
assert items(a) == items(b) == {item.raw, item2.raw}
a.delete('1.a', a.get('1.a')[1])
sync(a, b, status)
assert items(a) == items(b) == {item2.raw}
示例15: test_conflict_resolution_both_etags_new
# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import get [as 别名]
def test_conflict_resolution_both_etags_new(winning_storage):
a = MemoryStorage()
b = MemoryStorage()
item = Item(u"UID:1")
href_a, etag_a = a.upload(item)
href_b, etag_b = b.upload(item)
status = {}
sync(a, b, status)
assert status
a.update(href_a, Item(u"UID:1\nitem a"), etag_a)
b.update(href_b, Item(u"UID:1\nitem b"), etag_b)
with pytest.raises(SyncConflict):
sync(a, b, status)
sync(a, b, status, conflict_resolution="{} wins".format(winning_storage))
item_a, _ = a.get(href_a)
item_b, _ = b.get(href_b)
assert_item_equals(item_a, item_b)
n = item_a.raw.splitlines()
assert u"UID:1" in n
assert u"item {}".format(winning_storage) in n