pyhaystack.client.http package¶
Submodules¶
pyhaystack.client.http.auth module¶
Base HTTP client authentication classes. These classes simply act as containers for authentication methods defined in the HTTP spec.
-
class
pyhaystack.client.http.auth.
AuthenticationCredentials
¶ Bases:
object
A base class to represent authentication credentials.
-
class
pyhaystack.client.http.auth.
BasicAuthenticationCredentials
(username, password)¶ Bases:
pyhaystack.client.http.auth.UserPasswordAuthenticationCredentials
A class that represents Basic authentication.
-
class
pyhaystack.client.http.auth.
DigestAuthenticationCredentials
(username, password)¶ Bases:
pyhaystack.client.http.auth.UserPasswordAuthenticationCredentials
A class that represents Digest authentication.
-
class
pyhaystack.client.http.auth.
UserPasswordAuthenticationCredentials
(username, password)¶ Bases:
pyhaystack.client.http.auth.AuthenticationCredentials
A base class that represents username/password type authentication.
pyhaystack.client.http.base module¶
Base HTTP client handler class. This wraps a HTTP client library in a consistent interface to make processing and handling of requests more convenient and to aid portability of pyhaystack.
-
class
pyhaystack.client.http.base.
HTTPClient
(uri=None, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None, tls_verify=None, tls_cert=None, log=None)¶ Bases:
object
The base HTTP client interface. This class defines methods for making HTTP requests in a unified manner. The interface presented is an asynchronous one, even for synchronous implementations.
Instantiate a HTTP client instance with some default parameters. These parameters are made accessible as properties to be modified at will by the caller as needed.
Parameters: - uri – Base URI for all requests. If given, this string will be pre-pended to all requests passed through this client.
- params – A dictionary of key-value pairs to be passed as URI query parameters.
- headers – A dictionary of key-value pairs to be passed as HTTP headers.
- cookies – A dictionary of key-value pairs to be passed as cookies.
- auth – An instance of a HttpAuth object.
- timeout – An integer or float giving the default maximum time duration for requests before timing out.
- proxies – A dictionary mapping the hostname and protocol to a proxy server URI.
- tls_verify – For TLS servers, this determines whether the server is validated or not. It should be the path to the CA certificate file for this server, or alternatively can be set to ‘True’ to verify against CAs known to the client. (e.g. OS certificate store)
- tls_cert – For TLS servers, this specifies the certificate used by the client to authenticate itself with the server.
- log – If not None, then it’s a logging object that will be used for debugging HTTP operations.
-
PROTO_RE
= <_sre.SRE_Pattern object>¶
-
get
(uri, callback, **kwargs)¶ Convenience function: perform a HTTP GET operation. Arguments are the same as for request.
-
post
(uri, callback, body=None, body_type=None, body_size=None, headers=None, **kwargs)¶ Convenience function: perform a HTTP POST operation. Arguments are the same as for request.
Parameters: - body – Body data to be posted in this request as a string.
- body_type – Body MIME data type. This is a convenience for setting the Content-Type header.
- body_size – Length of the body to be sent. If None, the length is autodetected. Set to False to avoid this.
-
request
(method, uri, callback, body=None, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None, tls_verify=None, tls_cert=None, exclude_params=None, exclude_headers=None, exclude_cookies=None, exclude_proxies=None)¶ Perform a request with this client. Most parameters here exist to either add to or override the defaults given by the client attributes. The parameters exclude_... serve to allow selective removal of defaults.
Parameters: - method – The HTTP method to request.
- uri – URL for this request. If this is a relative URL, it will be relative to the URL given by the ‘uri’ attribute.
- callback – A callback function that will be presented with the result of this request.
- body – An optional body for the request.
- params – A dictionary of key-value pairs to be passed as URI query parameters.
- headers – A dictionary of key-value pairs to be passed as HTTP headers.
- cookies – A dictionary of key-value pairs to be passed as cookies.
- auth – An instance of a HttpAuth object.
- timeout – An integer or float giving the default maximum time duration for requests before timing out.
- proxies – A dictionary mapping the hostname and protocol to a proxy server URI.
- tls_verify – For TLS servers, this determines whether the server is validated or not. It should be the path to the CA certificate file for this server, or alternatively can be set to ‘True’ to verify against CAs known to the client. (e.g. OS certificate store)
- tls_cert – For TLS servers, this specifies the certificate used by the client to authenticate itself with the server.
- exclude_params – If True, exclude all default parameters and use only the parameters given. Otherwise, this is an iterable of parameter names to be excluded.
- exclude_headers – If True, exclude all default headers and use only the headers given. Otherwise, this is an iterable of header names to be excluded.
- exclude_cookies – If True, exclude all default cookies and use only the cookies given. Otherwise, this is an iterable of cookie names to be excluded.
- exclude_proxies – If True, exclude all default proxies and use only the proxies given. Otherwise, this is an iterable of proxy names to be excluded.
-
class
pyhaystack.client.http.base.
HTTPResponse
(status_code, headers, body, cookies=None)¶ Bases:
object
A class that represents the raw response from a HTTP request.
-
content_type
¶ Return the content type of the body.
-
content_type_args
¶ Return the content type arguments of the body.
-
text
¶ Attempt to decode the raw body into text based on the encoding given.
-
pyhaystack.client.http.exceptions module¶
HTTP client exception classes.
-
exception
pyhaystack.client.http.exceptions.
HTTPBaseError
¶ Bases:
exceptions.IOError
Error class to represent a HTTP errors.
-
exception
pyhaystack.client.http.exceptions.
HTTPConnectionError
¶ Bases:
pyhaystack.client.http.exceptions.HTTPBaseError
Error class to represent a failed attempt to connect to a host.
-
exception
pyhaystack.client.http.exceptions.
HTTPRedirectError
¶ Bases:
pyhaystack.client.http.exceptions.HTTPBaseError
Error class to represent that the server’s redirections are looping.
-
exception
pyhaystack.client.http.exceptions.
HTTPStatusError
(message, status, headers=None, body=None)¶ Bases:
pyhaystack.client.http.exceptions.HTTPBaseError
Error class to represent a returned failed status from the host.
-
exception
pyhaystack.client.http.exceptions.
HTTPTimeoutError
¶ Bases:
pyhaystack.client.http.exceptions.HTTPConnectionError
Error class to represent that a request timed out.
pyhaystack.client.http.sync module¶
Synchronous HTTP client using Python Requests.
-
class
pyhaystack.client.http.sync.
SyncHttpClient
(**kwargs)¶