Exemple #1
0
def http_connection(url, proxy=None):
    """
    Make an HTTPConnection or HTTPSConnection

    :param url: url to connect to
    :param proxy: proxy to connect through, if any; None by default; str of the
                  format 'http://127.0.0.1:8888' to set one
    :returns: tuple of (parsed url, connection object)
    :raises ClientException: Unable to handle protocol scheme
    """
    parsed = urlparse(url)
    proxy_parsed = urlparse(proxy) if proxy else None
    if parsed.scheme == 'http':
        conn = HTTPConnection((proxy_parsed if proxy else parsed).netloc)
    elif parsed.scheme == 'https':
        conn = HTTPSConnection((proxy_parsed if proxy else parsed).netloc)
    else:
        raise ClientException('Cannot handle protocol scheme %s for url %s' %
                              (parsed.scheme, repr(url)))
    if proxy:
        conn._set_tunnel(parsed.hostname, parsed.port)
    return parsed, conn
Exemple #2
0
 def __init__(self, node, partition, hash_, logger):
     ""
     self.logger = logger
     self.node = node
     BufferedHTTPConnection.__init__(self, '%(ip)s:%(port)s' % node)
     self.path = '/%s/%s/%s' % (node['device'], partition, hash_)
Exemple #3
0
 def __init__(self, node, partition, hash_, logger):
     ""
     self.logger = logger
     self.node = node
     BufferedHTTPConnection.__init__(self, '%(ip)s:%(port)s' % node)
     self.path = '/%s/%s/%s' % (node['device'], partition, hash_)