connector

Module Contents

Classes

Connection(self,connector,key,protocol,loop)
_TransportPlaceholder() placeholder for BaseConnector.connect function
BaseConnector(self) Base connector class.
_DNSCacheTable(self,ttl=None)
TCPConnector(self) TCP connector.
UnixConnector(self,path,force_close=False,keepalive_timeout=sentinel,limit=100,limit_per_host=0,loop=None) Unix socket connector.
class Connection(connector, key, protocol, loop)
__init__(connector, key, protocol, loop)
__repr__()
__del__(_warnings=warnings)
loop()
transport()
protocol()
writer()
add_callback(callback)
_notify_release()
close()
release()
detach()
closed()
class _TransportPlaceholder

placeholder for BaseConnector.connect function

close()
class BaseConnector

Base connector class.

keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. enable_cleanup_closed - Enables clean-up closed ssl transports.

Disabled by default.

loop - Optional event loop.

__init__()
__del__(_warnings=warnings)
__enter__()
__exit__(*exc)
force_close()

Ultimately close connection on releasing if True.

limit()

The total number for simultaneous connections.

If limit is 0 the connector has no limit. The default limit size is 100.

limit_per_host()

The limit_per_host for simultaneous connections to the same endpoint.

Endpoints are the same if they are have equal (host, port, is_ssl) triple.

_cleanup()

Cleanup unused transports.

_drop_acquired_per_host(key, val)
_cleanup_closed()

Double confirmation for transport close. Some broken ssl servers may leave socket open without proper close.

close()

Close all opened transports.

closed()

Is connector closed.

A readonly property.

_available_connections(key)

Return number of available connections taking into account the limit, limit_per_host and the connection key.

If it returns less than 1 means that there is no connections availables.

connect(req, traces, timeout)

Get from pool or create new connection.

_get(key)
_release_waiter()

Iterates over all waiters till found one that is not finsihed and belongs to a host that has available connections.

_release_acquired(key, proto)
_release(key, protocol)
_create_connection(req, traces, timeout)
class _DNSCacheTable(ttl=None)
__init__(ttl=None)
__contains__(host)
add(host, addrs)
remove(host)
clear()
next_addrs(host)
expired(host)
class TCPConnector

TCP connector.

verify_ssl - Set to True to check ssl certifications. fingerprint - Pass the binary sha256

digest of the expected certificate in DER format to verify that the certificate the server presents matches. See also https://en.wikipedia.org/wiki/Transport_Layer_Security#Certificate_pinning
resolver - Enable DNS lookups and use this
resolver

use_dns_cache - Use memory cache for DNS lookups. ttl_dns_cache - Max seconds having cached a DNS entry, None forever. family - socket address family local_addr - local tuple of (host, port) to bind socket to

keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. enable_cleanup_closed - Enables clean-up closed ssl transports.

Disabled by default.

loop - Optional event loop.

__init__()
close()

Close all ongoing DNS calls.

family()

Socket family like AF_INET.

use_dns_cache()

True if local DNS caching is enabled.

clear_dns_cache(host=None, port=None)

Remove specified host/port or clear all dns local cache.

_resolve_host(host, port, traces=None)
_create_connection(req, traces, timeout)

Create connection.

Has same keyword arguments as BaseEventLoop.create_connection.

_make_ssl_context()
_get_ssl_context(req)

Logic to get the correct SSL context

  1. if req.ssl is false, return None
  2. if ssl_context is specified in req, use it
  3. if _ssl_context is specified in self, use it
  4. otherwise:
    1. if verify_ssl is not specified in req, use self.ssl_context (will generate a default context according to self.verify_ssl)
    2. if verify_ssl is True in req, generate a default SSL context
    3. if verify_ssl is False in req, generate a SSL context that won’t verify
_get_fingerprint(req)
_wrap_create_connection(*args, **kwargs)
_create_direct_connection(req, traces, timeout)
_create_proxy_connection(req, traces, timeout)
class UnixConnector(path, force_close=False, keepalive_timeout=sentinel, limit=100, limit_per_host=0, loop=None)

Unix socket connector.

path - Unix socket path. keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. loop - Optional event loop.

__init__(path, force_close=False, keepalive_timeout=sentinel, limit=100, limit_per_host=0, loop=None)
path()

Path to unix socket.

_create_connection(req, traces, timeout)