summaryrefslogtreecommitdiff
path: root/Lib/nntplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-14 23:30:35 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-14 23:30:35 +0100
commit06b57ef9586c8095b38b58dbf04fb8de94c08c16 (patch)
tree887fb8c34ad06cb315c16f7757d827ddda0ac93a /Lib/nntplib.py
parent2603d0a6575024f619df0f4a0e1bfbfc11c1c52f (diff)
parent71135624d81fac63a1684d5cf31932652f9250ff (diff)
downloadcpython-git-06b57ef9586c8095b38b58dbf04fb8de94c08c16.tar.gz
Issue #10287: nntplib now queries the server's CAPABILITIES first before sending MODE READER, and only sends it if not already in READER mode.
Patch by Hynek Schlawack.
Diffstat (limited to 'Lib/nntplib.py')
-rw-r--r--Lib/nntplib.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/nntplib.py b/Lib/nntplib.py
index 7ebc6215fb..eb16206bbc 100644
--- a/Lib/nntplib.py
+++ b/Lib/nntplib.py
@@ -324,25 +324,30 @@ class _NNTPBase:
self.debugging = 0
self.welcome = self._getresp()
+ # Inquire about capabilities (RFC 3977).
+ self._caps = None
+ self.getcapabilities()
+
# 'MODE READER' is sometimes necessary to enable 'reader' mode.
# However, the order in which 'MODE READER' and 'AUTHINFO' need to
# arrive differs between some NNTP servers. If _setreadermode() fails
# with an authorization failed error, it will set this to True;
# the login() routine will interpret that as a request to try again
# after performing its normal function.
+ # Enable only if we're not already in READER mode anyway.
self.readermode_afterauth = False
- if readermode:
+ if readermode and 'READER' not in self._caps:
self._setreadermode()
+ if not self.readermode_afterauth:
+ # Capabilities might have changed after MODE READER
+ self._caps = None
+ self.getcapabilities()
# RFC 4642 2.2.2: Both the client and the server MUST know if there is
# a TLS session active. A client MUST NOT attempt to start a TLS
# session if a TLS session is already active.
self.tls_on = False
- # Inquire about capabilities (RFC 3977).
- self._caps = None
- self.getcapabilities()
-
# Log in and encryption setup order is left to subclasses.
self.authenticated = False
@@ -959,8 +964,12 @@ class _NNTPBase:
self._caps = None
self.getcapabilities()
# Attempt to send mode reader if it was requested after login.
- if self.readermode_afterauth:
+ # Only do so if we're not in reader mode already.
+ if self.readermode_afterauth and 'READER' not in self._caps:
self._setreadermode()
+ # Capabilities might have changed after MODE READER
+ self._caps = None
+ self.getcapabilities()
def _setreadermode(self):
try: