Пример #1
0
    def set_proxy(self, type_, host='localhost', port=8888, user='',
            password=''):
        """Set up proxy for FURTHER connections.

        :param type_: proxy type to use: \
            none/default/socks5/https/http.
        :param host: proxy server ip or host name.
        :param port: proxy port.
        """
        _types = {
            'default': QNetworkProxy.DefaultProxy,
            'none': QNetworkProxy.NoProxy,
            'socks5': QNetworkProxy.Socks5Proxy,
            'https': QNetworkProxy.HttpProxy,
            'http': QNetworkProxy.HttpCachingProxy
        }

        if type_ is None:
            type_ = 'none'
        type_ = type_.lower()
        if type_ in ['none', 'default']:
            self.manager.setProxy(QNetworkProxy(_types[type_]))
            return
        elif type_ in _types:
            proxy = QNetworkProxy(_types[type_], hostName=host, port=port,
                user=user, password=password)
            self.manager.setProxy(proxy)
        else:
            raise ValueError('Unsupported proxy type:' + type_ \
            + '\nsupported types are: none/socks5/http/https/default')
Пример #2
0
 def updateProxy(self):
     config = self.__parentWindow.config()
     if config.getProxyHost():
         proxy = QNetworkProxy(QNetworkProxy.HttpProxy,
                               config.getProxyHost(), config.getProxyPort())
     else:
         proxy = QNetworkProxy()
     self.__webNote.page().networkAccessManager().setProxy(proxy)
Пример #3
0
    def _init_proxy(self):
        _logger.debug('Initialize proxy')
        proxy = QNetworkProxy(QNetworkProxy.HttpProxy, "localhost",
            self._proxy_port)
        QNetworkProxy.setApplicationProxy(proxy)

        self._proxy_proc = subprocess.Popen(['python', '-m',
            'tornado_proxy.proxy', str(self._proxy_port)])

        atexit.register(self._proxy_proc.terminate)
Пример #4
0
 def __init__(self, parent):
     QNetworkAccessManager.__init__(self, parent)
     proxy = QNetworkProxy()
     proxy.setType(QNetworkProxy.HttpProxy)
     proxy.setHostName("127.0.0.1")
     proxy.setPort(8888)        
     self.setProxy(proxy)
Пример #5
0
 def setProxy(self):
     inst =  Jaime.getInstance()
     proxy_host = inst.getParam('proxy_host','')
     proxy_port = inst.getParam('proxy_port','')
     proxy_user = ''
     proxy_pass = ''
     
     if proxy_host and proxy_port :
         self.logger.info('Setting proxy to %s:%s with us/pass (%s,%s)' % (proxy_host,
                                                                           proxy_port,
                                                                           proxy_user,
                                                                           proxy_pass))
         
         proxy = QNetworkProxy()
         proxy.setType(QNetworkProxy.Socks5Proxy)
         proxy.setHostName(proxy_host)
         proxy.setPort(int(proxy_port))
         QNetworkProxy.setApplicationProxy(proxy)
Пример #6
0
    def set_proxy(self, string_proxy=None):
        """Set proxy:
        url can be in the form:

            - hostname                        (http proxy)
            - hostname:port                   (http proxy)
            - username:password@hostname:port (http proxy)
            - http://username:password@hostname:port
            - socks5://username:password@hostname:port
            - https://username:password@hostname:port
            - httpcaching://username:password@hostname:port
            - ftpcaching://username:password@hostname:port

        """
        if not string_proxy:
            string_proxy = ''
        if string_proxy:
            urlinfo = urlparse.urlparse(string_proxy)
            # default to http proxy if we have a string
            if not urlinfo.scheme:
                string_proxy = "http://%s" % string_proxy
                urlinfo = urlparse.urlparse(string_proxy)
            
            self.proxy_url = string_proxy
            proxy = QNetworkProxy()
            if urlinfo.scheme == 'socks5':
                proxy.setType(QNetworkProxy.Socks5Proxy)
            elif urlinfo.scheme in ['https', 'http']:
                proxy.setType(QNetworkProxy.HttpProxy)
            elif urlinfo.scheme == 'httpcaching':
                proxy.setType(QNetworkProxy.HttpCachingProxy)
            elif urlinfo.scheme == 'ftpcaching':
                proxy.setType(QNetworkProxy.FtpCachingProxy)
            else:
                proxy.setType(QNetworkProxy.NoProxy)
            if urlinfo.hostname != None:
                proxy.setHostName(urlinfo.hostname)
            if urlinfo.port != None:
                proxy.setPort(urlinfo.port)
            if urlinfo.username != None:
                proxy.setUser(urlinfo.username)
            else:
                proxy.setUser('')
            if urlinfo.password != None:
                proxy.setPassword(urlinfo.password)
            else:
                proxy.setPassword('')
            self.setProxy(proxy)
        return self.proxy()