mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #22351: The nntplib.NNTP constructor no longer leaves the connection
and socket open until the garbage collector cleans them up. Patch by Martin Panter.
This commit is contained in:
parent
63998a3520
commit
52027c301a
3 changed files with 127 additions and 15 deletions
|
@ -1041,11 +1041,18 @@ class NNTP(_NNTPBase):
|
|||
self.host = host
|
||||
self.port = port
|
||||
self.sock = socket.create_connection((host, port), timeout)
|
||||
file = self.sock.makefile("rwb")
|
||||
_NNTPBase.__init__(self, file, host,
|
||||
readermode, timeout)
|
||||
if user or usenetrc:
|
||||
self.login(user, password, usenetrc)
|
||||
file = None
|
||||
try:
|
||||
file = self.sock.makefile("rwb")
|
||||
_NNTPBase.__init__(self, file, host,
|
||||
readermode, timeout)
|
||||
if user or usenetrc:
|
||||
self.login(user, password, usenetrc)
|
||||
except:
|
||||
if file:
|
||||
file.close()
|
||||
self.sock.close()
|
||||
raise
|
||||
|
||||
def _close(self):
|
||||
try:
|
||||
|
@ -1065,12 +1072,19 @@ if _have_ssl:
|
|||
in default port and the `ssl_context` argument for SSL connections.
|
||||
"""
|
||||
self.sock = socket.create_connection((host, port), timeout)
|
||||
self.sock = _encrypt_on(self.sock, ssl_context, host)
|
||||
file = self.sock.makefile("rwb")
|
||||
_NNTPBase.__init__(self, file, host,
|
||||
readermode=readermode, timeout=timeout)
|
||||
if user or usenetrc:
|
||||
self.login(user, password, usenetrc)
|
||||
file = None
|
||||
try:
|
||||
self.sock = _encrypt_on(self.sock, ssl_context, host)
|
||||
file = self.sock.makefile("rwb")
|
||||
_NNTPBase.__init__(self, file, host,
|
||||
readermode=readermode, timeout=timeout)
|
||||
if user or usenetrc:
|
||||
self.login(user, password, usenetrc)
|
||||
except:
|
||||
if file:
|
||||
file.close()
|
||||
self.sock.close()
|
||||
raise
|
||||
|
||||
def _close(self):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue