home *** CD-ROM | disk | FTP | other *** search
- from httplib import HTTP
- import string,os
- import urllib
-
- # Proxy handling
- def getproxies_environment():
- """Return a dictionary of scheme -> proxy server URL mappings.
-
- Scan the environment for variables named <scheme>_proxy;
- this seems to be the standard convention.
- """
- proxies = {}
- for name, value in os.environ.items():
- name = string.lower(name)
- if value and name[-6:] == '_proxy':
- proxies[name[:-6]] = value
- return proxies
-
- class PPMHTTP(HTTP):
- """this is a subclass of standard HTTP class which also connects
- through a HTTP proxy server."""
-
- def __init__(self, host='', port=None, **x509):
- self.hostname = host
- self.proxyhost = None
- # get the proxy host from env
- proxies = urllib.getproxies()
- if proxies.has_key('http'):
- proxy = proxies['http']
- type, proxyurl = urllib.splittype(proxy)
- self.proxyhost, selector = urllib.splithost(proxyurl)
-
- if self.proxyhost:
- HTTP.__init__(self, self.proxyhost, port, **x509)
- else:
- HTTP.__init__(self, self.hostname, port, **x509)
-
- def postrequest(self, method, url):
- if self.proxyhost:
- import urlparse
- url = urlparse.urljoin('http://'+self.hostname,url)
-
- self.putrequest(method, url)
-