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


Python QNetworkRequest.setAttribute方法代码示例

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


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

示例1: _wrap_request

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.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:Cloverseer,项目名称:splash,代码行数:9,代码来源:network_manager.py

示例2: on_searchPushButton_clicked

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setAttribute [as 别名]
 def on_searchPushButton_clicked(self, checked):
     if self.categoryID != '' and self.categoryID != '-1':
         merchandising = Merchandising(warnings = False)
         response = merchandising.execute(
             'getMostWatchedItems',
             {
                 'categoryId': self.categoryID,
                 'maxResults': self.ui.spinBox.value()
             }
         )
         reply = response.reply
         itemRecommendations = reply.itemRecommendations.item
         row = self.ui.tableWidget.rowCount()
         for item in itemRecommendations:
             self.ui.tableWidget.insertRow(row)
             imageUrl = 'http://thumbs3.ebaystatic.com/pict/%s4040.jpg' % item.itemId
             request = QNetworkRequest(QUrl(imageUrl))
             request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.PreferCache)
             reply = self.manager.get(request)
             self.replyMap[reply] = row
             viewItemURL = QLabel()
             viewItemURL.setOpenExternalLinks(True)
             #viewItemURL.setTextInteractionFlags(Qt.TextBrowserInteraction)
             title = '<a href="%s">%s</a>' % (item.viewItemURL, item.title)
             viewItemURL.setText(title)
             self.ui.tableWidget.setCellWidget(row, 1, viewItemURL)
             self.ui.tableWidget.setItem(row, 2, QTableWidgetItem(item.primaryCategoryName))
             self.ui.tableWidget.setItem(row, 3, QTableWidgetItem(item.buyItNowPrice.value))
             self.ui.tableWidget.setItem(row, 4, QTableWidgetItem(item.watchCount))
             row += 1
开发者ID:xlongfeng,项目名称:oceanix,代码行数:32,代码来源:mostwatcheditems.py

示例3: checkPluginUpdatesAvailable

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setAttribute [as 别名]
 def checkPluginUpdatesAvailable(self):
     """
     Public method to check the availability of updates of plug-ins.
     """
     period = Preferences.getPluginManager("UpdatesCheckInterval")
     if period == 0:
         return
     elif period in [1, 2, 3]:
         lastModified = QFileInfo(self.pluginRepositoryFile).lastModified()
         if lastModified.isValid() and lastModified.date().isValid():
             lastModifiedDate = lastModified.date()
             now = QDate.currentDate()
             if period == 1 and lastModifiedDate.day() == now.day():
                 # daily
                 return
             elif period == 2 and lastModifiedDate.daysTo(now) < 7:
                 # weekly
                 return
             elif period == 3 and \
                 (lastModifiedDate.daysTo(now) <
                  lastModifiedDate.daysInMonth()):
                 # monthly
                 return
     
     self.__updateAvailable = False
     
     request = QNetworkRequest(
         QUrl(Preferences.getUI("PluginRepositoryUrl6")))
     request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
                          QNetworkRequest.AlwaysNetwork)
     reply = self.__networkManager.get(request)
     reply.finished.connect(self.__downloadRepositoryFileDone)
     self.__replies.append(reply)
开发者ID:Darriall,项目名称:eric,代码行数:35,代码来源:PluginManager.py

示例4: __downloadFile

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.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)
     @param filename local name of the file (string)
     @param doneMethod method to be called when done
     """
     self.__updateButton.setEnabled(False)
     self.__downloadButton.setEnabled(False)
     self.__downloadInstallButton.setEnabled(False)
     self.__downloadCancelButton.setEnabled(True)
     
     self.statusLabel.setText(url)
     
     self.__doneMethod = doneMethod
     self.__downloadURL = url
     self.__downloadFileName = 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)
     reply.finished.connect(self.__downloadFileDone)
     reply.downloadProgress.connect(self.__downloadProgress)
     self.__replies.append(reply)
开发者ID:testmana2,项目名称:test,代码行数:30,代码来源:PluginRepositoryDialog.py

示例5: _wrap_request

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.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)
     for attr in ['timeout', 'track_response_body']:
         if hasattr(request, attr):
             setattr(req, attr, getattr(request, attr))
     return req, req_id
开发者ID:xiaotianlis,项目名称:splash,代码行数:10,代码来源:network_manager.py

示例6: download

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setAttribute [as 别名]
    def download(self):
        grab = None
        for x in range(self._tilesRect.width()):
            for y in range(self._tilesRect.height()):
                tp = Point(self._tilesRect.topLeft() + QPoint(x, y))
                if tp not in self._tilePixmaps:
                    grab = QPoint(tp)
                    break

        if grab is None:
            self._url = QUrl()
            return

        path = 'http://tile.openstreetmap.org/%d/%d/%d.png' % (self.zoom, grab.x(), grab.y())
        self._url = QUrl(path)
        request = QNetworkRequest()
        request.setUrl(self._url)
        request.setRawHeader(b'User-Agent', b'Nokia (PyQt) Graphics Dojo 1.0')
        request.setAttribute(QNetworkRequest.User, grab)
        self._manager.get(request)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:22,代码来源:lightmaps.py

示例7: __downloadFile

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.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)
     @param filename local name of the file (string)
     @param doneMethod method to be called when done
     """
     if self.__networkConfigurationManager.isOnline():
         self.__updateButton.setEnabled(False)
         self.__downloadButton.setEnabled(False)
         self.__downloadInstallButton.setEnabled(False)
         self.__downloadCancelButton.setEnabled(True)
         
         self.statusLabel.setText(url)
         
         self.__doneMethod = doneMethod
         self.__downloadURL = url
         self.__downloadFileName = 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)
         reply.finished.connect(self.__downloadFileDone)
         reply.downloadProgress.connect(self.__downloadProgress)
         self.__replies.append(reply)
     else:
         E5MessageBox.warning(
             self,
             self.tr("Error downloading file"),
             self.tr(
                 """<p>Could not download the requested file"""
                 """ from {0}.</p><p>Error: {1}</p>"""
             ).format(url, self.tr("Computer is offline.")))
开发者ID:pycom,项目名称:EricShort,代码行数:39,代码来源:PluginRepositoryDialog.py

示例8: _wrap_request

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.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 self.disable_browser_caches:
            # disables the network cache
            # see http://doc.qt.io/qt-5/qnetworkrequest.html#CacheLoadControl-enum
            req.setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork)
            req.setAttribute(QNetworkRequest.CacheSaveControlAttribute, False)

        for attr in ['timeout', 'track_request_body', 'track_response_body']:
            if hasattr(request, attr):
                setattr(req, attr, getattr(request, attr))
        return req, req_id
开发者ID:scrapinghub,项目名称:splash,代码行数:17,代码来源:network_manager.py

示例9: Toolbox

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setAttribute [as 别名]

#.........这里部分代码省略.........
    def isInstalled(self, package_id: str) -> bool:
        return self._package_manager.isPackageInstalled(package_id)

    @pyqtSlot(str, result = bool)
    def isEnabled(self, package_id: str) -> bool:
        if package_id in self._plugin_registry.getActivePlugins():
            return True
        return False

    def loadingComplete(self) -> bool:
        populated = 0
        for list in self._metadata.items():
            if len(list) > 0:
                populated += 1
        if populated == len(self._metadata.items()):
            return True
        return False

    # Make API Calls
    # --------------------------------------------------------------------------
    def _makeRequestByType(self, type: str) -> None:
        Logger.log("i", "Toolbox: Requesting %s metadata from server.", type)
        request = QNetworkRequest(self._request_urls[type])
        request.setRawHeader(*self._request_header)
        self._network_manager.get(request)

    @pyqtSlot(str)
    def startDownload(self, url: str) -> None:
        Logger.log("i", "Toolbox: Attempting to download & install package from %s.", url)
        url = QUrl(url)
        self._download_request = QNetworkRequest(url)
        if hasattr(QNetworkRequest, "FollowRedirectsAttribute"):
            # Patch for Qt 5.6-5.8
            self._download_request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
        if hasattr(QNetworkRequest, "RedirectPolicyAttribute"):
            # Patch for Qt 5.9+
            self._download_request.setAttribute(QNetworkRequest.RedirectPolicyAttribute, True)
        self._download_request.setRawHeader(*self._request_header)
        self._download_reply = self._network_manager.get(self._download_request)
        self.setDownloadProgress(0)
        self.setIsDownloading(True)
        self._download_reply.downloadProgress.connect(self._onDownloadProgress)

    @pyqtSlot()
    def cancelDownload(self) -> None:
        Logger.log("i", "Toolbox: User cancelled the download of a plugin.")
        self.resetDownload()

    def resetDownload(self) -> None:
        if self._download_reply:
            self._download_reply.abort()
            self._download_reply.downloadProgress.disconnect(self._onDownloadProgress)
        self._download_reply = None
        self._download_request = None
        self.setDownloadProgress(0)
        self.setIsDownloading(False)

    # Handlers for Network Events
    # --------------------------------------------------------------------------
    def _onNetworkAccessibleChanged(self, accessible: int) -> None:
        if accessible == 0:
            self.resetDownload()

    def _onRequestFinished(self, reply: QNetworkReply) -> None:

        if reply.error() == QNetworkReply.TimeoutError:
开发者ID:CPS-3,项目名称:Cura,代码行数:70,代码来源:Toolbox.py

示例10: createRequest

# 需要导入模块: from PyQt5.QtNetwork import QNetworkRequest [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkRequest import setAttribute [as 别名]
 def createRequest(self, op, request, outgoingData=None):
     """
     Public method to create a request.
     
     @param op the operation to be performed
         (QNetworkAccessManager.Operation)
     @param request reference to the request object (QNetworkRequest)
     @param outgoingData reference to an IODevice containing data to be sent
         (QIODevice)
     @return reference to the created reply object (QNetworkReply)
     """
     scheme = request.url().scheme()
     if scheme == "https" and \
             (not SSL_AVAILABLE or not QSslSocket.supportsSsl()):
         from .NetworkProtocolUnknownErrorReply import \
             NetworkProtocolUnknownErrorReply
         return NetworkProtocolUnknownErrorReply(scheme, self)
     
     import Helpviewer.HelpWindow
     
     if op == QNetworkAccessManager.PostOperation and \
             outgoingData is not None:
         outgoingDataByteArray = outgoingData.peek(1024 * 1024)
         Helpviewer.HelpWindow.HelpWindow.passwordManager().post(
             request, outgoingDataByteArray)
     
     reply = None
     if scheme in self.__schemeHandlers:
         reply = self.__schemeHandlers[scheme]\
                     .createRequest(op, request, outgoingData)
     if reply is not None:
         return reply
     
     # give GreaseMonkey the chance to create a request
     reply = Helpviewer.HelpWindow.HelpWindow.greaseMonkeyManager()\
         .createRequest(op, request, outgoingData)
     if reply is not None:
         return reply
     
     req = QNetworkRequest(request)
     if req.rawHeader(b"X-Eric6-UserLoadAction") == QByteArray(b"1"):
         req.setRawHeader(b"X-Eric6-UserLoadAction", QByteArray())
         req.setAttribute(QNetworkRequest.User + 200, "")
     else:
         req.setAttribute(
             QNetworkRequest.User + 200, req.rawHeader(b"Referer"))
     
     if hasattr(QNetworkRequest, 'HttpPipeliningAllowedAttribute'):
         req.setAttribute(
             QNetworkRequest.HttpPipeliningAllowedAttribute, True)
     if not self.__acceptLanguage.isEmpty():
         req.setRawHeader(b"Accept-Language", self.__acceptLanguage)
     
     # AdBlock code
     if op == QNetworkAccessManager.GetOperation:
         if self.__adblockNetwork is None:
             self.__adblockNetwork = \
                 Helpviewer.HelpWindow.HelpWindow.adBlockManager().network()
         reply = self.__adblockNetwork.block(req)
         if reply is not None:
             reply.setParent(self)
             return reply
     
     # set cache policy
     if op == QNetworkAccessManager.GetOperation:
         urlHost = req.url().host()
         for host in Preferences.getHelp("NoCacheHosts"):
             if host in urlHost:
                 req.setAttribute(
                     QNetworkRequest.CacheLoadControlAttribute,
                     QNetworkRequest.AlwaysNetwork)
                 break
         else:
             req.setAttribute(
                 QNetworkRequest.CacheLoadControlAttribute,
                 Preferences.getHelp("CachePolicy"))
     else:
         req.setAttribute(
             QNetworkRequest.CacheLoadControlAttribute,
             QNetworkRequest.AlwaysNetwork)
     
     # Do Not Track feature
     if self.__doNotTrack:
         req.setRawHeader(b"DNT", b"1")
         req.setRawHeader(b"X-Do-Not-Track", b"1")
     
     # Send referer header?
     if not self.__sendReferer and \
        req.url().host() not in Preferences.getHelp("SendRefererWhitelist"):
         req.setRawHeader(b"Referer", b"")
     
     reply = QNetworkAccessManager.createRequest(
         self, op, req, outgoingData)
     self.requestCreated.emit(op, req, reply)
     
     return reply
开发者ID:testmana2,项目名称:test,代码行数:98,代码来源:NetworkAccessManager.py


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