Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4f09806e
Kaydet (Commit)
4f09806e
authored
Kas 28, 2015
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#25485: Add context manager support to Telnet class.
Patch by Stéphane Wirtel.
üst
37f54219
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
5 deletions
+35
-5
telnetlib.rst
Doc/library/telnetlib.rst
+11
-0
3.6.rst
Doc/whatsnew/3.6.rst
+7
-0
telnetlib.py
Lib/telnetlib.py
+10
-5
test_telnetlib.py
Lib/test/test_telnetlib.py
+5
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/telnetlib.rst
Dosyayı görüntüle @
4f09806e
...
...
@@ -43,6 +43,17 @@ Character), EL (Erase Line), GA (Go Ahead), SB (Subnegotiation Begin).
: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.
A :class:`Telnet` object is a context manager and can be used in a
:keyword:`with` statement. When the :keyword:`with` block ends, the
:meth:`close` method is called::
>>> from telnetlib import Telnet
>>> with Telnet('localhost', 23) as tn:
... tn.interact()
...
.. versionchanged:: 3.6 Context manager support added
.. seealso::
...
...
Doc/whatsnew/3.6.rst
Dosyayı görüntüle @
4f09806e
...
...
@@ -125,6 +125,13 @@ Previously, names of properties and slots which were not yet created on
an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.)
telnetlib
---------
:class:`~telnetlib.Telnet` is now a context manager (contributed by
Stéphane Wirtel in :issue:`25485`).
urllib.robotparser
------------------
...
...
Lib/telnetlib.py
Dosyayı görüntüle @
4f09806e
...
...
@@ -637,6 +637,12 @@ class Telnet:
raise
EOFError
return
(
-
1
,
None
,
text
)
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
def
test
():
"""Test program for telnetlib.
...
...
@@ -660,11 +666,10 @@ def test():
port
=
int
(
portstr
)
except
ValueError
:
port
=
socket
.
getservbyname
(
portstr
,
'tcp'
)
tn
=
Telnet
()
tn
.
set_debuglevel
(
debuglevel
)
tn
.
open
(
host
,
port
,
timeout
=
0.5
)
tn
.
interact
()
tn
.
close
()
with
Telnet
()
as
tn
:
tn
.
set_debuglevel
(
debuglevel
)
tn
.
open
(
host
,
port
,
timeout
=
0.5
)
tn
.
interact
()
if
__name__
==
'__main__'
:
test
()
Lib/test/test_telnetlib.py
Dosyayı görüntüle @
4f09806e
...
...
@@ -42,6 +42,11 @@ class GeneralTests(TestCase):
telnet
=
telnetlib
.
Telnet
(
HOST
,
self
.
port
)
telnet
.
sock
.
close
()
def
testContextManager
(
self
):
with
telnetlib
.
Telnet
(
HOST
,
self
.
port
)
as
tn
:
self
.
assertIsNotNone
(
tn
.
get_socket
())
self
.
assertIsNone
(
tn
.
get_socket
())
def
testTimeoutDefault
(
self
):
self
.
assertTrue
(
socket
.
getdefaulttimeout
()
is
None
)
socket
.
setdefaulttimeout
(
30
)
...
...
Misc/NEWS
Dosyayı görüntüle @
4f09806e
...
...
@@ -10,6 +10,8 @@ Release date: XXXX-XX-XX
Core and Builtins
-----------------
- Issue #25485: telnetlib.Telnet is now a context manager.
- Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment