The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Doc / lib / libtelnetlib.tex
blobf28833ee2951e837f50f77d8f93df735fc5bb832
1 % LaTeX'ized from the comments in the module by Skip Montanaro
2 % <skip@mojam.com>.
4 \section{\module{telnetlib} ---
5 Telnet client}
7 \declaremodule{standard}{telnetlib}
8 \modulesynopsis{Telnet client class.}
11 The \module{telnetlib} module provides a \class{Telnet} class that
12 implements the Telnet protocol. See \rfc{854} for details about the
13 protocol.
16 \begin{classdesc}{Telnet}{\optional{host\optional{, port}}}
17 \class{Telnet} represents a connection to a telnet server. The
18 instance is initially not connected; the \method{open()} method must
19 be used to establish a connection. Alternatively, the host name and
20 optional port number can be passed to the constructor, too.
22 Do not reopen an already connected instance.
24 This class has many \method{read_*()} methods. Note that some of them
25 raise \exception{EOFError} when the end of the connection is read,
26 because they can return an empty string for other reasons. See the
27 individual descriptions below.
28 \end{classdesc}
31 \subsection{Telnet Objects \label{telnet-objects}}
33 \class{Telnet} instances have the following methods:
36 \begin{methoddesc}{read_until}{expected\optional{, timeout}}
37 Read until a given string is encountered or until timeout.
39 When no match is found, return whatever is available instead,
40 possibly the empty string. Raise \exception{EOFError} if the connection
41 is closed and no cooked data is available.
42 \end{methoddesc}
44 \begin{methoddesc}{read_all}{}
45 Read all data until \EOF{}; block until connection closed.
46 \end{methoddesc}
48 \begin{methoddesc}{read_some}{}
49 Read at least one byte of cooked data unless \EOF{} is hit.
50 Return \code{''} if \EOF{} is hit. Block if no data is immediately
51 available.
52 \end{methoddesc}
54 \begin{methoddesc}{read_very_eager}{}
55 Read everything that can be without blocking in I/O (eager).
57 Raise \exception{EOFError} if connection closed and no cooked data
58 available. Return \code{''} if no cooked data available otherwise.
59 Do not block unless in the midst of an IAC sequence.
60 \end{methoddesc}
62 \begin{methoddesc}{read_eager}{}
63 Read readily available data.
65 Raise \exception{EOFError} if connection closed and no cooked data
66 available. Return \code{''} if no cooked data available otherwise.
67 Do not block unless in the midst of an IAC sequence.
68 \end{methoddesc}
70 \begin{methoddesc}{read_lazy}{}
71 Process and return data already in the queues (lazy).
73 Raise \exception{EOFError} if connection closed and no data available.
74 Return \code{''} if no cooked data available otherwise. Do not block
75 unless in the midst of an IAC sequence.
76 \end{methoddesc}
78 \begin{methoddesc}{read_very_lazy}{}
79 Return any data available in the cooked queue (very lazy).
81 Raise \exception{EOFError} if connection closed and no data available.
82 Return \code{''} if no cooked data available otherwise. This method
83 never blocks.
84 \end{methoddesc}
86 \begin{methoddesc}{open}{host\optional{, port}}
87 Connect to a host.
88 The optional second argument is the port number, which
89 defaults to the standard telnet port (23).
91 Do not try to reopen an already connected instance.
92 \end{methoddesc}
94 \begin{methoddesc}{msg}{msg\optional{, *args}}
95 Print a debug message when the debug level is \code{>} 0.
96 If extra arguments are present, they are substituted in the
97 message using the standard string formatting operator.
98 \end{methoddesc}
100 \begin{methoddesc}{set_debuglevel}{debuglevel}
101 Set the debug level. The higher the value of \var{debuglevel}, the
102 more debug output you get (on \code{sys.stdout}).
103 \end{methoddesc}
105 \begin{methoddesc}{close}{}
106 Close the connection.
107 \end{methoddesc}
109 \begin{methoddesc}{get_socket}{}
110 Return the socket object used internally.
111 \end{methoddesc}
113 \begin{methoddesc}{fileno}{}
114 Return the file descriptor of the socket object used internally.
115 \end{methoddesc}
117 \begin{methoddesc}{write}{buffer}
118 Write a string to the socket, doubling any IAC characters.
119 This can block if the connection is blocked. May raise
120 \exception{socket.error} if the connection is closed.
121 \end{methoddesc}
123 \begin{methoddesc}{interact}{}
124 Interaction function, emulates a very dumb telnet client.
125 \end{methoddesc}
127 \begin{methoddesc}{mt_interact}{}
128 Multithreaded version of \method{interact()}.
129 \end{methoddesc}
131 \begin{methoddesc}{expect}{list\optional{, timeout}}
132 Read until one from a list of a regular expressions matches.
134 The first argument is a list of regular expressions, either
135 compiled (\class{re.RegexObject} instances) or uncompiled (strings).
136 The optional second argument is a timeout, in seconds; the default
137 is to block indefinately.
139 Return a tuple of three items: the index in the list of the
140 first regular expression that matches; the match object
141 returned; and the text read up till and including the match.
143 If end of file is found and no text was read, raise
144 \exception{EOFError}. Otherwise, when nothing matches, return
145 \code{(-1, None, \var{text})} where \var{text} is the text received so
146 far (may be the empty string if a timeout happened).
148 If a regular expression ends with a greedy match (e.g. \regexp{.*})
149 or if more than one expression can match the same input, the
150 results are undeterministic, and may depend on the I/O timing.
151 \end{methoddesc}