2007-08-15 11:28:22 -03:00
|
|
|
:mod:`telnetlib` --- Telnet client
|
|
|
|
==================================
|
|
|
|
|
|
|
|
.. module:: telnetlib
|
|
|
|
:synopsis: Telnet client class.
|
Merged revisions 59407-59422 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59407 | armin.rigo | 2007-12-07 20:19:55 +0100 (Fri, 07 Dec 2007) | 2 lines
This is probably what was meant here.
........
r59410 | guido.van.rossum | 2007-12-08 05:38:23 +0100 (Sat, 08 Dec 2007) | 2 lines
Be (just a bit :) more specific about release date.
........
r59411 | alexandre.vassalotti | 2007-12-08 05:49:22 +0100 (Sat, 08 Dec 2007) | 3 lines
Fix issue #1530.
Return an error exit status if not all tests passes.
........
r59413 | georg.brandl | 2007-12-08 11:56:39 +0100 (Sat, 08 Dec 2007) | 2 lines
Fix tpyo.
........
r59414 | georg.brandl | 2007-12-08 12:05:05 +0100 (Sat, 08 Dec 2007) | 2 lines
Fix markup in whatsnew, use new directive in ACKS.
........
r59415 | georg.brandl | 2007-12-08 12:05:36 +0100 (Sat, 08 Dec 2007) | 2 lines
Fix Eren's name.
........
r59416 | georg.brandl | 2007-12-08 12:23:13 +0100 (Sat, 08 Dec 2007) | 2 lines
Add examples to the datetime documentation. Written for GHOP by "h4wk.cz".
........
r59417 | skip.montanaro | 2007-12-08 15:37:43 +0100 (Sat, 08 Dec 2007) | 2 lines
Note that open() is the preferred way to open files (issue 1510).
........
r59418 | skip.montanaro | 2007-12-08 16:23:31 +0100 (Sat, 08 Dec 2007) | 1 line
+ "context manager"
........
r59419 | skip.montanaro | 2007-12-08 16:26:16 +0100 (Sat, 08 Dec 2007) | 1 line
correct email address
........
r59420 | skip.montanaro | 2007-12-08 16:33:24 +0100 (Sat, 08 Dec 2007) | 3 lines
When splitting, avoid making a copy of the string if the split doesn't find
anything (issue 1538).
........
2007-12-08 13:28:33 -04:00
|
|
|
.. sectionauthor:: Skip Montanaro <skip@pobox.com>
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. index:: single: protocol; Telnet
|
|
|
|
|
|
|
|
The :mod:`telnetlib` module provides a :class:`Telnet` class that implements the
|
|
|
|
Telnet protocol. See :rfc:`854` for details about the protocol. In addition, it
|
|
|
|
provides symbolic constants for the protocol characters (see below), and for the
|
|
|
|
telnet options. The symbolic names of the telnet options follow the definitions
|
|
|
|
in ``arpa/telnet.h``, with the leading ``TELOPT_`` removed. For symbolic names
|
|
|
|
of options which are traditionally not included in ``arpa/telnet.h``, see the
|
|
|
|
module source itself.
|
|
|
|
|
|
|
|
The symbolic constants for the telnet commands are: IAC, DONT, DO, WONT, WILL,
|
|
|
|
SE (Subnegotiation End), NOP (No Operation), DM (Data Mark), BRK (Break), IP
|
|
|
|
(Interrupt process), AO (Abort output), AYT (Are You There), EC (Erase
|
|
|
|
Character), EL (Erase Line), GA (Go Ahead), SB (Subnegotiation Begin).
|
|
|
|
|
|
|
|
|
Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r74821 | georg.brandl | 2009-09-16 11:42:19 +0200 (Mi, 16 Sep 2009) | 1 line
#6885: run python 3 as python3.
................
r74828 | georg.brandl | 2009-09-16 16:23:20 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74829 | georg.brandl | 2009-09-16 16:24:29 +0200 (Mi, 16 Sep 2009) | 1 line
Small PEP8 correction.
................
r74830 | georg.brandl | 2009-09-16 16:36:22 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74831 | georg.brandl | 2009-09-16 17:54:04 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans and PEP8 for argdefaults.
................
r74833 | georg.brandl | 2009-09-16 17:58:14 +0200 (Mi, 16 Sep 2009) | 1 line
Last round of adapting style of documenting argument default values.
................
r74835 | georg.brandl | 2009-09-16 18:00:31 +0200 (Mi, 16 Sep 2009) | 33 lines
Merged revisions 74817-74820,74822-74824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74817 | georg.brandl | 2009-09-16 11:05:11 +0200 (Mi, 16 Sep 2009) | 1 line
Make deprecation notices as visible as warnings are right now.
........
r74818 | georg.brandl | 2009-09-16 11:23:04 +0200 (Mi, 16 Sep 2009) | 1 line
#6880: add reference to classes section in exceptions section, which comes earlier.
........
r74819 | georg.brandl | 2009-09-16 11:24:57 +0200 (Mi, 16 Sep 2009) | 1 line
#6876: fix base class constructor invocation in example.
........
r74820 | georg.brandl | 2009-09-16 11:30:48 +0200 (Mi, 16 Sep 2009) | 1 line
#6891: comment out dead link to Unicode article.
........
r74822 | georg.brandl | 2009-09-16 12:12:06 +0200 (Mi, 16 Sep 2009) | 1 line
#5621: refactor description of how class/instance attributes interact on a.x=a.x+1 or augassign.
........
r74823 | georg.brandl | 2009-09-16 15:06:22 +0200 (Mi, 16 Sep 2009) | 1 line
Remove strange trailing commas.
........
r74824 | georg.brandl | 2009-09-16 15:11:06 +0200 (Mi, 16 Sep 2009) | 1 line
#6892: fix optparse example involving help option.
........
................
2009-09-16 13:05:59 -03:00
|
|
|
.. class:: Telnet(host=None, port=0[, timeout])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
:class:`Telnet` represents a connection to a Telnet server. The instance is
|
|
|
|
initially not connected by default; the :meth:`open` method must be used to
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
establish a connection. Alternatively, the host name and optional port
|
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines
Patch #1722225: Support QNX 6.
........
r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line
Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo.
........
r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines
Fix issue2589: there was a potential integer overflow leading to
memory corruption on esoteric platforms and incorrect behavior on
normal platforms.
........
r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines
Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is
passed in. (The assert won't prevent this in non-debug builds).
........
r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line
Fix two typos.
........
r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines
Fixed the semantic of timeout for socket.create_connection and
all the upper level libraries that use it, including urllib2.
Added and fixed some tests, and changed docs correspondingly.
Thanks to John J Lee for the patch and the pusing, :)
........
r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines
Fix typo in testSum
........
r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines
* Mark intermedidate computes values (hi, lo, yr) as volatile.
* Expand comments.
* Swap variable names in the sum_exact code so that x and y
are consistently chosen as the larger and smaller magnitude
values respectively.
........
r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line
Implement heapq in terms of less-than (to match list.sort()).
........
r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines
Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
........
r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines
Fix issue 2782: be less strict about the format string type in strftime.
Accept unicode and anything else ParseTuple "s#" can deal with. This
matches the time.strftime behavior.
........
r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines
Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3.
(I didn't regen configure, since I don't have a working autoconf.)
........
r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line
Issue 3501: Make heapq support both __le__ and __lt__.
........
2008-06-10 14:40:04 -03:00
|
|
|
and timeout can be passed to the constructor, in which case the connection to
|
|
|
|
the server will be established before the constructor returns. The optional
|
|
|
|
*timeout* parameter specifies a timeout in seconds for the connection attempt (if
|
|
|
|
not specified, the global default timeout setting will be used).
|
|
|
|
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
number can be passed to the constructor, to, in which case the connection to
|
|
|
|
the server will be established before the constructor returns. The optional
|
|
|
|
*timeout* parameter specifies a timeout in seconds for blocking operations
|
|
|
|
like the connection attempt (if not specified, or passed as None, the global
|
|
|
|
default timeout setting will be used).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Do not reopen an already connected instance.
|
|
|
|
|
|
|
|
This class has many :meth:`read_\*` methods. Note that some of them raise
|
|
|
|
:exc:`EOFError` when the end of the connection is read, because they can return
|
|
|
|
an empty string for other reasons. See the individual descriptions below.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:rfc:`854` - Telnet Protocol Specification
|
|
|
|
Definition of the Telnet protocol.
|
|
|
|
|
|
|
|
|
|
|
|
.. _telnet-objects:
|
|
|
|
|
|
|
|
Telnet Objects
|
|
|
|
--------------
|
|
|
|
|
|
|
|
:class:`Telnet` instances have the following methods:
|
|
|
|
|
|
|
|
|
Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r74821 | georg.brandl | 2009-09-16 11:42:19 +0200 (Mi, 16 Sep 2009) | 1 line
#6885: run python 3 as python3.
................
r74828 | georg.brandl | 2009-09-16 16:23:20 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74829 | georg.brandl | 2009-09-16 16:24:29 +0200 (Mi, 16 Sep 2009) | 1 line
Small PEP8 correction.
................
r74830 | georg.brandl | 2009-09-16 16:36:22 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74831 | georg.brandl | 2009-09-16 17:54:04 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans and PEP8 for argdefaults.
................
r74833 | georg.brandl | 2009-09-16 17:58:14 +0200 (Mi, 16 Sep 2009) | 1 line
Last round of adapting style of documenting argument default values.
................
r74835 | georg.brandl | 2009-09-16 18:00:31 +0200 (Mi, 16 Sep 2009) | 33 lines
Merged revisions 74817-74820,74822-74824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74817 | georg.brandl | 2009-09-16 11:05:11 +0200 (Mi, 16 Sep 2009) | 1 line
Make deprecation notices as visible as warnings are right now.
........
r74818 | georg.brandl | 2009-09-16 11:23:04 +0200 (Mi, 16 Sep 2009) | 1 line
#6880: add reference to classes section in exceptions section, which comes earlier.
........
r74819 | georg.brandl | 2009-09-16 11:24:57 +0200 (Mi, 16 Sep 2009) | 1 line
#6876: fix base class constructor invocation in example.
........
r74820 | georg.brandl | 2009-09-16 11:30:48 +0200 (Mi, 16 Sep 2009) | 1 line
#6891: comment out dead link to Unicode article.
........
r74822 | georg.brandl | 2009-09-16 12:12:06 +0200 (Mi, 16 Sep 2009) | 1 line
#5621: refactor description of how class/instance attributes interact on a.x=a.x+1 or augassign.
........
r74823 | georg.brandl | 2009-09-16 15:06:22 +0200 (Mi, 16 Sep 2009) | 1 line
Remove strange trailing commas.
........
r74824 | georg.brandl | 2009-09-16 15:11:06 +0200 (Mi, 16 Sep 2009) | 1 line
#6892: fix optparse example involving help option.
........
................
2009-09-16 13:05:59 -03:00
|
|
|
.. method:: Telnet.read_until(expected, timeout=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Read until a given byte string, *expected*, is encountered or until *timeout*
|
|
|
|
seconds have passed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
When no match is found, return whatever is available instead, possibly empty
|
|
|
|
bytes. Raise :exc:`EOFError` if the connection is closed and no cooked data
|
|
|
|
is available.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_all()
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Read all data until EOF as bytes; block until connection closed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_some()
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Read at least one byte of cooked data unless EOF is hit. Return ``b''`` if
|
|
|
|
EOF is hit. Block if no data is immediately available.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_very_eager()
|
|
|
|
|
|
|
|
Read everything that can be without blocking in I/O (eager).
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Raise :exc:`EOFError` if connection closed and no cooked data available.
|
|
|
|
Return ``b''`` if no cooked data available otherwise. Do not block unless in
|
|
|
|
the midst of an IAC sequence.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_eager()
|
|
|
|
|
|
|
|
Read readily available data.
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Raise :exc:`EOFError` if connection closed and no cooked data available.
|
|
|
|
Return ``b''`` if no cooked data available otherwise. Do not block unless in
|
|
|
|
the midst of an IAC sequence.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_lazy()
|
|
|
|
|
|
|
|
Process and return data already in the queues (lazy).
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Raise :exc:`EOFError` if connection closed and no data available. Return
|
|
|
|
``b''`` if no cooked data available otherwise. Do not block unless in the
|
|
|
|
midst of an IAC sequence.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_very_lazy()
|
|
|
|
|
|
|
|
Return any data available in the cooked queue (very lazy).
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Raise :exc:`EOFError` if connection closed and no data available. Return
|
|
|
|
``b''`` if no cooked data available otherwise. This method never blocks.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.read_sb_data()
|
|
|
|
|
|
|
|
Return the data collected between a SB/SE pair (suboption begin/end). The
|
|
|
|
callback should access these data when it was invoked with a ``SE`` command.
|
|
|
|
This method never blocks.
|
|
|
|
|
|
|
|
|
Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r74821 | georg.brandl | 2009-09-16 11:42:19 +0200 (Mi, 16 Sep 2009) | 1 line
#6885: run python 3 as python3.
................
r74828 | georg.brandl | 2009-09-16 16:23:20 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74829 | georg.brandl | 2009-09-16 16:24:29 +0200 (Mi, 16 Sep 2009) | 1 line
Small PEP8 correction.
................
r74830 | georg.brandl | 2009-09-16 16:36:22 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74831 | georg.brandl | 2009-09-16 17:54:04 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans and PEP8 for argdefaults.
................
r74833 | georg.brandl | 2009-09-16 17:58:14 +0200 (Mi, 16 Sep 2009) | 1 line
Last round of adapting style of documenting argument default values.
................
r74835 | georg.brandl | 2009-09-16 18:00:31 +0200 (Mi, 16 Sep 2009) | 33 lines
Merged revisions 74817-74820,74822-74824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74817 | georg.brandl | 2009-09-16 11:05:11 +0200 (Mi, 16 Sep 2009) | 1 line
Make deprecation notices as visible as warnings are right now.
........
r74818 | georg.brandl | 2009-09-16 11:23:04 +0200 (Mi, 16 Sep 2009) | 1 line
#6880: add reference to classes section in exceptions section, which comes earlier.
........
r74819 | georg.brandl | 2009-09-16 11:24:57 +0200 (Mi, 16 Sep 2009) | 1 line
#6876: fix base class constructor invocation in example.
........
r74820 | georg.brandl | 2009-09-16 11:30:48 +0200 (Mi, 16 Sep 2009) | 1 line
#6891: comment out dead link to Unicode article.
........
r74822 | georg.brandl | 2009-09-16 12:12:06 +0200 (Mi, 16 Sep 2009) | 1 line
#5621: refactor description of how class/instance attributes interact on a.x=a.x+1 or augassign.
........
r74823 | georg.brandl | 2009-09-16 15:06:22 +0200 (Mi, 16 Sep 2009) | 1 line
Remove strange trailing commas.
........
r74824 | georg.brandl | 2009-09-16 15:11:06 +0200 (Mi, 16 Sep 2009) | 1 line
#6892: fix optparse example involving help option.
........
................
2009-09-16 13:05:59 -03:00
|
|
|
.. method:: Telnet.open(host, port=0[, timeout])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Connect to a host. The optional second argument is the port number, which
|
|
|
|
defaults to the standard Telnet port (23). The optional *timeout* parameter
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
specifies a timeout in seconds for blocking operations like the connection
|
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines
Patch #1722225: Support QNX 6.
........
r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line
Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo.
........
r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines
Fix issue2589: there was a potential integer overflow leading to
memory corruption on esoteric platforms and incorrect behavior on
normal platforms.
........
r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines
Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is
passed in. (The assert won't prevent this in non-debug builds).
........
r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line
Fix two typos.
........
r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines
Fixed the semantic of timeout for socket.create_connection and
all the upper level libraries that use it, including urllib2.
Added and fixed some tests, and changed docs correspondingly.
Thanks to John J Lee for the patch and the pusing, :)
........
r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines
Fix typo in testSum
........
r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines
* Mark intermedidate computes values (hi, lo, yr) as volatile.
* Expand comments.
* Swap variable names in the sum_exact code so that x and y
are consistently chosen as the larger and smaller magnitude
values respectively.
........
r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line
Implement heapq in terms of less-than (to match list.sort()).
........
r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines
Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
........
r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines
Fix issue 2782: be less strict about the format string type in strftime.
Accept unicode and anything else ParseTuple "s#" can deal with. This
matches the time.strftime behavior.
........
r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines
Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3.
(I didn't regen configure, since I don't have a working autoconf.)
........
r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line
Issue 3501: Make heapq support both __le__ and __lt__.
........
2008-06-10 14:40:04 -03:00
|
|
|
attempt (if not specified, the global default timeout setting will be used).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Do not try to reopen an already connected instance.
|
|
|
|
|
|
|
|
|
Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r74821 | georg.brandl | 2009-09-16 11:42:19 +0200 (Mi, 16 Sep 2009) | 1 line
#6885: run python 3 as python3.
................
r74828 | georg.brandl | 2009-09-16 16:23:20 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74829 | georg.brandl | 2009-09-16 16:24:29 +0200 (Mi, 16 Sep 2009) | 1 line
Small PEP8 correction.
................
r74830 | georg.brandl | 2009-09-16 16:36:22 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74831 | georg.brandl | 2009-09-16 17:54:04 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans and PEP8 for argdefaults.
................
r74833 | georg.brandl | 2009-09-16 17:58:14 +0200 (Mi, 16 Sep 2009) | 1 line
Last round of adapting style of documenting argument default values.
................
r74835 | georg.brandl | 2009-09-16 18:00:31 +0200 (Mi, 16 Sep 2009) | 33 lines
Merged revisions 74817-74820,74822-74824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74817 | georg.brandl | 2009-09-16 11:05:11 +0200 (Mi, 16 Sep 2009) | 1 line
Make deprecation notices as visible as warnings are right now.
........
r74818 | georg.brandl | 2009-09-16 11:23:04 +0200 (Mi, 16 Sep 2009) | 1 line
#6880: add reference to classes section in exceptions section, which comes earlier.
........
r74819 | georg.brandl | 2009-09-16 11:24:57 +0200 (Mi, 16 Sep 2009) | 1 line
#6876: fix base class constructor invocation in example.
........
r74820 | georg.brandl | 2009-09-16 11:30:48 +0200 (Mi, 16 Sep 2009) | 1 line
#6891: comment out dead link to Unicode article.
........
r74822 | georg.brandl | 2009-09-16 12:12:06 +0200 (Mi, 16 Sep 2009) | 1 line
#5621: refactor description of how class/instance attributes interact on a.x=a.x+1 or augassign.
........
r74823 | georg.brandl | 2009-09-16 15:06:22 +0200 (Mi, 16 Sep 2009) | 1 line
Remove strange trailing commas.
........
r74824 | georg.brandl | 2009-09-16 15:11:06 +0200 (Mi, 16 Sep 2009) | 1 line
#6892: fix optparse example involving help option.
........
................
2009-09-16 13:05:59 -03:00
|
|
|
.. method:: Telnet.msg(msg, *args)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Print a debug message when the debug level is ``>`` 0. If extra arguments are
|
|
|
|
present, they are substituted in the message using the standard string
|
|
|
|
formatting operator.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.set_debuglevel(debuglevel)
|
|
|
|
|
|
|
|
Set the debug level. The higher the value of *debuglevel*, the more debug
|
|
|
|
output you get (on ``sys.stdout``).
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.close()
|
|
|
|
|
|
|
|
Close the connection.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.get_socket()
|
|
|
|
|
|
|
|
Return the socket object used internally.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.fileno()
|
|
|
|
|
|
|
|
Return the file descriptor of the socket object used internally.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.write(buffer)
|
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
Write a byte string to the socket, doubling any IAC characters. This can
|
|
|
|
block if the connection is blocked. May raise :exc:`socket.error` if the
|
|
|
|
connection is closed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.interact()
|
|
|
|
|
|
|
|
Interaction function, emulates a very dumb Telnet client.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.mt_interact()
|
|
|
|
|
|
|
|
Multithreaded version of :meth:`interact`.
|
|
|
|
|
|
|
|
|
Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
................
r74821 | georg.brandl | 2009-09-16 11:42:19 +0200 (Mi, 16 Sep 2009) | 1 line
#6885: run python 3 as python3.
................
r74828 | georg.brandl | 2009-09-16 16:23:20 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74829 | georg.brandl | 2009-09-16 16:24:29 +0200 (Mi, 16 Sep 2009) | 1 line
Small PEP8 correction.
................
r74830 | georg.brandl | 2009-09-16 16:36:22 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans.
................
r74831 | georg.brandl | 2009-09-16 17:54:04 +0200 (Mi, 16 Sep 2009) | 1 line
Use true booleans and PEP8 for argdefaults.
................
r74833 | georg.brandl | 2009-09-16 17:58:14 +0200 (Mi, 16 Sep 2009) | 1 line
Last round of adapting style of documenting argument default values.
................
r74835 | georg.brandl | 2009-09-16 18:00:31 +0200 (Mi, 16 Sep 2009) | 33 lines
Merged revisions 74817-74820,74822-74824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74817 | georg.brandl | 2009-09-16 11:05:11 +0200 (Mi, 16 Sep 2009) | 1 line
Make deprecation notices as visible as warnings are right now.
........
r74818 | georg.brandl | 2009-09-16 11:23:04 +0200 (Mi, 16 Sep 2009) | 1 line
#6880: add reference to classes section in exceptions section, which comes earlier.
........
r74819 | georg.brandl | 2009-09-16 11:24:57 +0200 (Mi, 16 Sep 2009) | 1 line
#6876: fix base class constructor invocation in example.
........
r74820 | georg.brandl | 2009-09-16 11:30:48 +0200 (Mi, 16 Sep 2009) | 1 line
#6891: comment out dead link to Unicode article.
........
r74822 | georg.brandl | 2009-09-16 12:12:06 +0200 (Mi, 16 Sep 2009) | 1 line
#5621: refactor description of how class/instance attributes interact on a.x=a.x+1 or augassign.
........
r74823 | georg.brandl | 2009-09-16 15:06:22 +0200 (Mi, 16 Sep 2009) | 1 line
Remove strange trailing commas.
........
r74824 | georg.brandl | 2009-09-16 15:11:06 +0200 (Mi, 16 Sep 2009) | 1 line
#6892: fix optparse example involving help option.
........
................
2009-09-16 13:05:59 -03:00
|
|
|
.. method:: Telnet.expect(list, timeout=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Read until one from a list of a regular expressions matches.
|
|
|
|
|
|
|
|
The first argument is a list of regular expressions, either compiled
|
2008-10-15 19:28:54 -03:00
|
|
|
(:class:`re.RegexObject` instances) or uncompiled (byte strings). The
|
|
|
|
optional second argument is a timeout, in seconds; the default is to block
|
|
|
|
indefinitely.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Return a tuple of three items: the index in the list of the first regular
|
2008-10-15 19:28:54 -03:00
|
|
|
expression that matches; the match object returned; and the bytes read up
|
|
|
|
till and including the match.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
If end of file is found and no bytes were read, raise :exc:`EOFError`.
|
|
|
|
Otherwise, when nothing matches, return ``(-1, None, data)`` where *data* is
|
|
|
|
the bytes received so far (may be empty bytes if a timeout happened).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
If a regular expression ends with a greedy match (such as ``.*``) or if more
|
2008-10-15 19:28:54 -03:00
|
|
|
than one expression can match the same input, the results are
|
|
|
|
indeterministic, and may depend on the I/O timing.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Telnet.set_option_negotiation_callback(callback)
|
|
|
|
|
|
|
|
Each time a telnet option is read on the input flow, this *callback* (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.
|
|
|
|
|
|
|
|
|
|
|
|
.. _telnet-example:
|
|
|
|
|
|
|
|
Telnet Example
|
|
|
|
--------------
|
|
|
|
|
|
|
|
.. sectionauthor:: Peter Funk <pf@artcom-gmbh.de>
|
|
|
|
|
|
|
|
|
|
|
|
A simple example illustrating typical use::
|
|
|
|
|
|
|
|
import getpass
|
|
|
|
import telnetlib
|
|
|
|
|
|
|
|
HOST = "localhost"
|
2007-12-02 18:48:17 -04:00
|
|
|
user = input("Enter your remote account: ")
|
2007-08-15 11:28:22 -03:00
|
|
|
password = getpass.getpass()
|
|
|
|
|
|
|
|
tn = telnetlib.Telnet(HOST)
|
|
|
|
|
2008-10-15 17:54:24 -03:00
|
|
|
tn.read_until(b"login: ")
|
|
|
|
tn.write(user.encode('ascii') + b"\n")
|
2007-08-15 11:28:22 -03:00
|
|
|
if password:
|
2008-10-15 17:54:24 -03:00
|
|
|
tn.read_until(b"Password: ")
|
|
|
|
tn.write(password.encode('ascii') + b"\n")
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-10-15 17:54:24 -03:00
|
|
|
tn.write(b"ls\n")
|
|
|
|
tn.write(b"exit\n")
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-10-15 19:28:54 -03:00
|
|
|
print(tn.read_all().decode('ascii'))
|
2007-08-15 11:28:22 -03:00
|
|
|
|