本文整理汇总了Python中PyQt4.QtNetwork.QNetworkRequest.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkRequest.setAttribute方法的具体用法?Python QNetworkRequest.setAttribute怎么用?Python QNetworkRequest.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtNetwork.QNetworkRequest
的用法示例。
在下文中一共展示了QNetworkRequest.setAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _wrap_request
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def _wrap_request(self, request):
req = QNetworkRequest(request)
req_id = next(self._request_ids)
req.setAttribute(self._REQUEST_ID, req_id)
if hasattr(request, 'timeout'):
req.timeout = request.timeout
return req, req_id
示例2: __downloadFile
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def __downloadFile(self, url, filename, doneMethod = None):
"""
Private slot to download the given file.
@param url URL for the download (string or QString)
@param filename local name of the file (string or QString)
@param doneMethod method to be called when done
"""
self.__updateButton.setEnabled(False)
self.__downloadButton.setEnabled(False)
self.__downloadCancelButton.setEnabled(True)
self.statusLabel.setText(url)
self.__doneMethod = doneMethod
self.__downloadURL = url
self.__downloadFileName = QString(filename)
self.__downloadIODevice = QFile(self.__downloadFileName + ".tmp")
self.__downloadCancelled = False
request = QNetworkRequest(QUrl(url))
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.AlwaysNetwork)
reply = self.__networkManager.get(request)
self.connect(reply, SIGNAL("finished()"), self.__downloadFileDone)
self.connect(reply, SIGNAL("downloadProgress(qint64, qint64)"),
self.__downloadProgress)
self.__replies.append(reply)
示例3: get
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def get(self, url):
future = Future()
url = url = QUrl(url)
request = QNetworkRequest(url)
request.setRawHeader("User-Agent", "OWImageViewer/1.0")
request.setAttribute(
QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.PreferCache
)
# Future yielding a QNetworkReply when finished.
reply = self._netmanager.get(request)
future._reply = reply
n_redir = 0
def on_reply_ready(reply, future):
nonlocal n_redir
if reply.error() == QNetworkReply.OperationCanceledError:
# The network request itself was canceled
future.cancel()
return
if reply.error() != QNetworkReply.NoError:
# XXX Maybe convert the error into standard
# http and urllib exceptions.
future.set_exception(Exception(reply.errorString()))
return
# Handle a possible redirection
location = reply.attribute(
QNetworkRequest.RedirectionTargetAttribute)
if location is not None and n_redir < 1:
n_redir += 1
print(location)
location = reply.url().resolved(location)
# Retry the original request with a new url.
request = QNetworkRequest(reply.request())
request.setUrl(location)
newreply = self._netmanager.get(request)
future._reply = newreply
newreply.finished.connect(
partial(on_reply_ready, newreply, future))
return
reader = QImageReader(reply)
image = reader.read()
if image.isNull():
future.set_exception(Exception(reader.errorString()))
else:
future.set_result(image)
reply.finished.connect(partial(on_reply_ready, reply, future))
return future
示例4: loadTile
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def loadTile(self, x, y, zoom, url):
if self._manager is None:
self._manager = QNetworkAccessManager(parent=self)
self._manager.finished.connect(self.handleNetworkData)
self._cache = MapTileHTTPCache(maxSize=self._cacheSize, parent=self)
key = (x, y, zoom)
url = QUrl(url)
if url in self._cache:
# print('from cache')
data = self._cache[url]
self.tileLoaded.emit(x, y, zoom, data)
elif key in self._tileInDownload:
# Image is already in download... return
return
else:
request = QNetworkRequest(url=url)
request.setRawHeader('User-Agent', self._userAgent)
request.setAttribute(QNetworkRequest.User, key)
self._tileInDownload[key] = self._manager.get(request)
示例5: _wrapRequest
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def _wrapRequest(self, request):
request = QNetworkRequest(request)
request.setAttribute(self._REQUEST_ID, next(self._request_ids))
return request
示例6: get
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def get(self, url):
future = Future()
url = QUrl(url)
request = QNetworkRequest(url)
request.setRawHeader(b"User-Agent", b"OWImageViewer/1.0")
request.setAttribute(
QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.PreferCache
)
# Future yielding a QNetworkReply when finished.
reply = self._netmanager.get(request)
future._reply = reply
@future.add_done_callback
def abort_on_cancel(f):
# abort the network request on future.cancel()
if f.cancelled() and f._reply is not None:
f._reply.abort()
n_redir = 0
def on_reply_ready(reply, future):
nonlocal n_redir
# schedule deferred delete to ensure the reply is closed
# otherwise we will leak file/socket descriptors
reply.deleteLater()
future._reply = None
if reply.error() == QNetworkReply.OperationCanceledError:
# The network request was cancelled
reply.close()
future.cancel()
return
if reply.error() != QNetworkReply.NoError:
# XXX Maybe convert the error into standard
# http and urllib exceptions.
future.set_exception(Exception(reply.errorString()))
reply.close()
return
# Handle a possible redirection
location = reply.attribute(
QNetworkRequest.RedirectionTargetAttribute)
if location is not None and n_redir < 1:
n_redir += 1
location = reply.url().resolved(location)
# Retry the original request with a new url.
request = QNetworkRequest(reply.request())
request.setUrl(location)
newreply = self._netmanager.get(request)
future._reply = newreply
newreply.finished.connect(
partial(on_reply_ready, newreply, future))
reply.close()
return
reader = QImageReader(reply)
image = reader.read()
reply.close()
if image.isNull():
future.set_exception(Exception(reader.errorString()))
else:
future.set_result(image)
reply.finished.connect(partial(on_reply_ready, reply, future))
return future
示例7: _wrapRequest
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def _wrapRequest(self, request):
request = QNetworkRequest(request)
request.setAttribute(self._REQUEST_ID, self._next_id)
self._next_id += 1
return request
示例8: _get_url
# 需要导入模块: from PyQt4.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkRequest import setAttribute [as 别名]
def _get_url(self, url_string, request_type=None, request_metadata=None):
url = QUrl(url_string)
request = QNetworkRequest(QUrl(url))
if not request_type is None:
request.setAttribute(QNetworkRequest.User, (request_type, request_metadata))
self.manager.get(request)