本文整理汇总了Python中PyQt5.QtNetwork.QNetworkCacheMetaData.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkCacheMetaData.isValid方法的具体用法?Python QNetworkCacheMetaData.isValid怎么用?Python QNetworkCacheMetaData.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QNetworkCacheMetaData
的用法示例。
在下文中一共展示了QNetworkCacheMetaData.isValid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cache_full
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例2: preload_cache
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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)
示例3: test_cache_deactivated_private_browsing
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例4: test_cache_deactivated_update_metadata
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例5: test_cache_update_metadata
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例6: test_cache_metadata
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例7: test_cache_update_metadata
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例8: test_cache_metadata
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例9: test_cache_config_disable_private_browsing
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例10: test_cache_existing_metadata_file
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例11: test_cache_config_disable_private_browsing
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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
示例12: test_cache_existing_metadata_file
# 需要导入模块: from PyQt5.QtNetwork import QNetworkCacheMetaData [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkCacheMetaData import isValid [as 别名]
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