Exemplo n.º 1
0
 def __init__(self, node, partition, hash_, logger):
     ""
     self.logger = logger
     self.node = node
     host = "%s:%s" % (node['replication_ip'], node['replication_port'])
     BufferedHTTPConnection.__init__(self, host)
     self.path = '/%s/%s/%s' % (node['device'], partition, hash_)
Exemplo n.º 2
0
 def __init__(self, node, partition, hash_, logger):
     ""
     self.logger = logger
     self.node = node
     host = "%s:%s" % (node['replication_ip'], node['replication_port'])
     BufferedHTTPConnection.__init__(self, host)
     self.path = '/%s/%s/%s' % (node['device'], partition, hash_)
Exemplo n.º 3
0
def send_manifest(env, method, path, logger, extra_header, get_body=False,
                   query_string=None):
    """
    Use this method to send header against a resource already exist.
    """

    # Create a new Request
    req = Request(env)
    ssl = True if req.scheme.lower() == 'https' else False

    # Fixup the auth token, for some reason, the auth token padded the user
    # account at the front with a comma. We need to get rid of it, otherwise,
    # the auth token will be considered invalid.
    key, sep, value = req.headers[Consts.AUTH_TOKEN].partition(',')
    headers = {}
    headers[Consts.AUTH_TOKEN] = value if value != '' else key
    headers['Content-Length'] = '0'
    extra_header.update(headers)
    path = path.rstrip('/')

    if ssl:
        conn = HTTPSConnection('%s:%s' % (req.server_name,
                                          req.server_portport))
    else:
        conn = BufferedHTTPConnection('%s:%s' % (req.server_name,
                                                 req.server_port))

    conn.request('PUT', path, '', extra_header)

    res = conn.getresponse()

    return res
Exemplo n.º 4
0
 def _connect(self, url=None):
     if not url:
         if not self.storage_url:
             self._auth()
         url = self.storage_url
     parsed = urlparse(url)
     proxy_parsed = urlparse(self.proxy) if self.proxy else None
     netloc = (proxy_parsed if self.proxy else parsed).netloc
     if parsed.scheme == "http":
         conn = HTTPConnection(netloc)
     elif parsed.scheme == "https":
         conn = HTTPSConnection(netloc)
     else:
         raise HTTPException("Cannot handle protocol scheme %s for url %s" % (parsed.scheme, repr(url)))
     if self.proxy:
         conn._set_tunnel(parsed.hostname, parsed.port)
     return parsed, conn
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
    """
    url = encode_utf8(url)
    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)))

    def putheader_wrapper(func):
        @wraps(func)
        def putheader_escaped(key, value):
            func(encode_utf8(key), encode_utf8(value))

        return putheader_escaped

    conn.putheader = putheader_wrapper(conn.putheader)

    def request_wrapper(func):
        @wraps(func)
        def request_escaped(method, url, body=None, headers=None):
            url = encode_utf8(url)
            if body:
                body = encode_utf8(body)
            func(method, url, body=body, headers=headers or {})

        return request_escaped

    conn.request = request_wrapper(conn.request)
    if proxy:
        conn._set_tunnel(parsed.hostname, parsed.port)
    return parsed, conn
Exemplo n.º 8
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
    """
    url = encode_utf8(url)
    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)))

    def putheader_wrapper(func):

        @wraps(func)
        def putheader_escaped(key, value):
            func(encode_utf8(key), encode_utf8(value))
        return putheader_escaped
    conn.putheader = putheader_wrapper(conn.putheader)

    def request_wrapper(func):

        @wraps(func)
        def request_escaped(method, url, body=None, headers=None):
            url = encode_utf8(url)
            if body:
                body = encode_utf8(body)
            func(method, url, body=body, headers=headers or {})
        return request_escaped
    conn.request = request_wrapper(conn.request)
    if proxy:
        conn._set_tunnel(parsed.hostname, parsed.port)
    return parsed, conn
Exemplo n.º 9
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_)
Exemplo n.º 10
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_)
Exemplo n.º 11
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_)