Example #1
0
 def __init__(self, client, url, method, inp_params=None, headers=None,
              data=None, files=None, json=None, history=None, auth=None,
              charset=None, max_redirects=10, source_address=None,
              allow_redirects=False, decompress=True, version=None,
              wait_continue=False, websocket_handler=None, cookies=None,
              params=None, stream=False, proxies=None, verify=True,
              **ignored):
     self.client = client
     self.method = method.upper()
     self.inp_params = inp_params or {}
     self.unredirected_headers = Headers(kind='client')
     self.history = history
     self.wait_continue = wait_continue
     self.max_redirects = max_redirects
     self.allow_redirects = allow_redirects
     self.charset = charset or 'utf-8'
     self.version = version
     self.decompress = decompress
     self.websocket_handler = websocket_handler
     self.source_address = source_address
     self.stream = stream
     self.verify = verify
     self.new_parser()
     if auth and not isinstance(auth, Auth):
         auth = HTTPBasicAuth(*auth)
     self.auth = auth
     self.headers = client._get_headers(headers)
     self.url = full_url(url, params, method=self.method)
     self.body = self._encode_body(data, files, json)
     self._set_proxy(proxies, ignored)
     cookies = cookiejar_from_dict(client.cookies, cookies)
     if cookies:
         cookies.add_cookie_header(self)
Example #2
0
 def __init__(self, client, url, method, inp_params=None, headers=None,
              data=None, files=None, json=None, history=None, auth=None,
              charset=None, max_redirects=10, source_address=None,
              allow_redirects=False, decompress=True, version=None,
              wait_continue=False, websocket_handler=None, cookies=None,
              params=None, stream=False, proxies=None, verify=True,
              **ignored):
     self.client = client
     self.method = method.upper()
     self.inp_params = inp_params or {}
     self.unredirected_headers = Headers()
     self.history = history
     self.wait_continue = wait_continue
     self.max_redirects = max_redirects
     self.allow_redirects = allow_redirects
     self.charset = charset or 'utf-8'
     self.version = version
     self.decompress = decompress
     self.websocket_handler = websocket_handler
     self.source_address = source_address
     self.stream = stream
     self.verify = verify
     self.new_parser()
     if auth and not isinstance(auth, Auth):
         auth = HTTPBasicAuth(*auth)
     self.auth = auth
     self.headers = client._get_headers(headers)
     self.url = full_url(url, params, method=self.method)
     self.body = self._encode_body(data, files, json)
     self._set_proxy(proxies, ignored)
     cookies = cookiejar_from_dict(client.cookies, cookies)
     if cookies:
         cookies.add_cookie_header(self)
Example #3
0
 def __init__(
     self,
     proxy_info=None,
     cache=None,
     headers=None,
     encode_multipart=True,
     multipart_boundary=None,
     keyfile=None,
     certfile=None,
     cert_reqs=CERT_NONE,
     ca_certs=None,
     cookies=None,
     store_cookies=True,
     max_redirects=10,
     decompress=True,
     version=None,
     websocket_handler=None,
     parser=None,
     trust_env=True,
     loop=None,
     client_version=None,
     timeout=None,
     pool_size=10,
     frame_parser=None,
 ):
     super().__init__(loop)
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders["user-agent"] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxy_info = dict(proxy_info or ())
     if not self.proxy_info and self.trust_env:
         self.proxy_info = get_environ_proxies()
         if "no" not in self.proxy_info:
             self.proxy_info["no"] = ",".join(self.no_proxy)
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary or choose_boundary()
     self.websocket_handler = websocket_handler
     self.https_defaults = {"keyfile": keyfile, "certfile": certfile, "cert_reqs": cert_reqs, "ca_certs": ca_certs}
     self.http_parser = parser or http_parser
     self.frame_parser = frame_parser or websocket.frame_parser
     # Add hooks
     self.bind_event("pre_request", Tunneling(self._loop))
     self.bind_event("on_headers", handle_101)
     self.bind_event("on_headers", handle_100)
     self.bind_event("on_headers", handle_cookies)
     self.bind_event("post_request", handle_redirect)
Example #4
0
 def __init__(self, proxies=None, headers=None, verify=True,
              cookies=None, store_cookies=True, cert=None,
              max_redirects=10, decompress=True, version=None,
              websocket_handler=None, parser=None, trust_env=True,
              loop=None, client_version=None, timeout=None, stream=False,
              pool_size=10, frame_parser=None, logger=None,
              close_connections=False, keep_alive=None):
     super().__init__(
         partial(Connection, HttpResponse),
         loop=loop,
         keep_alive=keep_alive or cfg_value('http_keep_alive')
     )
     self.logger = logger or LOGGER
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     # SSL Verification default
     self.verify = verify
     # SSL client certificate default, if String, path to ssl client
     # cert file (.pem). If Tuple, ('cert', 'key') pair
     self.cert = cert
     self.stream = stream
     self.close_connections = close_connections
     dheaders = CIMultiDict(self.DEFAULT_HTTP_HEADERS)
     dheaders['user-agent'] = self.client_version
     # override headers
     if headers:
         for name, value in mapping_iterator(headers):
             if value is None:
                 dheaders.pop(name, None)
             else:
                 dheaders[name] = value
     self.headers = dheaders
     self.proxies = dict(proxies or ())
     if not self.proxies and self.trust_env:
         self.proxies = get_environ_proxies()
         if 'no' not in self.proxies:
             self.proxies['no'] = ','.join(self.no_proxy)
     self.websocket_handler = websocket_handler
     self.http_parser = parser or http.HttpResponseParser
     self.frame_parser = frame_parser or websocket.frame_parser
     # Add hooks
     self.event('on_headers').bind(handle_cookies)
     self.event('pre_request').bind(WebSocket())
     self.event('post_request').bind(Expect())
     self.event('post_request').bind(Redirect())
     self._decompressors = dict(
         gzip=GzipDecompress(),
         deflate=DeflateDecompress()
     )
Example #5
0
 def __init__(self,
              proxy_info=None,
              cache=None,
              headers=None,
              encode_multipart=True,
              multipart_boundary=None,
              keyfile=None,
              certfile=None,
              verify=True,
              ca_certs=None,
              cookies=None,
              store_cookies=True,
              max_redirects=10,
              decompress=True,
              version=None,
              websocket_handler=None,
              parser=None,
              trust_env=True,
              loop=None,
              client_version=None,
              timeout=None,
              pool_size=10,
              frame_parser=None):
     super().__init__(loop)
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     self.verify = verify
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders['user-agent'] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxy_info = dict(proxy_info or ())
     if not self.proxy_info and self.trust_env:
         self.proxy_info = get_environ_proxies()
         if 'no' not in self.proxy_info:
             self.proxy_info['no'] = ','.join(self.no_proxy)
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary or choose_boundary()
     self.websocket_handler = websocket_handler
     self.http_parser = parser or http_parser
     self.frame_parser = frame_parser or websocket.frame_parser
     # Add hooks
     self.bind_event('pre_request', Tunneling(self._loop))
     self.bind_event('on_headers', handle_101)
     self.bind_event('on_headers', handle_100)
     self.bind_event('on_headers', handle_cookies)
     self.bind_event('post_request', handle_redirect)
Example #6
0
 def __init__(self,
              proxies=None,
              headers=None,
              verify=True,
              cookies=None,
              store_cookies=True,
              max_redirects=10,
              decompress=True,
              version=None,
              websocket_handler=None,
              parser=None,
              trust_env=True,
              loop=None,
              client_version=None,
              timeout=None,
              stream=False,
              pool_size=10,
              frame_parser=None,
              logger=None,
              close_connections=False,
              keep_alive=None):
     super().__init__(loop)
     self._logger = logger or LOGGER
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     self.verify = verify
     self.stream = stream
     self.close_connections = close_connections
     self.keep_alive = cfg_value('http_keep_alive', keep_alive)
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders['user-agent'] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxies = dict(proxies or ())
     if not self.proxies and self.trust_env:
         self.proxies = get_environ_proxies()
         if 'no' not in self.proxies:
             self.proxies['no'] = ','.join(self.no_proxy)
     self.websocket_handler = websocket_handler
     self.http_parser = parser or http_parser
     self.frame_parser = frame_parser or websocket.frame_parser
     # Add hooks
     self.bind_event('pre_request', Tunneling(self._loop))
     self.bind_event('pre_request', WebSocket())
     self.bind_event('on_headers', handle_cookies)
     self.bind_event('post_request', Redirect())
Example #7
0
 def __init__(
     self,
     client,
     url,
     method,
     inp_params=None,
     headers=None,
     data=None,
     files=None,
     history=None,
     charset=None,
     encode_multipart=True,
     multipart_boundary=None,
     source_address=None,
     allow_redirects=False,
     max_redirects=10,
     decompress=True,
     version=None,
     wait_continue=False,
     websocket_handler=None,
     cookies=None,
     urlparams=None,
     **ignored
 ):
     self.client = client
     self._data = None
     self.files = files
     self.urlparams = urlparams
     self.inp_params = inp_params or {}
     self.unredirected_headers = Headers(kind="client")
     self.method = method.upper()
     self.full_url = url
     if urlparams:
         self._encode_url(urlparams)
     self.set_proxy(None)
     self.history = history
     self.wait_continue = wait_continue
     self.max_redirects = max_redirects
     self.allow_redirects = allow_redirects
     self.charset = charset or "utf-8"
     self.version = version
     self.decompress = decompress
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary
     self.websocket_handler = websocket_handler
     self.source_address = source_address
     self.new_parser()
     if self._scheme in tls_schemes:
         self._ssl = client.ssl_context(**ignored)
     self.headers = client.get_headers(self, headers)
     cookies = cookiejar_from_dict(client.cookies, cookies)
     if cookies:
         cookies.add_cookie_header(self)
     self.unredirected_headers["host"] = host_no_default_port(self._scheme, self._netloc)
     client.set_proxy(self)
     self.data = data
Example #8
0
 def __init__(self,
              client,
              url,
              method,
              inp_params=None,
              headers=None,
              data=None,
              files=None,
              history=None,
              charset=None,
              encode_multipart=True,
              multipart_boundary=None,
              source_address=None,
              allow_redirects=False,
              max_redirects=10,
              decompress=True,
              version=None,
              wait_continue=False,
              websocket_handler=None,
              cookies=None,
              urlparams=None,
              **ignored):
     self.client = client
     self._data = None
     self.files = files
     self.urlparams = urlparams
     self.inp_params = inp_params or {}
     self.unredirected_headers = Headers(kind='client')
     self.method = method.upper()
     self.full_url = url
     if urlparams:
         self._encode_url(urlparams)
     self.set_proxy(None)
     self.history = history
     self.wait_continue = wait_continue
     self.max_redirects = max_redirects
     self.allow_redirects = allow_redirects
     self.charset = charset or 'utf-8'
     self.version = version
     self.decompress = decompress
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary
     self.websocket_handler = websocket_handler
     self.source_address = source_address
     self.new_parser()
     if self._scheme in tls_schemes:
         self._ssl = client.ssl_context(**ignored)
     self.headers = client.get_headers(self, headers)
     cookies = cookiejar_from_dict(client.cookies, cookies)
     if cookies:
         cookies.add_cookie_header(self)
     self.unredirected_headers['host'] = host_no_default_port(
         self._scheme, self._netloc)
     client.set_proxy(self)
     self.data = data
Example #9
0
 def __init__(self, proxy_info=None, cache=None, headers=None,
              encode_multipart=True, multipart_boundary=None,
              keyfile=None, certfile=None, cert_reqs=CERT_NONE,
              ca_certs=None, cookies=None, store_cookies=True,
              max_redirects=10, decompress=True, version=None,
              websocket_handler=None, parser=None, trust_env=True,
              loop=None, client_version=None, timeout=None,
              pool_size=10, green=False):
     super(HttpClient, self).__init__(loop)
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     self.green = green and greenio
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders['user-agent'] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxy_info = dict(proxy_info or ())
     if not self.proxy_info and self.trust_env:
         self.proxy_info = get_environ_proxies()
         if 'no' not in self.proxy_info:
             self.proxy_info['no'] = ','.join(self.no_proxy)
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary or choose_boundary()
     self.websocket_handler = websocket_handler
     self.https_defaults = {'keyfile': keyfile,
                            'certfile': certfile,
                            'cert_reqs': cert_reqs,
                            'ca_certs': ca_certs}
     self.http_parser = parser or http_parser
     # Add hooks
     self.bind_event('pre_request', Tunneling(self._loop))
     self.bind_event('on_headers', handle_101)
     self.bind_event('on_headers', handle_100)
     self.bind_event('on_headers', handle_cookies)
     self.bind_event('post_request', handle_redirect)
     # greenlet
     if self.green:
         self.request = partial(green_request, self.request)
Example #10
0
 def __init__(self, proxies=None, cache=None, headers=None,
              encode_multipart=True, multipart_boundary=None,
              keyfile=None, certfile=None, verify=True,
              ca_certs=None, cookies=None, store_cookies=True,
              max_redirects=10, decompress=True, version=None,
              websocket_handler=None, parser=None, trust_env=True,
              loop=None, client_version=None, timeout=None, stream=False,
              pool_size=10, frame_parser=None, logger=None,
              close_connections=False):
     super().__init__(loop)
     self._logger = logger or LOGGER
     self.client_version = client_version or self.client_version
     self.connection_pools = {}
     self.pool_size = pool_size
     self.trust_env = trust_env
     self.timeout = timeout
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     self.verify = verify
     self.stream = stream
     self.close_connections = close_connections
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders['user-agent'] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxies = dict(proxies or ())
     if not self.proxies and self.trust_env:
         self.proxies = get_environ_proxies()
         if 'no' not in self.proxies:
             self.proxies['no'] = ','.join(self.no_proxy)
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary or choose_boundary()
     self.websocket_handler = websocket_handler
     self.http_parser = parser or http_parser
     self.frame_parser = frame_parser or websocket.frame_parser
     # Add hooks
     self.bind_event('finish', self._close)
     self.bind_event('pre_request', Tunneling(self._loop))
     self.bind_event('pre_request', WebSocket())
     self.bind_event('on_headers', handle_cookies)
     self.bind_event('post_request', Redirect())
Example #11
0
 def __init__(self, client, url, method, inp_params=None, headers=None,
              data=None, files=None, history=None, auth=None,
              charset=None, encode_multipart=True, multipart_boundary=None,
              source_address=None, allow_redirects=False, max_redirects=10,
              decompress=True, version=None, wait_continue=False,
              websocket_handler=None, cookies=None, urlparams=None,
              stream=False, proxies=None, verify=True, **ignored):
     self.client = client
     self._data = None
     self.files = files
     self.urlparams = urlparams
     self.inp_params = inp_params or {}
     self.unredirected_headers = Headers(kind='client')
     self.method = method.upper()
     self.full_url = url
     if urlparams:
         self._encode_url(urlparams)
     self.history = history
     self.wait_continue = wait_continue
     self.max_redirects = max_redirects
     self.allow_redirects = allow_redirects
     self.charset = charset or 'utf-8'
     self.version = version
     self.decompress = decompress
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary
     self.websocket_handler = websocket_handler
     self.source_address = source_address
     self.stream = stream
     self.verify = verify
     self.new_parser()
     if self._scheme in tls_schemes:
         self._ssl = client.ssl_context(verify=self.verify, **ignored)
     if auth and not isinstance(auth, Auth):
         auth = HTTPBasicAuth(*auth)
     self.auth = auth
     self.headers = client.get_headers(self, headers)
     cookies = cookiejar_from_dict(client.cookies, cookies)
     if cookies:
         cookies.add_cookie_header(self)
     self.unredirected_headers['host'] = host_no_default_port(self._scheme,
                                                              self._netloc)
     self.data = data
     self._set_proxy(proxies)
Example #12
0
 def setup(self, proxy_info=None, cache=None, headers=None,
           encode_multipart=True, multipart_boundary=None,
           keyfile=None, certfile=None, cert_reqs=CERT_NONE,
           ca_certs=None, cookies=None, store_cookies=True,
           max_redirects=10, decompress=True, version=None,
           websocket_handler=None, parser=None):
     self.store_cookies = store_cookies
     self.max_redirects = max_redirects
     self.cookies = cookiejar_from_dict(cookies)
     self.decompress = decompress
     self.version = version or self.version
     dheaders = self.DEFAULT_HTTP_HEADERS.copy()
     dheaders['user-agent'] = self.client_version
     if headers:
         dheaders.override(headers)
     self.headers = dheaders
     self.tunnel_headers = self.DEFAULT_TUNNEL_HEADERS.copy()
     self.proxy_info = dict(proxy_info or ())
     if not self.proxy_info and self.trust_env:
         self.proxy_info = get_environ_proxies()
         if 'no' not in self.proxy_info:
             self.proxy_info['no'] = ','.join(self.no_proxy)
     self.encode_multipart = encode_multipart
     self.multipart_boundary = multipart_boundary or choose_boundary()
     self.websocket_handler = websocket_handler
     self.https_defaults = {'keyfile': keyfile,
                            'certfile': certfile,
                            'cert_reqs': cert_reqs,
                            'ca_certs': ca_certs}
     self.http_parser = parser or http_parser
     # Add hooks
     self.bind_event('pre_request', Tunneling())
     self.bind_event('on_headers', handle_101)
     self.bind_event('on_headers', handle_100)
     self.bind_event('on_headers', handle_cookies)
     self.bind_event('post_request', handle_redirect)
Example #13
0
 def test_cookiejar_from_dict(self):
     j = cookiejar_from_dict({'bla': 'foo'}, None)
     self.assertEqual(len(j), 1)
     self.assertEqual(j, cookiejar_from_dict(None, j))
     j2 = cookiejar_from_dict({'pippo': 'pluto'}, None, j)
     self.assertEqual(len(j2), 2)
Example #14
0
 def test_cookiejar_from_dict(self):
     j = cookiejar_from_dict({"bla": "foo"})
     j2 = cookiejar_from_dict({"pippo": "pluto"}, j)
     self.assertEqual(j, j2)
Example #15
0
 def test_cookiejar_from_dict(self):
     j = httpurl.cookiejar_from_dict({'bla': 'foo'})
     j2 = httpurl.cookiejar_from_dict({'pippo': 'pluto'}, j)
     self.assertEqual(j, j2)
Example #16
0
 def test_cookiejar_from_dict(self):
     j = cookiejar_from_dict({'bla': 'foo'})
     j2 = cookiejar_from_dict({'pippo': 'pluto'}, j)
     self.assertEqual(j, j2)
Example #17
0
 def test_cookiejar_from_dict(self):
     j = cookiejar_from_dict({'bla': 'foo'}, None)
     self.assertEqual(len(j), 1)
     self.assertEqual(j, cookiejar_from_dict(None, j))
     j2 = cookiejar_from_dict({'pippo': 'pluto'}, None, j)
     self.assertEqual(len(j2), 2)