pybitmessage.network.asyncore_pollchoose module

Basic infrastructure for asynchronous socket service clients and servers.

exception ExitNow[source]

Bases: exceptions.Exception

We don’t use directly but may be necessary as we replace asyncore due to some library raising or expecting it

read(obj)[source]

Event to read from the object, i.e. its network socket.

write(obj)[source]

Event to write to the object, i.e. its network socket.

set_rates(download, upload)[source]

Set throttling rates

can_receive()[source]

Predicate indicating whether the download throttle is in effect

can_send()[source]

Predicate indicating whether the upload throttle is in effect

update_received(download=0)[source]

Update the receiving throttle

update_sent(upload=0)[source]

Update the sending throttle

readwrite(obj, flags)[source]

Read and write any pending data to/from the object

select_poller(timeout=0.0, map=None)[source]

A poller which uses select(), available on most platforms.

poll_poller(timeout=0.0, map=None)[source]

A poller which uses poll(), available on most UNIXen.

poll(timeout=0.0, map=None)[source]

A poller which uses select(), available on most platforms.

poll2(timeout=0.0, map=None)[source]

A poller which uses poll(), available on most UNIXen.

poll3(timeout=0.0, map=None)[source]

A poller which uses poll(), available on most UNIXen.

epoll_poller(timeout=0.0, map=None)[source]

A poller which uses epoll(), supported on Linux 2.5.44 and newer.

kqueue_poller(timeout=0.0, map=None)[source]

A poller which uses kqueue(), BSD specific.

loop(timeout=30.0, use_poll=False, map=None, count=None, poller=None)[source]

Poll in a loop, until count or timeout is reached

class dispatcher(sock=None, map=None)[source]

Bases: object

Dispatcher for socket objects

debug = False
accepting = False
connecting = False
closing = False
ignore_log_types = frozenset(['warning'])
poller_registered = False
poller_flags = 0
minTx = 1500
addr = None
connected = False
add_channel(map=None)

Add a channel

del_channel(map=None)

Delete a channel

create_socket(family=2, socket_type=1)

Create a socket

set_socket(sock, map=None)

Set socket

set_reuse_addr()

try to re-use a server port if possible

readable()

Predicate to indicate download throttle status

writable()

Predicate to indicate upload throttle status

listen(num)

Listen on a port

bind(addr)

Bind to an address

connect(address)

Connect to an address

accept()

Accept incoming connections. Returns either an address pair or None.

send(data)

Send data

recv(buffer_size)

Receive data

close()

Close connection

log(message)

Log a message to stderr

log_info(message, log_type='info')

Conditionally print a message

handle_read_event()

Handle a read event

handle_connect_event()

Handle a connection event

handle_write_event()

Handle a write event

handle_expt_event()

Handle expected exceptions

handle_error()

Handle unexpected exceptions

handle_accept()

Handle an accept event

handle_expt()

Log that the subclass does not implement handle_expt

handle_read()

Log that the subclass does not implement handle_read

handle_write()

Log that the subclass does not implement handle_write

handle_connect()

Log that the subclass does not implement handle_connect

handle_accepted(sock, addr)

Log that the subclass does not implement handle_accepted

handle_close()

Log that the subclass does not implement handle_close

class dispatcher_with_send(sock=None, map=None)[source]

Bases: pybitmessage.network.asyncore_pollchoose.dispatcher

adds simple buffered output capability, useful for simple clients. [for more sophisticated usage use asynchat.async_chat]

initiate_send()

Initiate a send

handle_write()

Handle a write event

writable()

Predicate to indicate if the object is writable

send(data)

Send data

compact_traceback()[source]

Return a compact traceback

close_all(map=None, ignore_all=False)[source]

Close all connections

class file_wrapper(fd)[source]

Here we override just enough to make a file look like a socket for the purposes of asyncore.

The passed fd is automatically os.dup()’d

recv(*args)

Fake recv()

send(*args)

Fake send()

getsockopt(level, optname, buflen=None)

Fake getsockopt()

read(*args)

Fake recv()

write(*args)

Fake send()

close()

Fake close()

fileno()

Fake fileno()

class file_dispatcher(fd, map=None)[source]

Bases: pybitmessage.network.asyncore_pollchoose.dispatcher

A dispatcher for file_wrapper objects

set_file(fd)

Set file