• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sync.sync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vdirsyncer.sync.sync函数的典型用法代码示例。如果您正苦于以下问题:Python sync函数的具体用法?Python sync怎么用?Python sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sync函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: sync

    def sync(self, status, a, b, force_delete, conflict_resolution):
        old_items_a = self._get_items(a)
        old_items_b = self._get_items(b)

        try:
            # If one storage is read-only, double-sync because changes don't
            # get reverted immediately.
            for _ in range(2 if a.read_only or b.read_only else 1):
                sync(a, b, status,
                     force_delete=force_delete,
                     conflict_resolution=conflict_resolution)
        except BothReadOnly:
            assert a.read_only and b.read_only
            assume(False)
        except StorageEmpty:
            if force_delete:
                raise
            else:
                assert not list(a.list()) or not list(b.list())
                return status

        items_a = self._get_items(a)
        items_b = self._get_items(b)

        assert items_a == items_b
        assert items_a == old_items_a or not a.read_only
        assert items_b == old_items_b or not b.read_only

        return status
开发者ID:ManReinsp,项目名称:vdirsyncer,代码行数:29,代码来源:test_sync.py


示例2: test_irrelevant_status

def test_irrelevant_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {'1': ('1.txt', 1234, '1.ics', 2345)}
    sync(a, b, status)
    assert not status
    assert empty_storage(a)
    assert empty_storage(b)
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:8,代码来源:test_sync.py


示例3: test_both_readonly

def test_both_readonly():
    a = MemoryStorage(read_only=True)
    b = MemoryStorage(read_only=True)
    assert a.read_only
    assert b.read_only
    status = {}
    with pytest.raises(BothReadOnly):
        sync(a, b, status)
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:8,代码来源:test_sync.py


示例4: test_conflict_resolution_invalid_mode

def test_conflict_resolution_invalid_mode():
    a = MemoryStorage()
    b = MemoryStorage()
    item_a = Item(u'UID:1\nitem a')
    item_b = Item(u'UID:1\nitem b')
    a.upload(item_a)
    b.upload(item_b)
    with pytest.raises(ValueError):
        sync(a, b, {}, conflict_resolution='yolo')
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:9,代码来源:test_sync.py


示例5: test_conflict_resolution_new_etags_without_changes

def test_conflict_resolution_new_etags_without_changes():
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item(u'UID:1')
    href_a, etag_a = a.upload(item)
    href_b, etag_b = b.upload(item)
    status = {'1': (href_a, 'BOGUS_a', href_b, 'BOGUS_b')}
    sync(a, b, status)
    assert status == {'1': (href_a, etag_a, href_b, etag_b)}
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:9,代码来源:test_sync.py


示例6: test_readonly

def test_readonly():
    a = MemoryStorage()
    b = MemoryStorage(read_only=True)
    status = {}
    href_a, _ = a.upload(Item(u'UID:1'))
    href_b, _ = b.upload(Item(u'UID:2'))
    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:10,代码来源:test_sync.py


示例7: test_missing_status

def test_missing_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    item = Item(u'asdf')
    href_a, _ = a.upload(item)
    href_b, _ = b.upload(item)
    sync(a, b, status)
    assert len(status) == 1
    assert a.has(href_a)
    assert b.has(href_b)
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:11,代码来源:test_sync.py


示例8: test_no_uids

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'}
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:12,代码来源:test_sync.py


示例9: test_updated_and_deleted

def test_updated_and_deleted():
    a = MemoryStorage()
    b = MemoryStorage()
    href_a, etag_a = a.upload(Item(u"UID:1"))
    status = {}
    sync(a, b, status, force_delete=True)

    (href_b, etag_b), = b.list()
    b.delete(href_b, etag_b)
    a.update(href_a, Item(u"UID:1\nupdated"), etag_a)
    sync(a, b, status, force_delete=True)

    assert len(list(a.list())) == len(list(b.list())) == 1
开发者ID:geier,项目名称:vdirsyncer,代码行数:13,代码来源:test_sync.py


示例10: test_already_synced

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", "etag": a.get("1.a")[1]}, {"href": "1.b", "etag": b.get("1.b")[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.a") and b.has("1.b")
开发者ID:geier,项目名称:vdirsyncer,代码行数:14,代码来源:test_sync.py


示例11: test_missing_status_and_different_items

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])
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:14,代码来源:test_sync.py


示例12: test_readonly

def test_readonly():
    a = MemoryStorage(instance_name="a")
    b = MemoryStorage(instance_name="b")
    status = {}
    href_a, _ = a.upload(Item(u"UID:1"))
    href_b, _ = b.upload(Item(u"UID:2"))
    b.read_only = True
    with pytest.raises(exceptions.ReadOnlyError):
        b.upload(Item(u"UID:3"))

    sync(a, b, status)
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status)
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
开发者ID:geier,项目名称:vdirsyncer,代码行数:14,代码来源:test_sync.py


示例13: test_read_only_and_prefetch

def test_read_only_and_prefetch():
    a = MemoryStorage()
    b = MemoryStorage()
    b.read_only = True

    status = {}
    item1 = Item(u"UID:1\nhaha")
    item2 = Item(u"UID:2\nhoho")
    a.upload(item1)
    a.upload(item2)

    sync(a, b, status, force_delete=True)
    sync(a, b, status, force_delete=True)

    assert list(a.list()) == list(b.list()) == []
开发者ID:geier,项目名称:vdirsyncer,代码行数:15,代码来源:test_sync.py


示例14: test_conflict_resolution_new_etags_without_changes

def test_conflict_resolution_new_etags_without_changes():
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item(u"UID:1")
    href_a, etag_a = a.upload(item)
    href_b, etag_b = b.upload(item)
    status = {"1": (href_a, "BOGUS_a", href_b, "BOGUS_b")}

    sync(a, b, status)

    (ident, (status_a, status_b)), = status.items()
    assert ident == "1"
    assert status_a["href"] == href_a
    assert status_a["etag"] == etag_a
    assert status_b["href"] == href_b
    assert status_b["etag"] == etag_b
开发者ID:geier,项目名称:vdirsyncer,代码行数:16,代码来源:test_sync.py


示例15: test_already_synced

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')
开发者ID:davidfraser,项目名称:vdirsyncer,代码行数:17,代码来源:test_sync.py



注:本文中的vdirsyncer.sync.sync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.SQLAlchemySession类代码示例发布时间:2022-05-26
下一篇:
Python memory.MemoryStorage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap