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


Python QNetworkRequest.setAttribute方法代码示例

本文整理汇总了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
开发者ID:greshem,项目名称:splash,代码行数:9,代码来源:network_manager.py

示例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)
开发者ID:usc-bbdl,项目名称:R01_HSC_cadaver_system,代码行数:30,代码来源:PluginRepositoryDialog.py

示例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
开发者ID:Micseb,项目名称:orange3,代码行数:57,代码来源:owimageviewer.py

示例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)
开发者ID:rugolotti,项目名称:PyTileMap,代码行数:22,代码来源:maptilesourcehttp.py

示例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
开发者ID:stav,项目名称:splash,代码行数:6,代码来源:network_manager.py

示例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
开发者ID:BlazZupan,项目名称:orange3,代码行数:71,代码来源:owimageviewer.py

示例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
开发者ID:microhello,项目名称:splash,代码行数:7,代码来源:network_manager.py

示例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)
开发者ID:se0siris,项目名称:bing-wallpaper-changer,代码行数:8,代码来源:mainwindow.py


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