예제 #1
0
파일: Copy of test.py 프로젝트: ptphp/PtPy
 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)
예제 #2
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()
예제 #3
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)