]> granicus.if.org Git - python/commitdiff
#6623: Add explicit deprecation warning for ftplib.Netrc.
authorR David Murray <rdmurray@bitdance.com>
Tue, 19 Feb 2013 23:32:28 +0000 (18:32 -0500)
committerR David Murray <rdmurray@bitdance.com>
Tue, 19 Feb 2013 23:32:28 +0000 (18:32 -0500)
Lib/ftplib.py
Lib/test/test_ftplib.py
Misc/NEWS

index 6aecd28a13f49b1597cf85a0fa4e925e96b06883..8d991582048cb93ca48ca07688321de96d5ab54a 100644 (file)
@@ -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"],
index 4dfc457010a11651a02e1c78532c83059039cf3e..2e899737ab025d0bb4d02c87c716c3b4c9b59590 100644 (file)
@@ -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)
 
index d702ed124194c66bfa9e6883a979ba7c0ba77cb2..ac29b186c7a9fb1fe81c359ff0d429f467bc1b12 100644 (file)
--- 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.