network.connection Module

Network connections.

class wpull.network.connection.BaseConnection(address: tuple, hostname: typing.Union=None, timeout: typing.Union=None, connect_timeout: typing.Union=None, bind_host: typing.Union=None, sock: typing.Union=None)[source]

Bases: object

Base network stream.

Parameters:
  • address – 2-item tuple containing the IP address and port or 4-item for IPv6.
  • hostname – Hostname of the address (for SSL).
  • timeout – Time in seconds before a read/write operation times out.
  • connect_timeout – Time in seconds before a connect operation times out.
  • bind_host – Host name for binding the socket interface.
  • sock – Use given socket. The socket must already by connected.
reader

Stream Reader instance.

writer

Stream Writer instance.

address

2-item tuple containing the IP address.

host

Host name.

port

Port number.

address
close()[source]

Close the connection.

closed() → bool[source]

Return whether the connection is closed.

connect()[source]

Establish a connection.

host
hostname
port
read(amount: int=-1) → bytes[source]

Read data.

readline() → bytes[source]

Read a line of data.

reset()[source]

Prepare connection for reuse.

run_network_operation(task, wait_timeout=None, close_timeout=None, name='Network operation')[source]

Run the task and raise appropriate exceptions.

Coroutine.

state() → wpull.network.connection.ConnectionState[source]

Return the state of this connection.

write(data: bytes, drain: bool=True)[source]

Write data.

class wpull.network.connection.CloseTimer(timeout, connection)[source]

Bases: object

Periodic timer to close connections if stalled.

close()[source]

Stop running timers.

is_timeout() → bool[source]

Return whether the timer has timed out.

with_timeout()[source]

Context manager that applies timeout checks.

class wpull.network.connection.Connection(*args, bandwidth_limiter=None, **kwargs)[source]

Bases: wpull.network.connection.BaseConnection

Network stream.

Parameters:(class (bandwidth_limiter) – .bandwidth.BandwidthLimiter): Bandwidth limiter for connection speed limiting.
key

Value used by the ConnectionPool for its host pool map. Internal use only.

wrapped_connection

A wrapped connection for ConnectionPool. Internal use only.

is_ssl

bool

Whether connection is SSL.

proxied

bool

Whether the connection is to a HTTP proxy.

tunneled

bool

Whether the connection has been tunneled with the CONNECT request.

is_ssl
proxied
read(amount: int=-1) → bytes[source]
start_tls(ssl_context: typing.Union=True) → 'SSLConnection'[source]

Start client TLS on this connection and return SSLConnection.

Coroutine

tunneled
class wpull.network.connection.ConnectionState[source]

Bases: enum.Enum

State of a connection

ready

Connection is ready to be used

created

connect has been called successfully

dead

Connection is closed

class wpull.network.connection.DummyCloseTimer[source]

Bases: object

Dummy close timer.

close()[source]
is_timeout()[source]
with_timeout()[source]
class wpull.network.connection.SSLConnection(*args, ssl_context: typing.Union=True, **kwargs)[source]

Bases: wpull.network.connection.Connection

SSL network stream.

Parameters:ssl_context – SSLContext
connect()[source]
is_ssl