]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44498: Issue a deprecation warning on asynchat, asyncore and smtpd import (#26882)
authorBarry Warsaw <barry@python.org>
Thu, 24 Jun 2021 19:37:26 +0000 (12:37 -0700)
committerGitHub <noreply@github.com>
Thu, 24 Jun 2021 19:37:26 +0000 (12:37 -0700)
* Issue a deprecation warning on smtpd import

* Also issue DeprecationWarnings for asynchat and asyncore

* Fix some tests

* test___all__ requires the word 'module' or 'package' in the deprecation
  warning text, so add those to smtpd, asynchat, and asyncore.
* In test_support, use pprint now instead of asyncore as the landmark.

* Add What's New

* Use ..deprecated::

* Use ..deprecated::

* Update Lib/smtpd.py

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
* Update Doc/library/smtpd.rst

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
* Import async{hat,ore} after the DeprecationWarning for this module

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Doc/library/smtpd.rst
Doc/whatsnew/3.10.rst
Lib/asynchat.py
Lib/asyncore.py
Lib/smtpd.py
Lib/test/test_support.py

index ae66e7e4596c62eb8e465ad913790409fe5778bb..611411ddd295b26a926311cc1ef12d766bab5a0a 100644 (file)
 
 This module offers several classes to implement SMTP (email) servers.
 
-.. seealso::
-
-    The `aiosmtpd <http://aiosmtpd.readthedocs.io/>`_ package is a recommended
-    replacement for this module.  It is based on :mod:`asyncio` and provides a
-    more straightforward API.  :mod:`smtpd` should be considered deprecated.
+.. deprecated:: 3.6
+   The `aiosmtpd <https://aiosmtpd.readthedocs.io/>`_ package is a recommended
+   replacement for this module.  It is based on :mod:`asyncio` and provides a
+   more straightforward API.
 
 Several server implementations are present; one is a generic
 do-nothing implementation, which can be overridden, while the other two offer
index 63d1bd02c68b9d2d69f440dbf74989625a9f9ff6..2a43d2686e3fbab4d554a45b16eeab2282684f0c 100644 (file)
@@ -883,6 +883,12 @@ The :meth:`~array.array.index` method of :class:`array.array` now has
 optional *start* and *stop* parameters.
 (Contributed by Anders Lorentsen and Zackery Spytz in :issue:`31956`.)
 
+asynchat, asyncore, smtpd
+-------------------------
+These modules have been marked as deprecated in their module documentation
+since Python 3.6.  An import-time :class:`DeprecationWarning` has now been
+added to all three of these modules.
+
 base64
 ------
 
index f4ba361bd4a3ef81e6801601a2ec83ac765b230e..de26ffa648ffecd3b98beebd45e0846267e6edd7 100644 (file)
@@ -48,6 +48,14 @@ you - by calling your self.found_terminator() method.
 import asyncore
 from collections import deque
 
+from warnings import warn
+warn(
+    'The asynchat module is deprecated. '
+    'The recommended replacement is asyncio',
+    DeprecationWarning,
+    stacklevel=2)
+
+
 
 class async_chat(asyncore.dispatcher):
     """This is an abstract class.  You must derive from this class, and add
index eeea48888616d7e3cec67ffbceb4db86d32d318c..b1eea4bf652118498a0664152d3f87ca1807283d 100644 (file)
@@ -57,6 +57,13 @@ from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
      ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
      errorcode
 
+warnings.warn(
+    'The asyncore module is deprecated. '
+    'The recommended replacement is asyncio',
+    DeprecationWarning,
+    stacklevel=2)
+
+
 _DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
                            EBADF})
 
index d0536023e84018358881959ced586997304f454b..1cd004fbc6fe5b88a89775d520a4ea88eaf95e31 100755 (executable)
@@ -76,8 +76,6 @@ import errno
 import getopt
 import time
 import socket
-import asyncore
-import asynchat
 import collections
 from warnings import warn
 from email._header_value_parser import get_addr_spec, get_angle_addr
@@ -86,6 +84,19 @@ __all__ = [
     "SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy",
 ]
 
+warn(
+    'The smtpd module is deprecated and unmaintained.  Please see aiosmtpd '
+    '(https://aiosmtpd.readthedocs.io/) for the recommended replacement.',
+    DeprecationWarning,
+    stacklevel=2)
+
+
+# These are imported after the above warning so that users get the correct
+# deprecation warning.
+import asyncore
+import asynchat
+
+
 program = sys.argv[0]
 __version__ = 'Python SMTP proxy version 0.3'
 
index 55d78b733353d2cd7236742c9740007c33cd4556..b1d3411a865bb26854eb7b9b6862e057ad3b83f3 100644 (file)
@@ -292,8 +292,8 @@ class TestSupport(unittest.TestCase):
 
     def test_CleanImport(self):
         import importlib
-        with import_helper.CleanImport("asyncore"):
-            importlib.import_module("asyncore")
+        with import_helper.CleanImport("pprint"):
+            importlib.import_module("pprint")
 
     def test_DirsOnSysPath(self):
         with import_helper.DirsOnSysPath('foo', 'bar'):