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


Python QtNetwork.QNetworkProxy类代码示例

本文整理汇总了Python中PyQt4.QtNetwork.QNetworkProxy的典型用法代码示例。如果您正苦于以下问题:Python QNetworkProxy类的具体用法?Python QNetworkProxy怎么用?Python QNetworkProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setProxy

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)
开发者ID:cnchengliang,项目名称:phantomjs_tool,代码行数:7,代码来源:zeromq.py

示例2: set_proxy_settings

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 ''))
开发者ID:SamiBabat,项目名称:playground,代码行数:8,代码来源:pmutils.py

示例3: __init__

    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')
开发者ID:aivaturi,项目名称:phantomjs,代码行数:56,代码来源:phantom.py

示例4: __init__

    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)
开发者ID:westonruter,项目名称:phantomjs,代码行数:55,代码来源:phantom.py

示例5: __init__

    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)
开发者ID:NathanHowell,项目名称:phantomjs-waf,代码行数:55,代码来源:phantom.py

示例6: setUp

    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()
开发者ID:jsoffer,项目名称:eilat,代码行数:28,代码来源:TestEilat.py

示例7: set_proxy

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()))
开发者ID:Aliandrana,项目名称:scripts,代码行数:13,代码来源:webkit_crawler.py

示例8: __init__

    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()))
开发者ID:lautis,项目名称:phantomjs,代码行数:48,代码来源:phantom.py

示例9: request

    def request(self, iri, method="GET", extra_headers=None,
                oauth_credentials=None, post_content=None):
        """Return a deferred that will be fired with a Response object."""
        uri = self.iri_to_uri(iri)
        request = QNetworkRequest(QUrl(uri))
        request.setSslConfiguration(self.ssl_config)
        headers = yield self.build_request_headers(uri, method, extra_headers,
                                                   oauth_credentials)

        for key, value in headers.items():
            request.setRawHeader(key, value)

        post_buffer = QBuffer()
        post_buffer.setData(post_content)
        try:
            result = yield self._perform_request(request, method, post_buffer)
        except ProxyUnauthorizedError as e:
            app_proxy = QNetworkProxy.applicationProxy()
            proxy_host = app_proxy.hostName() if app_proxy else "proxy server"
            got_creds = yield self.request_proxy_auth_credentials(
                                            proxy_host, self.proxy_retry)
            if got_creds:
                self.proxy_retry = True
                result = yield self.request(iri, method, extra_headers,
                                            oauth_credentials, post_content)
            else:
                excp = WebClientError('Proxy creds needed.', e)
                defer.returnValue(excp)
        defer.returnValue(result)
开发者ID:ArslanRafique,项目名称:dist-packages,代码行数:29,代码来源:qtnetwork.py

示例10: __init__

    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')
开发者ID:jsnell,项目名称:phantomjs,代码行数:47,代码来源:phantom.py

示例11: check_proxy_enabled

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
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:17,代码来源:tunnel_server.py

示例12: __set_proxy_slot

	def __set_proxy_slot(self, host, port):
		proxy = QNetworkProxy()
		
		if not host:
			proxy.setType(QNetworkProxy.NoProxy)
		else:
			proxy.setType(QNetworkProxy.HttpProxy)
			proxy.setHostName(host)
			proxy.setPort(port)
			self.__web_view.page().networkAccessManager().setProxy(proxy)
			
		self.__set_proxy_condition.acquire()
		self.__set_proxy_condition.notifyAll()
		self.__set_proxy_condition.release()
开发者ID:igui,项目名称:sdf-showcase,代码行数:14,代码来源:webkitbrowser.py

示例13: _set_proxy

 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))
开发者ID:BryanSchacht,项目名称:nuxeo-drive,代码行数:14,代码来源:dialog.py

示例14: proxy

 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 )
开发者ID:diegomvh,项目名称:prymatex,代码行数:18,代码来源:browser.py

示例15: configure_proxy

 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)
开发者ID:iddqdidkfa,项目名称:scudcloud,代码行数:9,代码来源:wrapper.py


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