<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"telnet-example.html" />
<link rel=
"prev" href=
"module-telnetlib.html" />
<link rel=
"parent" href=
"module-telnetlib.html" />
<link rel=
"next" href=
"telnet-example.html" />
<meta name='aesop' content='information'
/>
<title>11.14.1 Telnet Objects
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.14 telnetlib "
href=
"module-telnetlib.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11.14 telnetlib "
href=
"module-telnetlib.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.14.2 Telnet Example"
href=
"telnet-example.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-telnetlib.html">11.14 telnetlib
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"module-telnetlib.html">11.14 telnetlib
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"telnet-example.html">11.14.2 Telnet Example
</A>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION00131410000000000000000"></A><A NAME=
"telnet-objects"></A>
<tt class=
"class">Telnet
</tt> instances have the following methods:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3518' xml:id='l2h-
3518'
class=
"method">read_until
</tt></b>(
</nobr></td>
<td><var>expected
</var><big>[
</big><var>, timeout
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Read until a given string,
<var>expected
</var>, is encountered or until
<var>timeout
</var> seconds have passed.
When no match is found, return whatever is available instead,
possibly the empty string. Raise
<tt class=
"exception">EOFError
</tt> if the connection
is closed and no cooked data is available.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3519' xml:id='l2h-
3519'
class=
"method">read_all
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Read all data until EOF; block until connection closed.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3520' xml:id='l2h-
3520'
class=
"method">read_some
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Read at least one byte of cooked data unless EOF is hit.
Return
<code>''
</code> if EOF is hit. Block if no data is immediately
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3521' xml:id='l2h-
3521'
class=
"method">read_very_eager
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Read everything that can be without blocking in I/O (eager).
Raise
<tt class=
"exception">EOFError
</tt> if connection closed and no cooked data
available. Return
<code>''
</code> if no cooked data available otherwise.
Do not block unless in the midst of an IAC sequence.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3522' xml:id='l2h-
3522'
class=
"method">read_eager
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Read readily available data.
Raise
<tt class=
"exception">EOFError
</tt> if connection closed and no cooked data
available. Return
<code>''
</code> if no cooked data available otherwise.
Do not block unless in the midst of an IAC sequence.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3523' xml:id='l2h-
3523'
class=
"method">read_lazy
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Process and return data already in the queues (lazy).
Raise
<tt class=
"exception">EOFError
</tt> if connection closed and no data available.
Return
<code>''
</code> if no cooked data available otherwise. Do not block
unless in the midst of an IAC sequence.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3524' xml:id='l2h-
3524'
class=
"method">read_very_lazy
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return any data available in the cooked queue (very lazy).
Raise
<tt class=
"exception">EOFError
</tt> if connection closed and no data available.
Return
<code>''
</code> if no cooked data available otherwise. This method
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3525' xml:id='l2h-
3525'
class=
"method">read_sb_data
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the data collected between a SB/SE pair (suboption begin/end).
The callback should access these data when it was invoked with a
<code>SE
</code> command. This method never blocks.
<span class=
"versionnote">New in version
2.3.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3526' xml:id='l2h-
3526'
class=
"method">open
</tt></b>(
</nobr></td>
<td><var>host
</var><big>[
</big><var>, port
</var><big>]
</big><var></var>)
</td></tr></table></dt>
The optional second argument is the port number, which
defaults to the standard Telnet port (
23).
Do not try to reopen an already connected instance.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3527' xml:id='l2h-
3527'
class=
"method">msg
</tt></b>(
</nobr></td>
<td><var>msg
</var><big>[
</big><var>, *args
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Print a debug message when the debug level is
<code>></code> 0.
If extra arguments are present, they are substituted in the
message using the standard string formatting operator.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3528' xml:id='l2h-
3528'
class=
"method">set_debuglevel
</tt></b>(
</nobr></td>
<td><var>debuglevel
</var>)
</td></tr></table></dt>
Set the debug level. The higher the value of
<var>debuglevel
</var>, the
more debug output you get (on
<code>sys.stdout
</code>).
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3529' xml:id='l2h-
3529'
class=
"method">close
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3530' xml:id='l2h-
3530'
class=
"method">get_socket
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the socket object used internally.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3531' xml:id='l2h-
3531'
class=
"method">fileno
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return the file descriptor of the socket object used internally.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3532' xml:id='l2h-
3532'
class=
"method">write
</tt></b>(
</nobr></td>
<td><var>buffer
</var>)
</td></tr></table></dt>
Write a string to the socket, doubling any IAC characters.
This can block if the connection is blocked. May raise
<tt class=
"exception">socket.error
</tt> if the connection is closed.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3533' xml:id='l2h-
3533'
class=
"method">interact
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Interaction function, emulates a very dumb Telnet client.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3534' xml:id='l2h-
3534'
class=
"method">mt_interact
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Multithreaded version of
<tt class=
"method">interact()
</tt>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3535' xml:id='l2h-
3535'
class=
"method">expect
</tt></b>(
</nobr></td>
<td><var>list
</var><big>[
</big><var>, timeout
</var><big>]
</big><var></var>)
</td></tr></table></dt>
Read until one from a list of a regular expressions matches.
The first argument is a list of regular expressions, either
compiled (
<tt class=
"class">re.RegexObject
</tt> instances) or uncompiled (strings).
The optional second argument is a timeout, in seconds; the default
is to block indefinitely.
Return a tuple of three items: the index in the list of the
first regular expression that matches; the match object
returned; and the text read up till and including the match.
If end of file is found and no text was read, raise
<tt class=
"exception">EOFError
</tt>. Otherwise, when nothing matches, return
<code>(-
1, None,
<var>text
</var>)
</code> where
<var>text
</var> is the text received so
far (may be the empty string if a timeout happened).
If a regular expression ends with a greedy match (such as
<tt class=
"regexp">.*
</tt>)
or if more than one expression can match the same input, the
results are indeterministic, and may depend on the I/O timing.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3536' xml:id='l2h-
3536'
class=
"method">set_option_negotiation_callback
</tt></b>(
</nobr></td>
<td><var>callback
</var>)
</td></tr></table></dt>
Each time a telnet option is read on the input flow, this
<var>callback
</var> (if set) is called with the following parameters :
callback(telnet socket, command (DO/DONT/WILL/WONT), option). No other
action is done afterwards by telnetlib.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.14 telnetlib "
href=
"module-telnetlib.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11.14 telnetlib "
href=
"module-telnetlib.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.14.2 Telnet Example"
href=
"telnet-example.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-telnetlib.html">11.14 telnetlib
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"module-telnetlib.html">11.14 telnetlib
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"telnet-example.html">11.14.2 Telnet Example
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.