本文整理汇总了Python中PyQt4.QtNetwork.QNetworkProxy.setApplicationProxy方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkProxy.setApplicationProxy方法的具体用法?Python QNetworkProxy.setApplicationProxy怎么用?Python QNetworkProxy.setApplicationProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtNetwork.QNetworkProxy
的用法示例。
在下文中一共展示了QNetworkProxy.setApplicationProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setProxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def setProxy(self,arg):
item = arg.split(':')
if len(item) == 2:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy,item[0],int(item[1]))
QNetworkProxy.setApplicationProxy(proxy)
else:
QNetworkProxyFactory.setUseSystemConfiguration(True)
示例2: setUp
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def setUp(self):
if len(argv) == 2:
site = argv[1]
else:
site = None
options = extract_options(site)
if options['cookie_file'] is not None:
options['cookie_file'] = (
expanduser("~/.eilat/cookies/") + options['cookie_file'])
# Proxy
if options['use_proxy']:
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName('localhost')
proxy.setPort(3128)
QNetworkProxy.setApplicationProxy(proxy)
self.mainwin = MainWin(clipboard=CLIPBOARD, options=options, parent=None)
if site:
self.mainwin.add_tab(site)
else:
self.mainwin.add_tab()
self.mainwin.show()
示例3: set_proxy_settings
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def set_proxy_settings():
http = backend.pm.Iface().getConfig().get("general", "http_proxy")
if http and not http == "None":
items = parse_proxy(http)
QNetworkProxy.setApplicationProxy(
QNetworkProxy(QNetworkProxy.HttpProxy,
items['host'], int(items['port']),
items['user'] or '', items['pass'] or ''))
示例4: configure_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def configure_proxy(self):
proxy = urlparse(os.environ.get('http_proxy') or os.environ.get('HTTP_PROXY'))
if proxy.hostname is not None and proxy.port is not None:
q_network_proxy = QNetworkProxy(QNetworkProxy.HttpProxy, proxy.hostname, proxy.port)
if proxy.username is not None:
q_network_proxy.setUser(proxy.username)
if proxy.password is not None:
q_network_proxy.setPassword(proxy.password)
QNetworkProxy.setApplicationProxy(q_network_proxy)
示例5: check_proxy_enabled
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def check_proxy_enabled(host, port):
"""Check if the proxy is enabled."""
port = int(port)
if sys.platform.startswith("linux"):
settings = gsettings.get_proxy_settings()
enabled = len(settings) > 0
if enabled:
proxy = build_proxy(settings)
QNetworkProxy.setApplicationProxy(proxy)
else:
logger.info("Proxy is disabled.")
return enabled
else:
QNetworkProxyFactory.setUseSystemConfiguration(True)
query = QNetworkProxyQuery(host, port)
proxies = QNetworkProxyFactory.systemProxyForQuery(query)
return len(proxies) and proxies[0].type() != QNetworkProxy.NoProxy
示例6: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def __init__(self, parent, args):
QObject.__init__(self, parent)
# variable declarations
self.m_defaultPageSettings = {}
self.m_pages = []
self.m_verbose = args.verbose
self.m_page = WebPage(self)
self.m_returnValue = 0
self.m_terminated = False
# setup the values from args
self.m_scriptFile = args.script
self.m_args = args.script_args
self.m_filesystem = FileSystem(self)
self.m_pages.append(self.m_page)
do_action('PhantomInitPre')
if args.proxy is None:
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, args.proxy[0], int(args.proxy[1]))
QNetworkProxy.setApplicationProxy(proxy)
# Provide WebPage with a non-standard Network Access Manager
self.m_netAccessMan = NetworkAccessManager(self, args.disk_cache, args.cookies, args.ignore_ssl_errors)
self.m_page.setNetworkAccessManager(self.m_netAccessMan)
self.m_page.javaScriptConsoleMessageSent.connect(self.printConsoleMessage)
self.m_defaultPageSettings['loadImages'] = args.load_images
self.m_defaultPageSettings['loadPlugins'] = args.load_plugins
self.m_defaultPageSettings['javascriptEnabled'] = True
self.m_defaultPageSettings['XSSAuditingEnabled'] = False
self.m_defaultPageSettings['userAgent'] = self.m_page.userAgent()
self.m_defaultPageSettings['localAccessRemote'] = args.local_access_remote
self.m_page.applySettings(self.m_defaultPageSettings)
self.libraryPath = os.path.dirname(os.path.abspath(self.m_scriptFile))
# inject our properties and slots into javascript
self.m_page.mainFrame().addToJavaScriptWindowObject('phantom', self)
self.m_page.mainFrame().addToJavaScriptWindowObject('fs', self.m_filesystem)
bootstrap = QFile(':/bootstrap.js')
if not bootstrap.open(QFile.ReadOnly):
sys.exit('Can not bootstrap!')
bootstrapper = str(bootstrap.readAll())
bootstrap.close()
if not bootstrapper:
sys.exit('Can not bootstrap!')
self.m_page.mainFrame().evaluateJavaScript(bootstrapper)
do_action('PhantomInitPost')
示例7: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def __init__(self, args, parent = None):
QObject.__init__(self, parent)
# variable declarations
self.m_loadStatus = self.m_state = ''
self.m_var = self.m_paperSize = self.m_loadScript_cache = {}
self.m_verbose = args.verbose
self.m_page = WebPage(self)
self.m_clipRect = QRect()
# setup the values from args
self.m_script = args.script.read()
self.m_scriptFile = args.script.name
self.m_scriptDir = os.path.dirname(args.script.name)
if sys.platform.startswith('win'):
self.m_scriptDir += '\\'
else:
self.m_scriptDir += '/'
self.m_args = args.script_args
self.m_upload_file = args.upload_file
autoLoadImages = False if args.load_images == 'no' else True
pluginsEnabled = True if args.load_plugins == 'yes' else False
args.script.close()
palette = self.m_page.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
self.m_page.setPalette(palette)
if not args.proxy:
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, args.proxy[0], int(args.proxy[1]))
QNetworkProxy.setApplicationProxy(proxy)
self.m_page.settings().setAttribute(QWebSettings.AutoLoadImages, autoLoadImages)
self.m_page.settings().setAttribute(QWebSettings.PluginsEnabled, pluginsEnabled)
self.m_page.settings().setAttribute(QWebSettings.FrameFlatteningEnabled, True)
self.m_page.settings().setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True)
self.m_page.settings().setAttribute(QWebSettings.LocalStorageEnabled, True)
self.m_page.settings().setLocalStoragePath(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
self.m_page.settings().setOfflineStoragePath(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
# Ensure we have a document.body.
self.m_page.mainFrame().setHtml('<html><body></body></html>')
self.m_page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self.m_page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
if self.m_verbose:
m_netAccessMan = NetworkAccessManager(args.disk_cache, self)
self.m_page.setNetworkAccessManager(m_netAccessMan)
# inject our properties and slots into javascript
self.m_page.mainFrame().javaScriptWindowObjectCleared.connect(self.inject)
self.m_page.loadFinished.connect(self.finish)
示例8: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def __init__(self, args, parent = None):
QObject.__init__(self, parent)
# variable declarations
self.m_loadStatus = self.m_state = QString()
self.m_var = self.m_paperSize = self.m_loadScript_cache = {}
self.m_verbose = args.verbose
self.m_page = WebPage(self)
self.m_clipRect = QRect()
# setup the values from args
self.m_script = QString.fromUtf8(args.script[0].read())
self.m_scriptFile = args.script[0].name
self.m_args = args.script[1:]
self.m_upload_file = args.upload_file
autoLoadImages = False if args.load_images == 'no' else True
pluginsEnabled = True if args.load_plugins == 'yes' else False
args.script[0].close()
palette = self.m_page.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
self.m_page.setPalette(palette)
if not args.proxy:
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, args.proxy[0], int(args.proxy[1]))
QNetworkProxy.setApplicationProxy(proxy)
self.m_page.settings().setAttribute(QWebSettings.AutoLoadImages, autoLoadImages)
self.m_page.settings().setAttribute(QWebSettings.PluginsEnabled, pluginsEnabled)
self.m_page.settings().setAttribute(QWebSettings.FrameFlatteningEnabled, True)
self.m_page.settings().setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True)
self.m_page.settings().setAttribute(QWebSettings.LocalStorageEnabled, True)
self.m_page.settings().setLocalStoragePath(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
self.m_page.settings().setOfflineStoragePath(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
# Ensure we have a document.body.
self.m_page.mainFrame().setHtml('<html><body></body></html>')
self.m_page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self.m_page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
# if our script was called in a different directory, change to it
# to make any dealings with files be relative to the scripts directory
if os.path.dirname(self.m_scriptFile):
os.chdir(os.path.dirname(self.m_scriptFile))
if self.m_verbose:
m_netAccessMan = NetworkAccessManager(self)
self.m_page.setNetworkAccessManager(m_netAccessMan)
# inject our properties and slots into javascript
self.connect(self.m_page.mainFrame(), SIGNAL('javaScriptWindowObjectCleared()'), self.inject)
self.connect(self.m_page, SIGNAL('loadFinished(bool)'), self.finish)
示例9: set_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def set_proxy(proxy):
proxy_url = QUrl(proxy)
if unicode(proxy_url.scheme()).startswith('http'):
protocol = QNetworkProxy.HttpProxy
else:
protocol = QNetworkProxy.Socks5Proxy
QNetworkProxy.setApplicationProxy(
QNetworkProxy(
protocol,
proxy_url.host(),
proxy_url.port(),
proxy_url.userName(),
proxy_url.password()))
示例10: _set_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def _set_proxy(self, manager):
proxy_settings = manager.get_proxy_settings()
if proxy_settings.config == 'Manual':
if proxy_settings.server and proxy_settings.port:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, hostName=proxy_settings.server,
port=int(proxy_settings.port))
if proxy_settings.authenticated:
proxy.setPassword(proxy_settings.password)
proxy.setUser(proxy_settings.username)
QNetworkProxy.setApplicationProxy(proxy)
elif proxy_settings.config == 'System':
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.NoProxy))
示例11: prox
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def prox(self,mode,user,password,host,port):
proxy = QNetworkProxy()
if mode == "DefaultProxy":
proxy.setType(QNetworkProxy.DefaultProxy)
elif mode == "Socks5Proxy":
proxy.setType(QNetworkProxy.Socks5Proxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "HttpProxy":
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "HttpCachingProxy":
proxy.setType(QNetworkProxy.HttpCachingProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "FtpCachingProxy":
proxy.setType(QNetworkProxy.FtpCachingProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
示例12: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def __init__(self, args, parent=None):
QObject.__init__(self, parent)
# variable declarations
self.m_defaultPageSettings = {}
self.m_verbose = args.verbose
self.m_page = WebPage(self)
self.m_returnValue = 0
self.m_terminated = False
# setup the values from args
self.m_script = args.script
self.m_scriptFile = args.script_name
self.m_args = args.script_args
do_action('PhantomInitPre', Bunch(locals()))
if not args.proxy:
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, args.proxy[0], int(args.proxy[1]))
QNetworkProxy.setApplicationProxy(proxy)
# Provide WebPage with a non-standard Network Access Manager
self.m_netAccessMan = NetworkAccessManager(args.disk_cache, args.ignore_ssl_errors, self)
self.m_page.setNetworkAccessManager(self.m_netAccessMan)
self.m_page.javaScriptConsoleMessageSent.connect(self.printConsoleMessage)
self.m_defaultPageSettings['loadImages'] = args.load_images
self.m_defaultPageSettings['loadPlugins'] = args.load_plugins
self.m_defaultPageSettings['userAgent'] = self.m_page.userAgent()
self.m_page.applySettings(self.m_defaultPageSettings)
# inject our properties and slots into javascript
self.m_page.mainFrame().addToJavaScriptWindowObject('phantom', self)
bootstrap = QFile(':/bootstrap.js')
if not bootstrap.open(QFile.ReadOnly):
qCritical('Can not bootstrap!')
sys.exit(1)
bootstrapper = str(bootstrap.readAll())
bootstrap.close()
if not bootstrapper:
qCritical('Can not bootstrap!')
sys.exit(1)
self.m_page.mainFrame().evaluateJavaScript(bootstrapper)
do_action('PhantomInitPost', Bunch(locals()))
示例13: applySettings
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def applySettings(self):
if self.feedView.siteServer.session.user != str(self.ffNickname.text()) or self.feedView.siteServer.session.remoteKey != str(self.ffRemoteKey.text()):
self.feedView.siteServer.session.user = str(self.ffNickname.text())
self.feedView.siteServer.session.remoteKey = str(self.ffRemoteKey.text())
self.feedView.goHome()
proxy = QNetworkProxy()
proxyType = self.proxyType.currentIndex()
proxy.setType( (proxyType == 2) and QNetworkProxy.Socks5Proxy or ( (proxyType == 1) and QNetworkProxy.HttpProxy or QNetworkProxy.NoProxy ) )
if proxyType:
proxy.setHostName(self.proxyHost.text())
proxy.setPort(self.proxyPort.value())
if self.proxyAuth.checkState() == Qt.Checked:
proxy.setUser(self.proxyAuthUser.text())
proxy.setPassword(self.proxyAuthPassword.text())
QNetworkProxy.setApplicationProxy(proxy)
示例14: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def __init__(self, parent, args):
super(Phantom, self).__init__(parent)
# variable declarations
self.m_defaultPageSettings = {}
self.m_pages = []
self.m_verbose = args.verbose
self.m_page = WebPage(self, args)
self.m_returnValue = 0
self.m_terminated = False
# setup the values from args
self.app_args = args
self.m_scriptFile = args.script
self.m_args = args.script_args
self.m_scriptEncoding = Encode(args.script_encoding, 'utf-8')
self.m_outputEncoding = Encode(args.output_encoding, sys.stdout.encoding_sys)
self.m_pages.append(self.m_page)
do_action('PhantomInitPre')
if args.proxy is None:
QNetworkProxyFactory.setUseSystemConfiguration(True)
else:
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, args.proxy[0], int(args.proxy[1]))
QNetworkProxy.setApplicationProxy(proxy)
self.m_page.javaScriptConsoleMessageSent.connect(self.printConsoleMessage)
self.m_defaultPageSettings['loadImages'] = args.load_images
self.m_defaultPageSettings['loadPlugins'] = args.load_plugins
self.m_defaultPageSettings['javascriptEnabled'] = True
self.m_defaultPageSettings['XSSAuditingEnabled'] = False
self.m_defaultPageSettings['userAgent'] = self.m_page.userAgent()
self.m_defaultPageSettings['localToRemoteUrlAccessEnabled'] = args.local_to_remote_url_access
self.m_page.applySettings(self.m_defaultPageSettings)
self.libraryPath = os.path.dirname(os.path.abspath(self.m_scriptFile))
# inject our properties and slots into javascript
self.m_page.mainFrame().addToJavaScriptWindowObject('phantom', self)
with QPyFile(':/bootstrap.js') as f:
bootstrap = str(f.readAll())
self.m_page.mainFrame().evaluateJavaScript(bootstrap)
do_action('PhantomInitPost')
示例15: proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setApplicationProxy [as 别名]
def proxy(self, value):
"""System wide proxy
"""
proxy_url = QtCore.QUrl(value)
#TODO: Una regexp para filtar basura y quitar el try except
if not value:
network_proxy = QNetworkProxy(QNetworkProxy.NoProxy)
else:
try:
protocol = QNetworkProxy.NoProxy
if proxy_url.scheme().startswith('http'):
protocol = QNetworkProxy.HttpProxy
else:
protocol = QNetworkProxy.Socks5Proxy
network_proxy = QNetworkProxy(protocol, proxy_url.host(), proxy_url.port(), proxy_url.userName(), proxy_url.password())
except:
network_proxy = QNetworkProxy(QNetworkProxy.NoProxy)
QNetworkProxy.setApplicationProxy( network_proxy )