Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cb121e

Browse files
committed
Issue #1926: Add support for NNTP over SSL on port 563, as well as
STARTTLS. Patch by Andrew Vant.
1 parent 14fb799 commit 1cb121e

5 files changed

Lines changed: 310 additions & 102 deletions

File tree

Doc/library/nntplib.rst

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ The module itself defines the following classes:
6969
*readermode* defaults to ``None``. *usenetrc* defaults to ``True``.
7070

7171

72+
.. class:: NNTP_SSL(host, port=563, user=None, password=None, ssl_context=None, readermode=None, usenetrc=True, [timeout])
73+
74+
Return a new :class:`NNTP_SSL` object, representing an encrypted
75+
connection to the NNTP server running on host *host*, listening at
76+
port *port*. :class:`NNTP_SSL` objects have the same methods as
77+
:class:`NNTP` objects. If *port* is omitted, port 563 (NNTPS) is used.
78+
*ssl_context* is also optional, and is a :class:`~ssl.SSLContext` object.
79+
All other parameters behave the same as for :class:`NNTP`.
80+
81+
Note that SSL-on-563 is discouraged per :rfc:`4642`, in favor of
82+
STARTTLS as described below. However, some servers only support the
83+
former.
84+
85+
.. versionadded:: 3.2
86+
87+
7288
.. exception:: NNTPError
7389

7490
Derived from the standard exception :exc:`Exception`, this is the base
@@ -111,8 +127,8 @@ The module itself defines the following classes:
111127
NNTP Objects
112128
------------
113129

114-
When connected, :class:`NNTP` objects support the following methods and
115-
attributes.
130+
When connected, :class:`NNTP` and :class:`NNTP_SSL` objects support the
131+
following methods and attributes.
116132

117133
Attributes
118134
^^^^^^^^^^
@@ -179,6 +195,35 @@ tuples or objects that the method normally returns will be empty.
179195
.. versionadded:: 3.2
180196

181197

198+
.. method:: NNTP.login(user=None, password=None, usenetrc=True)
199+
200+
Send ``AUTHINFO`` commands with the user name and password. If *user*
201+
and *password* are None and *usenetrc* is True, credentials from
202+
``~/.netrc`` will be used if possible.
203+
204+
Unless intentionally delayed, login is normally performed during the
205+
:class:`NNTP` object initialization and separately calling this function
206+
is unnecessary. To force authentication to be delayed, you must not set
207+
*user* or *password* when creating the object, and must set *usenetrc* to
208+
False.
209+
210+
.. versionadded:: 3.2
211+
212+
213+
.. method:: NNTP.starttls(ssl_context=None)
214+
215+
Send a ``STARTTLS`` command. The *ssl_context* argument is optional
216+
and should be a :class:`ssl.SSLContext` object. This will enable
217+
encryption on the NNTP connection.
218+
219+
Note that this may not be done after authentication information has
220+
been transmitted, and authentication occurs by default if possible during a
221+
:class:`NNTP` object initialization. See :meth:`NNTP.login` for information
222+
on suppressing this behavior.
223+
224+
.. versionadded:: 3.2
225+
226+
182227
.. method:: NNTP.newgroups(date, *, file=None)
183228

184229
Send a ``NEWGROUPS`` command. The *date* argument should be a

0 commit comments

Comments
 (0)