2008/10/23 Paolo Cavallini <[EMAIL PROTECTED]>:

> Apparently it's a bug in Qt (bug opened; I cannot check it now, but you'll
> find it in the trac).
> I agree in some situations is a very serious issue.

 I've just written a workaround. It's a python class called QPHttp
which is a drop-in replacement for QHttp but sets proxy settings from
those that urllib.getproxies() gets.

 I've tested it standalone, all I need to do now is s/QHttp/QPHttp/ in
the right places in the plugin installer..

 I'll attach it for anyone to play with - there may be some people
with proxy configs that break it...

Barry
###
### QPHttp
###
### Wrapper class for QHttp that gets proxy information from 
### urllib.getproxies. So in Unix it gets if from the http_proxy 
### environment variable, in Windows it gets it from the registry
### or whatever, and on the Mac it gets it from somewhere shiny.
###
### Written by Barry Rowlingson 2008 and you may do what you like 
### with this code.
###

from PyQt4.QtNetwork import *

import urllib
from urlparse import urlparse

def parseProxy(proxyString):
    """ get host/port from URL """
    bits = urlparse(proxyString)
    return (bits.hostname, bits.port)

class QPHttp(QHttp):
    def __init__(self,*args):
        QHttp.__init__(self,*args)
        proxies = urllib.getproxies()
        if proxies.has_key('http'):
            (host,port) = parseProxy(proxies['http'])
            self.proxy=QNetworkProxy()
            self.proxy.setType(QNetworkProxy.HttpProxy)
            self.proxy.setHostName(host)
            self.proxy.setPort(port)
            self.setProxy(self.proxy)
        return None

### test code, reads trolltech's homepage.
        
import sys
from PyQt4.QtCore import *
from PyQt4.QtNetwork import QNetworkProxy

def process(error):
  if not error:
    print "no errors"
    content = unicode(QString(page.readAll()))
    print content[:100],"..."
  else:
    print "errors occured"
    print str(page.errorString())
  quit()

if __name__ == "__main__":

    app = QCoreApplication (sys.argv)

    page = QPHttp("trolltech.com")
    QObject.connect(page, SIGNAL("done(bool)"), process);
    gprocId = page.get('/')
    sys.exit (app.exec_ ())
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to