Simplified Async Socket

class urllib3.contrib.ssa.AsyncSocket(family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=-1, fileno=None)

Bases: object

This class is brought to add a level of abstraction to an asyncio transport (reader, or writer) We don’t want to have two distinct code (async/sync) but rather a unified and easily verifiable code base.

‘ssa’ stands for Simplified - Socket - Asynchronous.

Parameters:
  • family (socket.AddressFamily)

  • type (socket.SocketKind)

  • proto (int)

  • fileno (int | None)

bind(addr)
Parameters:

addr (tuple[str, int])

Return type:

None

close()
Return type:

None

async connect(addr)
Parameters:

addr (tuple[str, int] | tuple[str, int, int, int])

Return type:

None

fileno()
Return type:

int

getpeername()
Return type:

tuple[str, int]

getsockopt(_AsyncSocket__level, _AsyncSocket__optname)
Parameters:
  • _AsyncSocket__level (int)

  • _AsyncSocket__optname (int)

Return type:

int

async read()

Just an alias for sendall(), it is needed due to our custom AsyncSocks override.

Return type:

bytes

async read_exact(size=-1)

Just an alias for sendall(), it is needed due to our custom AsyncSocks override.

Parameters:

size (int)

Return type:

bytes

async recv(size=-1)
Parameters:

size (int)

Return type:

bytes

async send(data)
Parameters:

data (bytes | bytearray | memoryview)

Return type:

None

async sendall(data)
Parameters:

data (bytes | bytearray | memoryview)

Return type:

None

setsockopt(_AsyncSocket__level, _AsyncSocket__optname, _AsyncSocket__value)
Parameters:
  • _AsyncSocket__level (int)

  • _AsyncSocket__optname (int)

  • _AsyncSocket__value (int)

Return type:

None

settimeout(_AsyncSocket__value=None)
Parameters:

_AsyncSocket__value (float | None)

Return type:

None

should_connect()
Return type:

bool

async wait_for_readiness()
Return type:

None

async wrap_socket(ctx, *, server_hostname=None, ssl_handshake_timeout=None)
Parameters:
Return type:

SSLAsyncSocket

async write_all(data)

Just an alias for sendall(), it is needed due to our custom AsyncSocks override.

Parameters:

data (bytes | bytearray | memoryview)

Return type:

None

class urllib3.contrib.ssa.SSLAsyncSocket(family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=-1, fileno=None)

Bases: AsyncSocket

Parameters:
  • family (socket.AddressFamily)

  • type (socket.SocketKind)

  • proto (int)

  • fileno (int | None)

cipher()
Return type:

tuple[str, str, int] | None

getpeercert(binary_form: Literal[False] = False) _TYPE_PEER_CERT_RET_DICT | None
getpeercert(binary_form: Literal[True]) bytes | None
selected_alpn_protocol()
Return type:

str | None

property sslobj: ssl.SSLSocket | ssl.SSLObject
async wrap_socket(ctx, *, server_hostname=None, ssl_handshake_timeout=None)
Parameters:
Return type:

SSLAsyncSocket