~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Doc/library/asynchat.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
   :exc:`NotImplementedError` exception.
81
81
 
82
82
 
83
 
.. method:: async_chat._collect_incoming_data(data)
84
 
 
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`.
87
 
 
88
 
 
89
83
.. method:: async_chat.discard_buffers()
90
84
 
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.
101
95
 
102
96
 
103
 
.. method:: async_chat._get_data()
104
 
 
105
 
   Will return and clear the data received with the sample
106
 
   :meth:`_collect_incoming_data` implementation.
107
 
 
108
 
 
109
97
.. method:: async_chat.get_terminator()
110
98
 
111
99
   Returns the current terminator for the channel.
112
100
 
113
101
 
114
 
.. method:: async_chat.handle_close()
115
 
 
116
 
   Called when the channel is closed. The default method silently closes the
117
 
   channel's socket.
118
 
 
119
 
 
120
 
.. method:: async_chat.handle_read()
121
 
 
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.
129
 
 
130
 
 
131
 
.. method:: async_chat.handle_write()
132
 
 
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
136
 
   with the channel.
137
 
 
138
 
 
139
102
.. method:: async_chat.push(data)
140
103
 
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.
146
108
 
147
109
 
148
110
.. method:: async_chat.push_with_producer(producer)
153
115
   method and send the data to the remote endpoint.
154
116
 
155
117
 
156
 
.. method:: async_chat.readable()
157
 
 
158
 
   Should return ``True`` for the channel to be included in the set of
159
 
   channels tested by the :cfunc:`select` loop for readability.
160
 
 
161
 
 
162
 
.. method:: async_chat.refill_buffer()
163
 
 
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.
168
 
 
169
 
 
170
118
.. method:: async_chat.set_terminator(term)
171
119
 
172
120
   Sets the terminating condition to be recognized on the channel.  ``term``
191
139
   by the channel after :meth:`found_terminator` is called.
192
140
 
193
141
 
194
 
.. method:: async_chat.writable()
195
 
 
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.
198
 
 
199
 
 
200
 
asynchat - Auxiliary Classes and Functions
 
142
asynchat - Auxiliary Classes
201
143
------------------------------------------
202
144
 
203
 
 
204
 
.. class:: simple_producer(data, buffer_size=512)
205
 
 
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*.
209
 
 
210
 
 
211
 
   .. method:: more()
212
 
 
213
 
      Produces the next chunk of information from the producer, or returns the
214
 
      empty string.
215
 
 
216
 
 
217
145
.. class:: fifo(list=None)
218
146
 
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.
224
152
 
225
153
 
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.
246
174
 
247
 
The :mod:`asynchat` module also defines one utility function, which may be of
248
 
use in network and textual analysis operations.
249
 
 
250
 
 
251
 
.. function:: find_prefix_at_end(haystack, needle)
252
 
 
253
 
   Returns ``True`` if string *haystack* ends with any non-empty prefix of
254
 
   string *needle*.
255
 
 
256
175
 
257
176
.. _asynchat-example:
258
177