graviti.utility.requests#

The implementation of request related tools.

Module Contents#

Classes#

Config

This is a base class defining the concept of Request Config.

TimeoutHTTPAdapter

This class defines the http adapter for setting the timeout value.

UserSession

This class defines UserSession.

UserResponse

This class used to read data from Response with stream method.

Functions#

get_session()

Create and return a session per PID so each sub-processes will use their own session.

submit_multithread_tasks(function, arguments, *, jobs)

Multi-thread framework.

Attributes#

graviti.utility.requests.logger[source]#
class graviti.utility.requests.Config[source]#

This is a base class defining the concept of Request Config.

max_retries#

Maximum retry times of the request.

allowed_retry_methods#

The allowed methods for retrying request.

allowed_retry_status#

The allowed status for retrying request. If both methods and status are fitted, the retrying strategy will work.

timeout#

Timeout value of the request in seconds.

is_internal#

Whether the request is from internal.

graviti.utility.requests.config[source]#
class graviti.utility.requests.TimeoutHTTPAdapter(*args, timeout=None, **kwargs)[source]#

Bases: requests.adapters.HTTPAdapter

This class defines the http adapter for setting the timeout value.

Parameters
  • *args – Extra arguments to initialize TimeoutHTTPAdapter.

  • timeout (Optional[int]) – Timeout value of the post request in seconds.

  • **kwargs – Extra keyword arguments to initialize TimeoutHTTPAdapter.

  • args (Any) –

  • kwargs (Any) –

send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None)[source]#

Send the request.

Parameters
  • request (requests.models.PreparedRequest) – The PreparedRequest being sent.

  • stream (Any) – Whether to stream the request content.

  • timeout (Any) – Timeout value of the post request in seconds.

  • verify (Any) – A path string to a CA bundle to use or a boolean which controls whether to verify the server’s TLS certificate.

  • cert (Any) – User-provided SSL certificate.

  • proxies (Any) – Proxies dict applying to the request.

Returns

Response object.

Return type

Any

class graviti.utility.requests.UserSession[source]#

Bases: requests.Session

This class defines UserSession.

request(self, method, url, *args, **kwargs)[source]#

Make the request.

Parameters
  • method (str) – Method for the request.

  • url (str) – URL for the request.

  • *args – Extra arguments to make the request.

  • **kwargs – Extra keyword arguments to make the request.

  • args (Any) –

  • kwargs (Any) –

Returns

Response of the request.

Raises

ResponseError – If post response error.

Return type

requests.models.Response

graviti.utility.requests.SESSIONS :DefaultDict[int, UserSession][source]#
graviti.utility.requests.get_session()[source]#

Create and return a session per PID so each sub-processes will use their own session.

Returns

The session corresponding to the process.

Return type

UserSession

class graviti.utility.requests.UserResponse(response)[source]#

This class used to read data from Response with stream method.

Parameters

response (requests.models.Response) – Response of the Session.request().

close(self)[source]#

Close the response.

Return type

None

read(self, amt=None)[source]#

Read data from response.

Parameters

amt (Optional[int]) – The needed read amount.

Returns

Response of the request.

Return type

bytes

graviti.utility.requests.submit_multithread_tasks(function, arguments, *, jobs)[source]#

Multi-thread framework.

Parameters
  • function (Callable[[_T], Any]) – The function to call.

  • arguments (Iterable[_T]) – The arguments of the function.

  • jobs (int) – The number of the max workers in multi-thread call procession.

Return type

None