From: R David Murray Date: Tue, 19 Feb 2013 23:32:28 +0000 (-0500) Subject: #6623: Add explicit deprecation warning for ftplib.Netrc. X-Git-Tag: v3.4.0a1~1354 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87632f1a9ec1dd310df1b0addc4c8842d83828bf;p=python #6623: Add explicit deprecation warning for ftplib.Netrc. --- diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 6aecd28a13..8d99158204 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -39,6 +39,7 @@ python ftplib.py -d localhost -l -p -l import os import sys import socket +import warnings from socket import _GLOBAL_DEFAULT_TIMEOUT __all__ = ["FTP","Netrc"] @@ -953,6 +954,8 @@ class Netrc: __defacct = None def __init__(self, filename=None): + warnings.warn("This class is deprecated, use the netrc module instead", + DeprecationWarning, 2) if filename is None: if "HOME" in os.environ: filename = os.path.join(os.environ["HOME"], diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 4dfc457010..2e899737ab 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -985,8 +985,19 @@ class TestTimeouts(TestCase): ftp.close() +class TestNetrcDeprecation(TestCase): + + def test_deprecation(self): + with support.temp_cwd(), support.EnvironmentVarGuard() as env: + env['HOME'] = os.getcwd() + open('.netrc', 'w').close() + with self.assertWarns(DeprecationWarning): + ftplib.Netrc() + + + def test_main(): - tests = [TestFTPClass, TestTimeouts] + tests = [TestFTPClass, TestTimeouts, TestNetrcDeprecation] if support.IPV6_ENABLED: tests.append(TestIPv6Environment) diff --git a/Misc/NEWS b/Misc/NEWS index d702ed1241..ac29b186c7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -260,6 +260,9 @@ Core and Builtins Library ------- +- Issue #6623: Added explicit DeprecationWarning for ftplib.netrc, which has + been deprecated and undocumented for a long time. + - Issue #13700: Fix byte/string handling in imaplib authentication when an authobject is specified.