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