|
25 | 25 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
26 | 26 | # ====================================================================== |
27 | 27 |
|
| 28 | +"""A class supporting chat-style (command/response) protocols. |
| 29 | +
|
| 30 | +This class adds support for 'chat' style protocols - where one side |
| 31 | +sends a 'command', and the other sends a response (examples would be |
| 32 | +the common internet protocols - smtp, nntp, ftp, etc..). |
| 33 | +
|
| 34 | +The handle_read() method looks at the input stream for the current |
| 35 | +'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n' |
| 36 | +for multi-line output), calling self.found_terminator() on its |
| 37 | +receipt. |
| 38 | +
|
| 39 | +for example: |
| 40 | +Say you build an async nntp client using this class. At the start |
| 41 | +of the connection, you'll have self.terminator set to '\r\n', in |
| 42 | +order to process the single-line greeting. Just before issuing a |
| 43 | +'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST |
| 44 | +command will be accumulated (using your own 'collect_incoming_data' |
| 45 | +method) up to the terminator, and then control will be returned to |
| 46 | +you - by calling your self.found_terminator() method. |
| 47 | +""" |
| 48 | + |
28 | 49 | import socket |
29 | 50 | import asyncore |
30 | 51 | import string |
31 | 52 |
|
32 | | -# This class adds support for 'chat' style protocols - where one side |
33 | | -# sends a 'command', and the other sends a response (examples would be |
34 | | -# the common internet protocols - smtp, nntp, ftp, etc..). |
35 | | - |
36 | | -# The handle_read() method looks at the input stream for the current |
37 | | -# 'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n' |
38 | | -# for multi-line output), calling self.found_terminator() on its |
39 | | -# receipt. |
40 | | - |
41 | | -# for example: |
42 | | -# Say you build an async nntp client using this class. At the start |
43 | | -# of the connection, you'll have self.terminator set to '\r\n', in |
44 | | -# order to process the single-line greeting. Just before issuing a |
45 | | -# 'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST |
46 | | -# command will be accumulated (using your own 'collect_incoming_data' |
47 | | -# method) up to the terminator, and then control will be returned to |
48 | | -# you - by calling your self.found_terminator() method |
49 | | - |
50 | 53 | class async_chat (asyncore.dispatcher): |
51 | 54 | """This is an abstract class. You must derive from this class, and add |
52 | 55 | the two methods collect_incoming_data() and found_terminator()""" |
|
0 commit comments