provider.rpc_monitoring_adapter

Documentation for eth_defi.provider.rpc_monitoring_adapter Python module.

Functions

create_monitored_session()

Classes

class RPCMonitoringAdapter

Bases: requests.adapters.HTTPAdapter

build_response(req, resp)

Builds a Response object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter

Parameters
  • req – The PreparedRequest used to generate the response.

  • resp – The urllib3 response object.

Return type

requests.Response

__init__(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)
add_headers(request, **kwargs)

Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the HTTPAdapter.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • request – The PreparedRequest to add headers to.

  • kwargs – The keyword arguments from the call to send().

build_connection_pool_key_attributes(request, verify, cert=None)

Build the PoolKey attributes used by urllib3 to return a connection.

This looks at the PreparedRequest, the user-specified verify value, and the value of the cert parameter to determine what PoolKey values to use to select a connection from a given urllib3 Connection Pool.

The SSL related pool key arguments are not consistently set. As of this writing, use the following to determine what keys may be in that dictionary:

  • If verify is True, "ssl_context" will be set and will be the default Requests SSL Context

  • If verify is False, "ssl_context" will not be set but "cert_reqs" will be set

  • If verify is a string, (i.e., it is a user-specified trust bundle) "ca_certs" will be set if the string is not a directory recognized by os.path.isdir(), otherwise "ca_cert_dir" will be set.

  • If "cert" is specified, "cert_file" will always be set. If "cert" is a tuple with a second item, "key_file" will also be present

To override these settings, one may subclass this class, call this method and use the above logic to change parameters as desired. For example, if one wishes to use a custom ssl.SSLContext one must both set "ssl_context" and based on what else they require, alter the other keys to ensure the desired behaviour.

Parameters
  • request (PreparedRequest) – The PreparedReqest being sent over the connection.

  • verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use.

  • cert – (optional) Any user-provided SSL certificate for client authentication (a.k.a., mTLS). This may be a string (i.e., just the path to a file which holds both certificate and key) or a tuple of length 2 with the certificate file path and key file path.

Returns

A tuple of two dictionaries. The first is the “host parameters” portion of the Pool Key including scheme, hostname, and port. The second is a dictionary of SSLContext related parameters.

cert_verify(conn, url, verify, cert)

Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • conn – The urllib3 connection object associated with the cert.

  • url – The requested URL.

  • verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use

  • cert – The SSL certificate to verify.

close()

Disposes of any internal state.

Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections.

get_connection(url, proxies=None)

DEPRECATED: Users should move to get_connection_with_tls_context for all subclasses of HTTPAdapter using Requests>=2.32.2.

Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • url – The URL to connect to.

  • proxies – (optional) A Requests-style dictionary of proxies used on this request.

Return type

urllib3.ConnectionPool

get_connection_with_tls_context(request, verify, proxies=None, cert=None)

Returns a urllib3 connection for the given request and TLS settings. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • request – The PreparedRequest object to be sent over the connection.

  • verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use.

  • proxies – (optional) The proxies dictionary to apply to the request.

  • cert – (optional) Any user-provided SSL certificate to be used for client authentication (a.k.a., mTLS).

Return type

urllib3.ConnectionPool

init_poolmanager(connections, maxsize, block=False, **pool_kwargs)

Initializes a urllib3 PoolManager.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • connections – The number of urllib3 connection pools to cache.

  • maxsize – The maximum number of connections to save in the pool.

  • block – Block when no free connections are available.

  • pool_kwargs – Extra keyword arguments used to initialize the Pool Manager.

proxy_headers(proxy)

Returns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters

proxy – The url of the proxy being used for this request.

Return type

dict

proxy_manager_for(proxy, **proxy_kwargs)

Return urllib3 ProxyManager for the given proxy.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • proxy – The proxy to return a urllib3 ProxyManager for.

  • proxy_kwargs – Extra keyword arguments used to configure the Proxy Manager.

Returns

ProxyManager

Return type

urllib3.ProxyManager

request_url(request, proxies)

Obtain the url to use when making the final request.

If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • request – The PreparedRequest being sent.

  • proxies – A dictionary of schemes or schemes and hosts to proxy URLs.

Return type

str

send(request, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Sends PreparedRequest object. Returns Response object.

Parameters
  • request – The PreparedRequest being sent.

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

  • timeout (float or tuple or urllib3 Timeout object) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.

  • verify – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use

  • cert – (optional) Any user-provided SSL certificate to be trusted.

  • proxies – (optional) The proxies dictionary to apply to the request.

Return type

requests.Response