blob: f28833ee2951e837f50f77d8f93df735fc5bb832 [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
Fred Drakeb7168c31999-04-22 17:53:37 +000016\begin{classdesc}{Telnet}{\optional{host\optional{, port}}}
Fred Drake658cef01999-03-15 15:44:18 +000017\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
Fred Drakeb7168c31999-04-22 17:53:37 +000027individual descriptions below.
Fred Drake658cef01999-03-15 15:44:18 +000028\end{classdesc}
29
30
31\subsection{Telnet Objects \label{telnet-objects}}
32
33\class{Telnet} instances have the following methods:
34
35
Fred Drakeb7168c31999-04-22 17:53:37 +000036\begin{methoddesc}{read_until}{expected\optional{, timeout}}
Fred Drake658cef01999-03-15 15:44:18 +000037Read 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
Fred Drakeb7168c31999-04-22 17:53:37 +000044\begin{methoddesc}{read_all}{}
45Read all data until \EOF{}; block until connection closed.
Fred Drake658cef01999-03-15 15:44:18 +000046\end{methoddesc}
47
Fred Drakeb7168c31999-04-22 17:53:37 +000048\begin{methoddesc}{read_some}{}
49Read at least one byte of cooked data unless \EOF{} is hit.
50Return \code{''} if \EOF{} is hit. Block if no data is immediately
51available.
Fred Drake658cef01999-03-15 15:44:18 +000052\end{methoddesc}
53
Fred Drakeb7168c31999-04-22 17:53:37 +000054\begin{methoddesc}{read_very_eager}{}
55Read everything that can be without blocking in I/O (eager).
Fred Drake658cef01999-03-15 15:44:18 +000056
57Raise \exception{EOFError} if connection closed and no cooked data
58available. Return \code{''} if no cooked data available otherwise.
Fred Drakeb7168c31999-04-22 17:53:37 +000059Do not block unless in the midst of an IAC sequence.
Fred Drake658cef01999-03-15 15:44:18 +000060\end{methoddesc}
61
Fred Drakeb7168c31999-04-22 17:53:37 +000062\begin{methoddesc}{read_eager}{}
Fred Drake658cef01999-03-15 15:44:18 +000063Read readily available data.
64
65Raise \exception{EOFError} if connection closed and no cooked data
66available. Return \code{''} if no cooked data available otherwise.
Fred Drakeb7168c31999-04-22 17:53:37 +000067Do not block unless in the midst of an IAC sequence.
Fred Drake658cef01999-03-15 15:44:18 +000068\end{methoddesc}
69
Fred Drakeb7168c31999-04-22 17:53:37 +000070\begin{methoddesc}{read_lazy}{}
71Process and return data already in the queues (lazy).
Fred Drake658cef01999-03-15 15:44:18 +000072
73Raise \exception{EOFError} if connection closed and no data available.
Fred Drakeb7168c31999-04-22 17:53:37 +000074Return \code{''} if no cooked data available otherwise. Do not block
Fred Drake658cef01999-03-15 15:44:18 +000075unless in the midst of an IAC sequence.
76\end{methoddesc}
77
Fred Drakeb7168c31999-04-22 17:53:37 +000078\begin{methoddesc}{read_very_lazy}{}
Fred Drake658cef01999-03-15 15:44:18 +000079Return any data available in the cooked queue (very lazy).
80
81Raise \exception{EOFError} if connection closed and no data available.
Fred Drakeb7168c31999-04-22 17:53:37 +000082Return \code{''} if no cooked data available otherwise. This method
83never blocks.
Fred Drake658cef01999-03-15 15:44:18 +000084\end{methoddesc}
85
Fred Drakeb7168c31999-04-22 17:53:37 +000086\begin{methoddesc}{open}{host\optional{, port}}
Fred Drake658cef01999-03-15 15:44:18 +000087Connect to a host.
Fred Drake658cef01999-03-15 15:44:18 +000088The optional second argument is the port number, which
89defaults to the standard telnet port (23).
90
Fred Drakeb7168c31999-04-22 17:53:37 +000091Do not try to reopen an already connected instance.
Fred Drake658cef01999-03-15 15:44:18 +000092\end{methoddesc}
93
Fred Drakeb7168c31999-04-22 17:53:37 +000094\begin{methoddesc}{msg}{msg\optional{, *args}}
95Print a debug message when the debug level is \code{>} 0.
Fred Drake658cef01999-03-15 15:44:18 +000096If extra arguments are present, they are substituted in the
97message using the standard string formatting operator.
98\end{methoddesc}
99
Fred Drakeb7168c31999-04-22 17:53:37 +0000100\begin{methoddesc}{set_debuglevel}{debuglevel}
101Set the debug level. The higher the value of \var{debuglevel}, the
102more debug output you get (on \code{sys.stdout}).
Fred Drake658cef01999-03-15 15:44:18 +0000103\end{methoddesc}
104
Fred Drakeb7168c31999-04-22 17:53:37 +0000105\begin{methoddesc}{close}{}
Fred Drake658cef01999-03-15 15:44:18 +0000106Close the connection.
107\end{methoddesc}
108
Fred Drakeb7168c31999-04-22 17:53:37 +0000109\begin{methoddesc}{get_socket}{}
Fred Drake658cef01999-03-15 15:44:18 +0000110Return the socket object used internally.
111\end{methoddesc}
112
Fred Drakeb7168c31999-04-22 17:53:37 +0000113\begin{methoddesc}{fileno}{}
114Return the file descriptor of the socket object used internally.
Fred Drake658cef01999-03-15 15:44:18 +0000115\end{methoddesc}
116
Fred Drakeb7168c31999-04-22 17:53:37 +0000117\begin{methoddesc}{write}{buffer}
Fred Drake658cef01999-03-15 15:44:18 +0000118Write a string to the socket, doubling any IAC characters.
Fred Drakeb7168c31999-04-22 17:53:37 +0000119This can block if the connection is blocked. May raise
120\exception{socket.error} if the connection is closed.
Fred Drake658cef01999-03-15 15:44:18 +0000121\end{methoddesc}
122
Fred Drakeb7168c31999-04-22 17:53:37 +0000123\begin{methoddesc}{interact}{}
Fred Drake658cef01999-03-15 15:44:18 +0000124Interaction function, emulates a very dumb telnet client.
125\end{methoddesc}
126
Fred Drakeb7168c31999-04-22 17:53:37 +0000127\begin{methoddesc}{mt_interact}{}
128Multithreaded version of \method{interact()}.
Fred Drake658cef01999-03-15 15:44:18 +0000129\end{methoddesc}
130
Fred Drakeb7168c31999-04-22 17:53:37 +0000131\begin{methoddesc}{expect}{list\optional{, timeout}}
Fred Drake658cef01999-03-15 15:44:18 +0000132Read until one from a list of a regular expressions matches.
133
134The first argument is a list of regular expressions, either
135compiled (\class{re.RegexObject} instances) or uncompiled (strings).
Fred Drakeb7168c31999-04-22 17:53:37 +0000136The optional second argument is a timeout, in seconds; the default
137is to block indefinately.
Fred Drake658cef01999-03-15 15:44:18 +0000138
139Return a tuple of three items: the index in the list of the
140first regular expression that matches; the match object
141returned; and the text read up till and including the match.
142
143If 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
146far (may be the empty string if a timeout happened).
147
148If a regular expression ends with a greedy match (e.g. \regexp{.*})
149or if more than one expression can match the same input, the
150results are undeterministic, and may depend on the I/O timing.
151\end{methoddesc}