当前位置: 首页>>代码示例>>Python>>正文


Python MemoryStorage.read_only方法代码示例

本文整理汇总了Python中vdirsyncer.storage.memory.MemoryStorage.read_only方法的典型用法代码示例。如果您正苦于以下问题:Python MemoryStorage.read_only方法的具体用法?Python MemoryStorage.read_only怎么用?Python MemoryStorage.read_only使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vdirsyncer.storage.memory.MemoryStorage的用法示例。


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

示例1: test_partial_sync_revert

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
def test_partial_sync_revert():
    a = MemoryStorage(instance_name='a')
    b = MemoryStorage(instance_name='b')
    status = {}
    a.upload(Item(u'UID:1'))
    b.upload(Item(u'UID:2'))
    b.read_only = True

    sync(a, b, status, partial_sync='revert')
    assert len(status) == 2
    assert items(a) == {'UID:1', 'UID:2'}
    assert items(b) == {'UID:2'}

    sync(a, b, status, partial_sync='revert')
    assert len(status) == 1
    assert items(a) == {'UID:2'}
    assert items(b) == {'UID:2'}

    # Check that updates get reverted
    a.items[next(iter(a.items))] = ('foo', Item('UID:2\nupdated'))
    assert items(a) == {'UID:2\nupdated'}
    sync(a, b, status, partial_sync='revert')
    assert len(status) == 1
    assert items(a) == {'UID:2\nupdated'}
    sync(a, b, status, partial_sync='revert')
    assert items(a) == {'UID:2'}

    # Check that deletions get reverted
    a.items.clear()
    sync(a, b, status, partial_sync='revert', force_delete=True)
    sync(a, b, status, partial_sync='revert', force_delete=True)
    assert items(a) == {'UID:2'}
开发者ID:DamienCassou,项目名称:vdirsyncer,代码行数:34,代码来源:test_sync.py

示例2: test_partial_sync_error

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
def test_partial_sync_error():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.upload(Item('UID:0'))
    b.read_only = True

    with pytest.raises(PartialSync):
        sync(a, b, status, partial_sync='error')
开发者ID:DamienCassou,项目名称:vdirsyncer,代码行数:12,代码来源:test_sync.py

示例3: newstorage

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
    def newstorage(self, read_only, flaky_etags):
        s = MemoryStorage()
        s.read_only = read_only
        if flaky_etags:
            def get(href):
                _, item = s.items[href]
                etag = _random_string()
                s.items[href] = etag, item
                return item, etag
            s.get = get

        return s
开发者ID:evgeni,项目名称:vdirsyncer,代码行数:14,代码来源:test_sync.py

示例4: test_partial_sync_ignore2

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
def test_partial_sync_ignore2():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    href, etag = a.upload(Item('UID:0'))
    a.read_only = True

    sync(a, b, status, partial_sync='ignore', force_delete=True)
    assert items(b) == items(a) == {'UID:0'}

    b.items.clear()
    sync(a, b, status, partial_sync='ignore', force_delete=True)
    sync(a, b, status, partial_sync='ignore', force_delete=True)
    assert items(a) == {'UID:0'}
    assert not b.items

    a.read_only = False
    a.update(href, Item('UID:0\nupdated'), etag)
    a.read_only = True
    sync(a, b, status, partial_sync='ignore', force_delete=True)
    assert items(b) == items(a) == {'UID:0\nupdated'}
开发者ID:,项目名称:,代码行数:24,代码来源:

示例5: test_readonly

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
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, partial_sync='revert')
    assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
    sync(a, b, status, partial_sync='revert')
    assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
开发者ID:,项目名称:,代码行数:16,代码来源:

示例6: test_readonly

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
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,代码行数:16,代码来源:test_sync.py

示例7: test_read_only_and_prefetch

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
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 not items(a) and not items(b)
开发者ID:,项目名称:,代码行数:17,代码来源:

示例8: test_read_only_and_prefetch

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
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,代码行数:17,代码来源:test_sync.py

示例9: newstorage

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
    def newstorage(self, read_only, flaky_etags, null_etag_on_upload):
        s = MemoryStorage()
        s.read_only = read_only
        if flaky_etags:
            def get(href):
                old_etag, item = s.items[href]
                etag = _random_string()
                s.items[href] = etag, item
                return item, etag
            s.get = get

        if null_etag_on_upload:
            _old_upload = s.upload
            _old_update = s.update
            s.upload = lambda item: (_old_upload(item)[0], 'NULL')
            s.update = lambda h, i, e: _old_update(h, i, e) and 'NULL'

        return s
开发者ID:,项目名称:,代码行数:20,代码来源:

示例10: test_partial_sync_ignore

# 需要导入模块: from vdirsyncer.storage.memory import MemoryStorage [as 别名]
# 或者: from vdirsyncer.storage.memory.MemoryStorage import read_only [as 别名]
def test_partial_sync_ignore():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    item0 = Item('UID:0\nhehe')
    a.upload(item0)
    b.upload(item0)

    b.read_only = True

    item1 = Item('UID:1\nhaha')
    a.upload(item1)

    sync(a, b, status, partial_sync='ignore')
    sync(a, b, status, partial_sync='ignore')

    assert items(a) == {item0.raw, item1.raw}
    assert items(b) == {item0.raw}
开发者ID:,项目名称:,代码行数:21,代码来源:


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