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


Python QtNetwork.QNetworkCacheMetaData类代码示例

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


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

示例1: preload_cache

def preload_cache(cache, url='http://www.example.com/', content=b'foobar'):
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    device = cache.prepare(metadata)
    assert device is not None
    device.write(content)
    cache.insert(device)
开发者ID:swalladge,项目名称:qutebrowser,代码行数:8,代码来源:test_cache.py

示例2: test_cache_deactivated_private_browsing

def test_cache_deactivated_private_browsing(config_stub, tmpdir):
    """Test if cache is deactivated in private-browsing mode."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": True}}
    disk_cache = cache.DiskCache(str(tmpdir))

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl("http://www.example.com/"))
    assert metadata.isValid()
    assert disk_cache.prepare(metadata) is None
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:9,代码来源:test_cache.py

示例3: test_cache_deactivated_update_metadata

def test_cache_deactivated_update_metadata(config_stub, tmpdir):
    """Test updating the meta data when cache is not activated."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": True}}
    url = "http://qutebrowser.org"
    disk_cache = cache.DiskCache(str(tmpdir))

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    assert disk_cache.updateMetaData(metadata) is None
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:10,代码来源:test_cache.py

示例4: test_cache_update_metadata

def test_cache_update_metadata(disk_cache):
    """Test updating the meta data for an existing cache entry."""
    url = 'http://qutebrowser.org'
    preload_cache(disk_cache, url, b'foo')
    assert disk_cache.cacheSize() > 0

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    disk_cache.updateMetaData(metadata)
    assert disk_cache.metaData(QUrl(url)) == metadata
开发者ID:swalladge,项目名称:qutebrowser,代码行数:11,代码来源:test_cache.py

示例5: test_cache_metadata

def test_cache_metadata(disk_cache):
    """Ensure that DiskCache.metaData() returns exactly what was inserted."""
    url = 'http://qutebrowser.org'
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    device = disk_cache.prepare(metadata)
    device.write(b'foobar')
    disk_cache.insert(device)

    assert disk_cache.metaData(QUrl(url)) == metadata
开发者ID:swalladge,项目名称:qutebrowser,代码行数:11,代码来源:test_cache.py

示例6: test_cache_update_metadata

def test_cache_update_metadata(config_stub, tmpdir):
    """Test updating the meta data for an existing cache entry."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": False}}
    url = "http://qutebrowser.org"
    disk_cache = cache.DiskCache(str(tmpdir))
    preload_cache(disk_cache, url, b"foo")
    assert disk_cache.cacheSize() > 0

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    disk_cache.updateMetaData(metadata)
    assert disk_cache.metaData(QUrl(url)) == metadata
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:13,代码来源:test_cache.py

示例7: test_cache_metadata

def test_cache_metadata(config_stub, tmpdir):
    """Ensure that DiskCache.metaData() returns exactly what was inserted."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": False}}
    url = "http://qutebrowser.org"
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()
    disk_cache = cache.DiskCache(str(tmpdir))
    device = disk_cache.prepare(metadata)
    device.write(b"foobar")
    disk_cache.insert(device)

    assert disk_cache.metaData(QUrl(url)) == metadata
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:13,代码来源:test_cache.py

示例8: test_cache_config_disable_private_browsing

def test_cache_config_disable_private_browsing(config_stub, tmpdir):
    """Change private-browsing config to False and emit signal."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": True}}
    url = "http://qutebrowser.org"
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()

    disk_cache = cache.DiskCache(str(tmpdir))
    assert disk_cache.prepare(metadata) is None

    config_stub.set("general", "private-browsing", False)
    content = b"cute"
    preload_cache(disk_cache, url, content)
    assert disk_cache.data(QUrl(url)).readAll() == content
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:15,代码来源:test_cache.py

示例9: test_cache_deactivated_insert_data

def test_cache_deactivated_insert_data(config_stub, tmpdir):
    """Insert data when cache is deactivated."""
    # First create QNetworkDiskCache just to get a valid QIODevice from it
    url = "http://qutebrowser.org"
    disk_cache = QNetworkDiskCache()
    disk_cache.setCacheDirectory(str(tmpdir))
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    device = disk_cache.prepare(metadata)
    assert device is not None

    # Now create a deactivated DiskCache and insert the valid device created
    # above (there probably is a better way to get a valid QIODevice...)
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": True}}

    deactivated_cache = cache.DiskCache(str(tmpdir))
    assert deactivated_cache.insert(device) is None
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:17,代码来源:test_cache.py

示例10: test_cache_existing_metadata_file

def test_cache_existing_metadata_file(tmpdir, disk_cache):
    """Test querying existing meta data file from activated cache."""
    url = 'http://qutebrowser.org'
    content = b'foobar'

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()

    device = disk_cache.prepare(metadata)
    assert device is not None
    device.write(content)
    disk_cache.insert(device)
    disk_cache.updateMetaData(metadata)

    files = list(tmpdir.visit(fil=lambda path: path.isfile()))
    assert len(files) == 1
    assert disk_cache.fileMetaData(str(files[0])) == metadata
开发者ID:swalladge,项目名称:qutebrowser,代码行数:18,代码来源:test_cache.py

示例11: test_cache_config_disable_private_browsing

def test_cache_config_disable_private_browsing(config_stub, tmpdir):
    """Change private-browsing config to False and emit signal."""
    config_stub.data = {
        'storage': {'cache-size': 1024},
        'general': {'private-browsing': True}
    }
    url = 'http://qutebrowser.org'
    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()

    disk_cache = cache.DiskCache(str(tmpdir))
    assert disk_cache.prepare(metadata) is None

    config_stub.set('general', 'private-browsing', False)
    content = b'cute'
    preload_cache(disk_cache, url, content)
    assert disk_cache.data(QUrl(url)).readAll() == content
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:18,代码来源:test_cache.py

示例12: test_cache_existing_metadata_file

def test_cache_existing_metadata_file(config_stub, tmpdir):
    """Test querying existing meta data file from activated cache."""
    config_stub.data = {"storage": {"cache-size": 1024}, "general": {"private-browsing": False}}
    url = "http://qutebrowser.org"
    content = b"foobar"

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    assert metadata.isValid()

    disk_cache = cache.DiskCache(str(tmpdir))
    device = disk_cache.prepare(metadata)
    assert device is not None
    device.write(content)
    disk_cache.insert(device)
    disk_cache.updateMetaData(metadata)

    files = list(tmpdir.visit(fil=lambda path: path.isfile()))
    assert len(files) == 1
    assert disk_cache.fileMetaData(str(files[0])) == metadata
开发者ID:AkDmOl,项目名称:qutebrowser,代码行数:20,代码来源:test_cache.py

示例13: test_cache_full

def test_cache_full(config_stub, tmpdir):
    """Do a sanity test involving everything."""
    config_stub.data = {
        'storage': {'cache-size': 1024},
        'general': {'private-browsing': False}
    }
    disk_cache = QNetworkDiskCache()
    disk_cache.setCacheDirectory(str(tmpdir))

    url = 'http://qutebrowser.org'
    content = b'cutebowser'
    preload_cache(disk_cache, url, content)
    url2 = 'https://qutebrowser.org'
    content2 = b'ohmycert'
    preload_cache(disk_cache, url2, content2)

    metadata = QNetworkCacheMetaData()
    metadata.setUrl(QUrl(url))
    soon = QDateTime.currentDateTime().addMonths(4)
    assert soon.isValid()
    metadata.setLastModified(soon)
    assert metadata.isValid()
    disk_cache.updateMetaData(metadata)
    disk_cache.remove(QUrl(url2))

    assert disk_cache.metaData(QUrl(url)).lastModified() == soon
    assert disk_cache.data(QUrl(url)).readAll() == content
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:27,代码来源:test_cache.py


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