本文整理汇总了Python中PyQt4.QtNetwork.QNetworkDiskCache.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkDiskCache.clear方法的具体用法?Python QNetworkDiskCache.clear怎么用?Python QNetworkDiskCache.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtNetwork.QNetworkDiskCache
的用法示例。
在下文中一共展示了QNetworkDiskCache.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ghost
# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import clear [as 别名]
#.........这里部分代码省略.........
:param timeout_message: The exception message on timeout.
"""
started_at = time.time()
while not condition():
if time.time() > (started_at + self.wait_timeout):
raise Exception(timeout_message)
time.sleep(0.01)
Ghost._app.processEvents()
if self.wait_callback is not None:
self.wait_callback()
def wait_for_alert(self):
"""Waits for main frame alert().
"""
self.wait_for(lambda: Ghost._alert is not None,
'User has not been alerted.')
msg = Ghost._alert
Ghost._alert = None
return msg, self._release_last_resources()
def wait_for_page_loaded(self):
"""Waits until page is loaded, assumed that a page as been requested.
"""
self.wait_for(lambda: self.loaded,
'Unable to load requested page')
resources = self._release_last_resources()
page = None
url = self.main_frame.url().toString()
for resource in resources:
if url == resource.url:
page = resource
return page, resources
def wait_for_selector(self, selector):
"""Waits until selector match an element on the frame.
:param selector: The selector to wait for.
"""
self.wait_for(lambda: self.exists(selector),
'Can\'t find element matching "%s"' % selector)
return True, self._release_last_resources()
def wait_for_text(self, text):
"""Waits until given text appear on main frame.
:param text: The text to wait for.
"""
self.wait_for(lambda: text in self.content,
'Can\'t find "%s" in current frame' % text)
return True, self._release_last_resources()
def _authenticate(self, mix, authenticator):
"""Called back on basic / proxy http auth.
:param mix: The QNetworkReply or QNetworkProxy object.
:param authenticator: The QAuthenticator object.
"""
if self._auth_attempt == 0:
username, password = self._auth
authenticator.setUser(username)
authenticator.setPassword(password)
self._auth_attempt += 1
def _page_loaded(self):
"""Called back when page is loaded.
"""
self.loaded = True
self.cache.clear()
def _page_load_started(self):
"""Called back when page load started.
"""
self.loaded = False
def _release_last_resources(self):
"""Releases last loaded resources.
:return: The released resources.
"""
last_resources = self.http_resources
self.http_resources = []
return last_resources
def _request_ended(self, reply):
"""Adds an HttpResource object to http_resources.
:param reply: The QNetworkReply object.
"""
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute):
self.http_resources.append(HttpResource(reply, self.cache))
def _unsupported_content(self, reply):
"""Adds an HttpResource object to http_resources with unsupported
content.
:param reply: The QNetworkReply object.
"""
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute):
self.http_resources.append(HttpResource(reply, self.cache,
reply.readAll()))
示例2: Ghost
# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import clear [as 别名]
#.........这里部分代码省略.........
:param confirm: A boolean to set confirmation.
:param callable: A callable that returns a boolean for confirmation.
"""
def __init__(self, confirm=True, callback=None):
self.confirm = confirm
self.callback = callback
def __enter__(self):
Ghost._confirm_expected = (self.confirm, self.callback)
def __exit__(self, type, value, traceback):
Ghost._confirm_expected = None
@property
def content(self, to_unicode=True):
"""Returns current frame HTML as a string.
:param to_unicode: Whether to convert html to unicode or not
"""
if to_unicode:
return unicode(self.main_frame.toHtml())
else:
return self.main_frame.toHtml()
@property
def cookies(self):
"""Returns all cookies."""
return self.cookie_jar.allCookies()
def delete_cookies(self):
"""Deletes all cookies."""
self.cookie_jar.setAllCookies([])
def clear_alert_message(self):
"""Clears the alert message"""
self._alert = None
@can_load_page
def evaluate(self, script):
"""Evaluates script in page frame.
:param script: The script to evaluate.
"""
return (self.main_frame.evaluateJavaScript("%s" % script),
self._release_last_resources())
def evaluate_js_file(self, path, encoding='utf-8'):
"""Evaluates javascript file at given path in current frame.
Raises native IOException in case of invalid file.
:param path: The path of the file.
:param encoding: The file's encoding.
"""
self.evaluate(codecs.open(path, encoding=encoding).read())
def exists(self, selector):
"""Checks if element exists for given selector.
:param string: The element selector.
"""
return not self.main_frame.findFirstElement(selector).isNull()
def exit(self):
"""Exits application and related."""
if self.display:
self.webview.close()