def proxy_info_from_url(url, method='http'):
 url = urlparse.urlparse(url)
 username = None
 password = None
 port = None
 if ('@' in url[1]):
  (ident, host_port) = url[1].split('@', 1)
  if (':' in ident):
   (username, password) = ident.split(':', 1)
  else:
   password = ident
 else:
  host_port = url[1]
 if (':' in host_port):
  (host, port) = host_port.split(':', 1)
 else:
  host = host_port
 if port:
  port = int(port)
 else:
  port = dict(https=443, http=80)[method]
 proxy_type = 3
 return ProxyInfo(proxy_type=proxy_type, proxy_host=host, proxy_port=port, proxy_user=(username or None), proxy_pass=(password or None))

def proxy_info_from_url ( url , method = 'http' ) : url = urlparse . urlparse ( url ) username = None password = None port = None if ( '@' in url [ 1 ] ) : ( ident , host_port ) = url [ 1 ] . split ( '@' , 1 ) if ( ':' in ident ) : ( username , password ) = ident . split ( ':' , 1 ) else : password = ident else : host_port = url [ 1 ] if ( ':' in host_port ) : ( host , port ) = host_port . split ( ':' , 1 ) else : host = host_port if port : port = int ( port ) else : port = dict ( https = 443 , http = 80 ) [ method ] proxy_type = 3 return ProxyInfo ( proxy_type = proxy_type , proxy_host = host , proxy_port = port , proxy_user = ( username or None ) , proxy_pass = ( password or None ) )
construct a proxyinfo from a url .