Changeset 391 for python/trunk/Doc/library/asynchat.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/asynchat.rst
r2 r391 1 2 1 :mod:`asynchat` --- Asynchronous socket command/response handler 3 2 ================================================================ … … 8 7 .. sectionauthor:: Steve Holden <sholden@holdenweb.com> 9 8 9 **Source code:** :source:`Lib/asynchat.py` 10 11 -------------- 10 12 11 13 This module builds on the :mod:`asyncore` infrastructure, simplifying … … 33 35 Like :class:`asyncore.dispatcher`, :class:`async_chat` defines a set of 34 36 events that are generated by an analysis of socket conditions after a 35 :c func:`select` call. Once the polling loop has been started the37 :c:func:`select` call. Once the polling loop has been started the 36 38 :class:`async_chat` object's methods are called by the event-processing 37 39 framework with no action on the part of the programmer. … … 82 84 83 85 84 .. method:: async_chat._collect_incoming_data(data)85 86 Sample implementation of a data collection rutine to be used in conjunction87 with :meth:`_get_data` in a user-specified :meth:`found_terminator`.88 89 90 86 .. method:: async_chat.discard_buffers() 91 87 … … 102 98 103 99 104 .. method:: async_chat._get_data()105 106 Will return and clear the data received with the sample107 :meth:`_collect_incoming_data` implementation.108 109 110 100 .. method:: async_chat.get_terminator() 111 101 … … 113 103 114 104 115 .. method:: async_chat.handle_close()116 117 Called when the channel is closed. The default method silently closes the118 channel's socket.119 120 121 .. method:: async_chat.handle_read()122 123 Called when a read event fires on the channel's socket in the asynchronous124 loop. The default method checks for the termination condition established125 by :meth:`set_terminator`, which can be either the appearance of a126 particular string in the input stream or the receipt of a particular number127 of characters. When the terminator is found, :meth:`handle_read` calls the128 :meth:`found_terminator` method after calling :meth:`collect_incoming_data`129 with any data preceding the terminating condition.130 131 132 .. method:: async_chat.handle_write()133 134 Called when the application may write data to the channel. The default135 method calls the :meth:`initiate_send` method, which in turn will call136 :meth:`refill_buffer` to collect data from the producer fifo associated137 with the channel.138 139 140 105 .. method:: async_chat.push(data) 141 106 142 Creates a :class:`simple_producer` object (*see below*) containing the data 143 and pushes it on to the channel's ``producer_fifo`` to ensure its 144 transmission. This is all you need to do to have the channel write the 145 data out to the network, although it is possible to use your own producers 146 in more complex schemes to implement encryption and chunking, for example. 107 Pushes data on to the channel's fifo to ensure its transmission. 108 This is all you need to do to have the channel write the data out to the 109 network, although it is possible to use your own producers in more complex 110 schemes to implement encryption and chunking, for example. 147 111 148 112 … … 155 119 156 120 157 .. method:: async_chat.readable()158 159 Should return ``True`` for the channel to be included in the set of160 channels tested by the :cfunc:`select` loop for readability.161 162 163 .. method:: async_chat.refill_buffer()164 165 Refills the output buffer by calling the :meth:`more` method of the166 producer at the head of the fifo. If it is exhausted then the producer is167 popped off the fifo and the next producer is activated. If the current168 producer is, or becomes, ``None`` then the channel is closed.169 170 171 121 .. method:: async_chat.set_terminator(term) 172 122 … … 193 143 194 144 195 .. method:: async_chat.writable() 196 197 Should return ``True`` as long as items remain on the producer fifo, or the 198 channel is connected and the channel's output buffer is non-empty. 199 200 201 asynchat - Auxiliary Classes and Functions 145 asynchat - Auxiliary Classes 202 146 ------------------------------------------ 203 147 204 205 .. class:: simple_producer(data[, buffer_size=512])206 207 A :class:`simple_producer` takes a chunk of data and an optional buffer208 size. Repeated calls to its :meth:`more` method yield successive chunks of209 the data no larger than *buffer_size*.210 211 212 .. method:: more()213 214 Produces the next chunk of information from the producer, or returns the215 empty string.216 217 218 148 .. class:: fifo([list=None]) 219 149 220 Each channel maintains a :class:`fifo` holding data which has been pushed221 by the application but not yet popped for writing to the channel. A222 :class:`fifo` is a list used to hold data and/or producers until they are223 required. If the *list* argument is provided then it should contain224 producers or data items to bewritten to the channel.150 A :class:`fifo` holding data which has been pushed by the application but 151 not yet popped for writing to the channel. A :class:`fifo` is a list used 152 to hold data and/or producers until they are required. If the *list* 153 argument is provided then it should contain producers or data items to be 154 written to the channel. 225 155 226 156 … … 245 175 If the fifo is not empty, returns ``True, first()``, deleting the popped 246 176 item. Returns ``False, None`` for an empty fifo. 247 248 The :mod:`asynchat` module also defines one utility function, which may be of249 use in network and textual analysis operations.250 251 252 .. function:: find_prefix_at_end(haystack, needle)253 254 Returns ``True`` if string *haystack* ends with any non-empty prefix of255 string *needle*.256 177 257 178
Note:
See TracChangeset
for help on using the changeset viewer.