本文整理汇总了Python中PyQt5.QtNetwork.QNetworkAccessManager类的典型用法代码示例。如果您正苦于以下问题:Python QNetworkAccessManager类的具体用法?Python QNetworkAccessManager怎么用?Python QNetworkAccessManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkAccessManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createRequest
def createRequest(self, op, request, device = None ):
global block_list,TMP_DIR
try:
urlLnk = (request.url()).toString()
path = (request.url().toString())
except UnicodeEncodeError:
path = (request.url().path())
if '9anime.to' in path and 'episode/info?' in path:
f = open(os.path.join(TMP_DIR,'lnk.txt'),'w')
f.write(path)
f.close()
lower_path = path.lower()
#block_list = []
block_list = ["doubleclick.net" ,"ads",'.gif','.css','facebook','.aspx', r"||youtube-nocookie.com/gen_204?", r"youtube.com###watch-branded-actions", "imagemapurl","b.scorecardresearch.com","rightstuff.com","scarywater.net","popup.js","banner.htm","_tribalfusion","||n4403ad.doubleclick.net^$third-party",".googlesyndication.com","graphics.js","fonts.googleapis.com/css","s0.2mdn.net","server.cpmstar.com","||banzai/banner.$subdocument","@@||anime-source.com^$document","/pagead2.","frugal.gif","jriver_banner.png","show_ads.js",'##a[href^="http://billing.frugalusenet.com/"]',"http://jriver.com/video.html","||animenewsnetwork.com^*.aframe?","||contextweb.com^$third-party",".gutter",".iab",'http://www.animenewsnetwork.com/assets/[^"]*.jpg','revcontent']
block = False
for l in block_list:
if l in lower_path:
block = True
break
if block:
return QNetworkAccessManager.createRequest(self, QNetworkAccessManager.GetOperation, QtNetwork.QNetworkRequest(QtCore.QUrl()))
else:
if 'itag=' in urlLnk and 'redirector' not in urlLnk:
print('*********')
#f = open(os.path.join(TMP_DIR,'lnk.txt'),'w')
#f.write(urlLnk)
#f.close()
return QNetworkAccessManager.createRequest(self, op, request, device)
else:
return QNetworkAccessManager.createRequest(self, op, request, device)
示例2: createRequest
def createRequest(self, op, request, device = None ):
global block_list
try:
path = (request.url().toString())
except UnicodeEncodeError:
path = (request.url().path())
lower_path = path.lower()
block_list = [
"doubleclick.net" ,"adnxs", r"||youtube-nocookie.com/gen_204?",
r"youtube.com###watch-branded-actions", "imagemapurl",
"b.scorecardresearch.com","rightstuff.com","scarywater.net","popup.js",
"banner.htm","_tribalfusion","||n4403ad.doubleclick.net^$third-party",
".googlesyndication.com","graphics.js","fonts.googleapis.com/css",
"s0.2mdn.net","server.cpmstar.com","||banzai/banner.$subdocument",
"@@||anime-source.com^$document","/pagead2.","frugal.gif",
"jriver_banner.png","show_ads.js",
'##a[href^="http://billing.frugalusenet.com/"]',
"http://jriver.com/video.html","||animenewsnetwork.com^*.aframe?",
"||contextweb.com^$third-party",".gutter",".iab",
'http://www.animenewsnetwork.com/assets/[^"]*.jpg','revcontent'
]
block = False
for l in block_list:
if l in lower_path:
block = True
break
if block:
return QNetworkAccessManager.createRequest(self, QNetworkAccessManager.GetOperation, QtNetwork.QNetworkRequest(QtCore.QUrl()))
else:
return QNetworkAccessManager.createRequest(self, op, request, device)
示例3: qnam
def qnam(qapp):
"""Session-wide QNetworkAccessManager."""
from PyQt5.QtNetwork import QNetworkAccessManager
nam = QNetworkAccessManager()
nam.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
return nam
示例4: __init__
def __init__(self):
QNetworkAccessManager.__init__(self)
url = QUrl("http://localhost:8085/events")
req = QNetworkRequest(url)
self.reply = self.get(req)
self.reply.readyRead.connect(self.on_read_data)
self.reply.finished.connect(self.on_finished)
self.reply.error.connect(self.on_error)
示例5: __init__
def __init__(self):
QNetworkAccessManager.__init__(self)
self.dispatch_map = {
'GET': self.perform_get,
'PATCH': self.perform_patch,
'PUT': self.perform_put,
'DELETE': self.perform_delete,
'POST': self.perform_post
}
self.protocol = DEFAULT_API_PROTOCOL
self.host = DEFAULT_API_HOST
self.port = DEFAULT_API_PORT
示例6: __init__
def __init__(self, api_port):
QNetworkAccessManager.__init__(self)
url = QUrl("http://localhost:%d/events" % api_port)
self.request = QNetworkRequest(url)
self.failed_attempts = 0
self.connect_timer = QTimer()
self.current_event_string = ""
self.tribler_version = "Unknown"
self.reply = None
self.emitted_tribler_started = False # We should only emit tribler_started once
self.shutting_down = False
self._logger = logging.getLogger('TriblerGUI')
示例7: __init__
def __init__(self, **kwargs):
super(Ycm, self).__init__(**kwargs)
self.addr = None
"""Address of the ycmd server."""
self.port = 0
"""TCP port of the ycmd server."""
self._ready = False
self.secret = ''
self.config = {}
self.proc = QProcess()
self.proc.started.connect(self.procStarted)
self.proc.errorOccurred.connect(self.procError)
self.proc.finished.connect(self.procFinished)
self.pingTimer = QTimer(self)
self.pingTimer.timeout.connect(self.ping)
self.network = QNetworkAccessManager()
qApp().aboutToQuit.connect(self.stop)
self.addCategory('ycm_control')
示例8: __init__
def __init__(self, parent=None):
"""Init class."""
super(Downloader, self).__init__(parent)
self.setWindowTitle(__doc__)
if not os.path.isfile(__file__) or not __source__:
return
if not os.access(__file__, os.W_OK):
error_msg = ("Destination file permission denied (not Writable)! "
"Try again to Update but as root or administrator.")
log.critical(error_msg)
QMessageBox.warning(self, __doc__.title(), error_msg)
return
self._time, self._date = time.time(), datetime.now().isoformat()[:-7]
self._url, self._dst = __source__, __file__
log.debug("Downloading from {} to {}.".format(self._url, self._dst))
if not self._url.lower().startswith("https:"):
log.warning("Unsecure Download over plain text without SSL.")
self.template = """<h3>Downloading</h3><hr><table>
<tr><td><b>From:</b></td> <td>{}</td>
<tr><td><b>To: </b></td> <td>{}</td> <tr>
<tr><td><b>Started:</b></td> <td>{}</td>
<tr><td><b>Actual:</b></td> <td>{}</td> <tr>
<tr><td><b>Elapsed:</b></td> <td>{}</td>
<tr><td><b>Remaining:</b></td> <td>{}</td> <tr>
<tr><td><b>Received:</b></td> <td>{} MegaBytes</td>
<tr><td><b>Total:</b></td> <td>{} MegaBytes</td> <tr>
<tr><td><b>Speed:</b></td> <td>{}</td>
<tr><td><b>Percent:</b></td> <td>{}%</td></table><hr>"""
self.manager = QNetworkAccessManager(self)
self.manager.finished.connect(self.save_downloaded_data)
self.manager.sslErrors.connect(self.download_failed)
self.progreso = self.manager.get(QNetworkRequest(QUrl(self._url)))
self.progreso.downloadProgress.connect(self.update_download_progress)
self.show()
self.exec_()
示例9: createRequest
def createRequest(self, operation, request, device):
path = o = request.url().toString()
if path.startswith('app://') or path.startswith('lens://'):
if path == 'app:///':
path = 'file://' + self._uri_app_base + 'app.html'
logger.debug('Loading app resource: {0} ({1})'.format(o, path))
elif path.startswith('app://'):
path = path.replace('app://', 'file://' + self._uri_app_base)
logger.debug('Loading app resource: {0} ({1})'.format(o, path))
# variable substitution
path = path.replace('$backend', 'qt5')
elif path.startswith('lens://'):
path = path.replace('lens://', 'file://' + self._uri_lens_base)
logger.debug('Loading lens resource: {0} ({1})'.format(o, path))
# make lens.css backend specific
path = path.replace('lens.css', 'lens-qt5.css')
request.setUrl(QUrl(QString(path)))
return QNetworkAccessManager.createRequest(self, operation, request, device)
示例10: createRequest
def createRequest(self, operation, request, data):
try:
requestFunc = self._dispatcher[request.url().scheme()]
except KeyError:
self.addHeadersToRequest(request)
return QNetworkAccessManager.createRequest(self, operation, request, data)
return requestFunc(self, operation, request, data)
示例11: __init__
def __init__(self, parent=None):
super(WeatherController, self).__init__(parent)
self._dataReceived = False
self._forecastDataReceived = False
self._weather_data = CurrentWeatherData()
self._weather_forecast_data = []
self._data_model = ForecastDataModel()
self._network_manager = QNetworkAccessManager(self)
self._timer = QTimer(self)
self._timer.timeout.connect(self.update_weather)
self._current_weather = None
self._forecast_weather = None
self._api_key = ''
self._last_update_time = ''
self._requested_location = 'Dachau'
try:
with open('resources/api.txt') as f:
self._api_key = f.readline()
except FileNotFoundError:
print('The api key is not found')
示例12: _create_request
def _create_request(self, operation, request, data):
print(data.readAll())
reply = QNetworkAccessManager.createRequest(self.network_manager,
operation,
request,
data)
return reply
示例13: __init__
def __init__(self, parent=None):
"""Init class."""
super(Downloader, self).__init__(parent)
self.setWindowTitle(__doc__)
if not os.path.isfile(__file__) or not __source__:
self.close()
self._time, self._date = time.time(), datetime.now().isoformat()[:-7]
self._url, self._dst = __source__, __file__
log.debug("Downloading from {} to {}.".format(self._url, self._dst))
if not self._url.lower().startswith("https:"):
log.warning("Unsecure Download over plain text without SSL.")
self.template = """<h3>Downloading</h3><hr><table>
<tr><td><b>From:</b></td> <td>{}</td>
<tr><td><b>To: </b></td> <td>{}</td> <tr>
<tr><td><b>Started:</b></td> <td>{}</td>
<tr><td><b>Actual:</b></td> <td>{}</td> <tr>
<tr><td><b>Elapsed:</b></td> <td>{}</td>
<tr><td><b>Remaining:</b></td> <td>{}</td> <tr>
<tr><td><b>Received:</b></td> <td>{} MegaBytes</td>
<tr><td><b>Total:</b></td> <td>{} MegaBytes</td> <tr>
<tr><td><b>Speed:</b></td> <td>{}</td>
<tr><td><b>Percent:</b></td> <td>{}%</td></table><hr>"""
self.manager = QNetworkAccessManager(self)
self.manager.finished.connect(self.save_downloaded_data)
self.manager.sslErrors.connect(self.download_failed)
self.progreso = self.manager.get(QNetworkRequest(QUrl(self._url)))
self.progreso.downloadProgress.connect(self.update_download_progress)
self.show()
self.exec_()
示例14: __init__
def __init__(self):
super().__init__()
self._zero_conf = None
self._browser = None
self._printers = {}
self._api_version = "1"
self._api_prefix = "/api/v" + self._api_version + "/"
self._network_manager = QNetworkAccessManager()
self._network_manager.finished.connect(self._onNetworkRequestFinished)
# List of old printer names. This is used to ensure that a refresh of zeroconf does not needlessly forces
# authentication requests.
self._old_printers = []
# Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
self.addPrinterSignal.connect(self.addPrinter)
self.removePrinterSignal.connect(self.removePrinter)
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
# Get list of manual printers from preferences
self._preferences = Preferences.getInstance()
self._preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
self._manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
示例15: browsePackages
def browsePackages(self) -> None:
# Create the network manager:
# This was formerly its own function but really had no reason to be as
# it was never called more than once ever.
if self._network_manager is not None:
self._network_manager.finished.disconnect(self._onRequestFinished)
self._network_manager.networkAccessibleChanged.disconnect(self._onNetworkAccessibleChanged)
self._network_manager = QNetworkAccessManager()
self._network_manager.finished.connect(self._onRequestFinished)
self._network_manager.networkAccessibleChanged.connect(self._onNetworkAccessibleChanged)
# Make remote requests:
self._makeRequestByType("packages")
self._makeRequestByType("authors")
# Gather installed packages:
self._updateInstalledModels()
if not self._dialog:
self._dialog = self._createDialog("Toolbox.qml")
if not self._dialog:
Logger.log("e", "Unexpected error trying to create the 'Marketplace' dialog.")
return
self._dialog.show()
# Apply enabled/disabled state to installed plugins
self.enabledChanged.emit()