80
80
:exc:`NotImplementedError` exception.
83
.. method:: async_chat._collect_incoming_data(data)
85
Sample implementation of a data collection rutine to be used in conjunction
86
with :meth:`_get_data` in a user-specified :meth:`found_terminator`.
89
83
.. method:: async_chat.discard_buffers()
91
85
In emergencies this method will discard any data held in the input and/or
100
94
should be available via an instance attribute.
103
.. method:: async_chat._get_data()
105
Will return and clear the data received with the sample
106
:meth:`_collect_incoming_data` implementation.
109
97
.. method:: async_chat.get_terminator()
111
99
Returns the current terminator for the channel.
114
.. method:: async_chat.handle_close()
116
Called when the channel is closed. The default method silently closes the
120
.. method:: async_chat.handle_read()
122
Called when a read event fires on the channel's socket in the asynchronous
123
loop. The default method checks for the termination condition established
124
by :meth:`set_terminator`, which can be either the appearance of a
125
particular string in the input stream or the receipt of a particular number
126
of characters. When the terminator is found, :meth:`handle_read` calls the
127
:meth:`found_terminator` method after calling :meth:`collect_incoming_data`
128
with any data preceding the terminating condition.
131
.. method:: async_chat.handle_write()
133
Called when the application may write data to the channel. The default
134
method calls the :meth:`initiate_send` method, which in turn will call
135
:meth:`refill_buffer` to collect data from the producer fifo associated
139
102
.. method:: async_chat.push(data)
141
Creates a :class:`simple_producer` object (*see below*) containing the data
142
and pushes it on to the channel's ``producer_fifo`` to ensure its
143
transmission. This is all you need to do to have the channel write the
144
data out to the network, although it is possible to use your own producers
145
in more complex schemes to implement encryption and chunking, for example.
104
Pushes data on to the channel's fifo to ensure its transmission.
105
This is all you need to do to have the channel write the data out to the
106
network, although it is possible to use your own producers in more complex
107
schemes to implement encryption and chunking, for example.
148
110
.. method:: async_chat.push_with_producer(producer)
153
115
method and send the data to the remote endpoint.
156
.. method:: async_chat.readable()
158
Should return ``True`` for the channel to be included in the set of
159
channels tested by the :cfunc:`select` loop for readability.
162
.. method:: async_chat.refill_buffer()
164
Refills the output buffer by calling the :meth:`more` method of the
165
producer at the head of the fifo. If it is exhausted then the producer is
166
popped off the fifo and the next producer is activated. If the current
167
producer is, or becomes, ``None`` then the channel is closed.
170
118
.. method:: async_chat.set_terminator(term)
172
120
Sets the terminating condition to be recognized on the channel. ``term``
191
139
by the channel after :meth:`found_terminator` is called.
194
.. method:: async_chat.writable()
196
Should return ``True`` as long as items remain on the producer fifo, or the
197
channel is connected and the channel's output buffer is non-empty.
200
asynchat - Auxiliary Classes and Functions
142
asynchat - Auxiliary Classes
201
143
------------------------------------------
204
.. class:: simple_producer(data, buffer_size=512)
206
A :class:`simple_producer` takes a chunk of data and an optional buffer
207
size. Repeated calls to its :meth:`more` method yield successive chunks of
208
the data no larger than *buffer_size*.
213
Produces the next chunk of information from the producer, or returns the
217
145
.. class:: fifo(list=None)
219
Each channel maintains a :class:`fifo` holding data which has been pushed
220
by the application but not yet popped for writing to the channel. A
221
:class:`fifo` is a list used to hold data and/or producers until they are
222
required. If the *list* argument is provided then it should contain
223
producers or data items to be written to the channel.
147
A :class:`fifo` holding data which has been pushed by the application but
148
not yet popped for writing to the channel. A :class:`fifo` is a list used
149
to hold data and/or producers until they are required. If the *list*
150
argument is provided then it should contain producers or data items to be
151
written to the channel.
226
154
.. method:: is_empty()
244
172
If the fifo is not empty, returns ``True, first()``, deleting the popped
245
173
item. Returns ``False, None`` for an empty fifo.
247
The :mod:`asynchat` module also defines one utility function, which may be of
248
use in network and textual analysis operations.
251
.. function:: find_prefix_at_end(haystack, needle)
253
Returns ``True`` if string *haystack* ends with any non-empty prefix of
257
176
.. _asynchat-example: