本文整理汇总了Python中PyQt5.QtNetwork.QNetworkAccessManager.createRequest方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkAccessManager.createRequest方法的具体用法?Python QNetworkAccessManager.createRequest怎么用?Python QNetworkAccessManager.createRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QNetworkAccessManager
的用法示例。
在下文中一共展示了QNetworkAccessManager.createRequest方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
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
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
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: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
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)
示例4: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
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)
示例5: _create_request
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def _create_request(self, operation, request, data):
print(data.readAll())
reply = QNetworkAccessManager.createRequest(self.network_manager,
operation,
request,
data)
return reply
示例6: __pass
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def __pass(self, operation, request, data, info=None):
""" short for "ignore filter, just generate the request" """
if info is not None and info['notify']:
show_labeled(info['message'], info['qurl'], color=info['color'])
return QNetworkAccessManager.createRequest(
self, operation, request, data)
示例7: _create_request
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def _create_request(self, operation, request, data):
# print(data)
reply = QNetworkAccessManager.createRequest(self.conn,
operation,
request,
data)
self.conn.new_reply = reply
self.wv_reply = reply
return reply
示例8: __block
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def __block(self, message, info=None):
""" short for "ignore request; generate default empty request" """
if info is not None and info['notify']:
show_labeled(info['message'], info['qurl'],
color=info['color'], detail=info['detail'])
return QNetworkAccessManager.createRequest(
self,
QNetworkAccessManager.GetOperation,
QNetworkRequest(QUrl(message)),
None)
示例9: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def createRequest(self, operation, request, device):
path = o = request.url().toString().split('?')[0]
if path.startswith('app://'):
if path == 'app:///':
path = self._uri_app_base + 'app.html'
else:
path = path.replace('app://', self._uri_app_base)
logger.debug('Loading app resource: {0} ({1})'.format(o, path))
# variable substitution
path = path.replace('$backend', 'qt5')
logger.debug('Loading app resource: {0} ({1})'.format(o, path))
elif path.startswith('lens://'):
path = path.replace('lens://', self._uri_lens_base)
# make lens.css backend specific
path = path.replace('lens.css', 'lens-qt5.css')
logger.debug('Loading lens resource: {0} ({1})'.format(o, path))
elif path.startswith('tmp://'):
path = path.replace('tmp://', self._uri_lens_base)
logger.debug('Loading tmp resource: {0} ({1})'.format(o, path))
elif path.startswith('user://'):
path = path.replace('user://', self._uri_lens_base)
logger.debug('Loading tmp resource: {0} ({1})'.format(o, path))
elif path.startswith('file://'):
path = path.replace('file://', '')
logger.debug('Loading resource: {0} ({1})'.format(o, path))
if not os.path.exists(path):
raise Exception('Resource path not found: {0}'.format(path))
request.setUrl(QUrl(QString('file://' + path)))
return QNetworkAccessManager.createRequest(self, operation, request, device)
示例10: __init__
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def __init__(self, parent):
super().__init__(parent)
self.set_url('http://google.ru')
conn = QNetworkAccessManager()
self.conn = conn
self.r = QNetworkRequest()
self.r.attribute(QNetworkRequest.CookieSaveControlAttribute, QVariant(True))
# self.r.setHeader(QNetworkRequest.ContentTypeHeader, "application/x-www-form-urlencoded")
# self.r.setRawHeader("Referer", "http://www.facebook.com/")
# self.r.setRawHeader("Host", "www.facebook.com")
self.cj = QNetworkCookieJar()
conn.setCookieJar(self.cj)
conn.createRequest = self._create_request
self.wv = WebView()
self.wv.show()
self.wv.page().setNetworkAccessManager(conn)
# self.wv.auth()
self.loop = QEventLoop()
pass
示例11: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [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)
"""
if self.primaryManager is not None:
pageRequest = QNetworkRequest(request)
if self.__webPage is not None:
self.__webPage.populateNetworkRequest(pageRequest)
return self.primaryManager.createRequest(
op, pageRequest, outgoingData)
else:
return QNetworkAccessManager.createRequest(
self, op, request, outgoingData)
示例12: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [as 别名]
def createRequest(self, op, request, device=None):
url = request.url()
ctype = str(request.header(QNetworkRequest.ContentTypeHeader))
urlString = url.toString()
lurlString = urlString.lower()
x = filtering.adblock_filter.match(urlString)
y = url.authority() in filtering.host_rules if settings.setting_to_bool("content/HostFilterEnabled") and url.authority() != "" else False
z = (lurlString.endswith(".swf") or "flash" in ctype) and not settings.setting_to_bool("content/FlashEnabled")
aa = (lurlString.endswith(".gif") or "image/gif" in ctype) and not settings.setting_to_bool("content/GIFsEnabled")
if x != None or y or z or aa:
return QNetworkAccessManager.createRequest(self, self.GetOperation, QNetworkRequest(QUrl(random.choice(("http://www.randomkittengenerator.com/images/cats/rotator.php", "http://thecatapi.com/api/images/get?format=src&type=png&size=small")) if settings.setting_to_bool("content/KittensEnabled") else "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==")))
if urlString in tuple(replacement_table.keys()):
return QNetworkAccessManager.createRequest(self, op, QNetworkRequest(QUrl(replacement_table[urlString])), device)
if url.scheme() == "file" and os.path.isdir(os.path.abspath(url.path())):
try:
html = directoryView % {"title": urlString, "heading": url.path(), "links": "".join(["<a href=\"%s\">%s</a><br/>" % (QUrl.fromUserInput(os.path.join(urlString, path)).toString(), path,) for path in [".."] + sorted(os.listdir(os.path.abspath(url.path())))])}
except:
html = directoryView % {"title": urlString, "heading": url.path(), "links": tr("The contents of this directory could not be loaded.")}
return NetworkReply(self, url, self.GetOperation, html)
if url.scheme() == "nimbus-extension":
request.setUrl(QUrl("http://127.0.0.1:8133/" + stringfunctions.chop(url.toString(QUrl.RemoveScheme), "//")))
return QNetworkAccessManager.createRequest(self, op, request, device)
if url.scheme() == "nimbus":
request.setUrl(QUrl("file://%s/" % (paths.app_folder,) + stringfunctions.chop(url.toString(QUrl.RemoveScheme), "//")))
return self.createRequest(op, request, device)
if url.scheme() == "nimbus-settings":
request.setUrl(QUrl("file://%s/" % (settings.settings_folder,) + stringfunctions.chop(url.toString(QUrl.RemoveScheme), "//")))
return self.createRequest(op, request, device)
if url.scheme() == "apt":
os.system("xterm -e \"sudo apt-get install %s\" &" % (stringfunctions.chop(url.toString(QUrl.RemoveScheme), "//").split("&")[0],))
return QNetworkAccessManager.createRequest(self, self.GetOperation, QNetworkRequest(QUrl("")))
if url.scheme() == "mailto":
QDesktopServices.openUrl(url)
return QNetworkAccessManager.createRequest(self, self.GetOperation, QNetworkRequest(QUrl("")))
else:
return QNetworkAccessManager.createRequest(self, op, request, device)
示例13: createRequest
# 需要导入模块: from PyQt5.QtNetwork import QNetworkAccessManager [as 别名]
# 或者: from PyQt5.QtNetwork.QNetworkAccessManager import createRequest [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