cpython: ec196a99af8d (original) (raw)
Mercurial > cpython
changeset 93328:ec196a99af8d
Issue #6623: Remove deprecated Netrc class in the ftplib module. Patch by Matt Chaput. [#6623]
Berker Peksag berker.peksag@gmail.com | |
---|---|
date | Sat, 01 Nov 2014 10:45:57 +0200 |
parents | 26d0a17affb5 |
children | 193ac288bc7f |
files | Doc/whatsnew/3.5.rst Lib/ftplib.py Lib/test/test_ftplib.py Misc/ACKS Misc/NEWS |
diffstat | 5 files changed, 23 insertions(+), 129 deletions(-)[+] [-] Doc/whatsnew/3.5.rst 8 Lib/ftplib.py 117 Lib/test/test_ftplib.py 23 Misc/ACKS 1 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -369,10 +369,18 @@ Deprecated features Removed ======= +API and Feature Removals +------------------------ + +The following obsolete and previously deprecated APIs and features have been +removed: +
- The
__version__
attribute has been dropped from the email package. The email code hasn't been shipped separately from the stdlib for a long time, and the__version__
string was not updated in the last few releases. +* The internalNetrc
class in the :mod:ftplib
module was deprecated in
- 3.4, and has now been removed. (Contributed by Matt Chaput in :issue:
6623
.) Porting to Python 3.5 =====================
--- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -42,7 +42,7 @@ import socket import warnings from socket import _GLOBAL_DEFAULT_TIMEOUT -all = ["FTP", "Netrc"] +all = ["FTP"]
Magic number from <socket.h>
MSG_OOB = 0x1 # Process data out of band @@ -920,115 +920,6 @@ def ftpcp(source, sourcename, target, ta target.voidresp() -class Netrc:
- def init(self, filename=None):
warnings.warn("This class is deprecated, use the netrc module instead",[](#l2.29)
DeprecationWarning, 2)[](#l2.30)
if filename is None:[](#l2.31)
if "HOME" in os.environ:[](#l2.32)
filename = os.path.join(os.environ["HOME"],[](#l2.33)
".netrc")[](#l2.34)
else:[](#l2.35)
raise OSError("specify file to load or set $HOME")[](#l2.36)
self.__hosts = {}[](#l2.37)
self.__macros = {}[](#l2.38)
fp = open(filename, "r")[](#l2.39)
in_macro = 0[](#l2.40)
while 1:[](#l2.41)
line = fp.readline()[](#l2.42)
if not line:[](#l2.43)
break[](#l2.44)
if in_macro and line.strip():[](#l2.45)
macro_lines.append(line)[](#l2.46)
continue[](#l2.47)
elif in_macro:[](#l2.48)
self.__macros[macro_name] = tuple(macro_lines)[](#l2.49)
in_macro = 0[](#l2.50)
words = line.split()[](#l2.51)
host = user = passwd = acct = None[](#l2.52)
default = 0[](#l2.53)
i = 0[](#l2.54)
while i < len(words):[](#l2.55)
w1 = words[i][](#l2.56)
if i+1 < len(words):[](#l2.57)
w2 = words[i + 1][](#l2.58)
else:[](#l2.59)
w2 = None[](#l2.60)
if w1 == 'default':[](#l2.61)
default = 1[](#l2.62)
elif w1 == 'machine' and w2:[](#l2.63)
host = w2.lower()[](#l2.64)
i = i + 1[](#l2.65)
elif w1 == 'login' and w2:[](#l2.66)
user = w2[](#l2.67)
i = i + 1[](#l2.68)
elif w1 == 'password' and w2:[](#l2.69)
passwd = w2[](#l2.70)
i = i + 1[](#l2.71)
elif w1 == 'account' and w2:[](#l2.72)
acct = w2[](#l2.73)
i = i + 1[](#l2.74)
elif w1 == 'macdef' and w2:[](#l2.75)
macro_name = w2[](#l2.76)
macro_lines = [][](#l2.77)
in_macro = 1[](#l2.78)
break[](#l2.79)
i = i + 1[](#l2.80)
if default:[](#l2.81)
self.__defuser = user or self.__defuser[](#l2.82)
self.__defpasswd = passwd or self.__defpasswd[](#l2.83)
self.__defacct = acct or self.__defacct[](#l2.84)
if host:[](#l2.85)
if host in self.__hosts:[](#l2.86)
ouser, opasswd, oacct = \[](#l2.87)
self.__hosts[host][](#l2.88)
user = user or ouser[](#l2.89)
passwd = passwd or opasswd[](#l2.90)
acct = acct or oacct[](#l2.91)
self.__hosts[host] = user, passwd, acct[](#l2.92)
fp.close()[](#l2.93)
- def get_hosts(self):
"""Return a list of hosts mentioned in the .netrc file."""[](#l2.96)
return self.__hosts.keys()[](#l2.97)
The return value is a triple containing userid,[](#l2.102)
password, and the accounting field.[](#l2.103)
"""[](#l2.105)
host = host.lower()[](#l2.106)
user = passwd = acct = None[](#l2.107)
if host in self.__hosts:[](#l2.108)
user, passwd, acct = self.__hosts[host][](#l2.109)
user = user or self.__defuser[](#l2.110)
passwd = passwd or self.__defpasswd[](#l2.111)
acct = acct or self.__defacct[](#l2.112)
return user, passwd, acct[](#l2.113)
- def get_macros(self):
"""Return a list of all defined macro names."""[](#l2.116)
return self.__macros.keys()[](#l2.117)
- def get_macro(self, macro):
"""Return a sequence of lines which define a named macro."""[](#l2.120)
return self.__macros[macro][](#l2.121)
- - - def test(): '''Test program. Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ... @@ -1042,6 +933,8 @@ def test(): print(test.doc) sys.exit(0)
+ debugging = 0 rcfile = None while sys.argv[1] == '-d': @@ -1056,14 +949,14 @@ def test(): ftp.set_debuglevel(debugging) userid = passwd = acct = '' try:
netrc = Netrc(rcfile)[](#l2.141)
except OSError: if rcfile is not None: sys.stderr.write("Could not open account file" " -- using anonymous login.") else: try:netrcobj = netrc.netrc(rcfile)[](#l2.142)
userid, passwd, acct = netrc.get_account(host)[](#l2.149)
userid, acct, passwd = netrcobj.authenticators(host)[](#l2.150) except KeyError:[](#l2.151) # no account for host[](#l2.152) sys.stderr.write([](#l2.153)
--- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -76,7 +76,7 @@ class DummyDTPHandler(asynchat.async_cha super(DummyDTPHandler, self).push(what.encode('ascii')) def handle_error(self):
raise[](#l3.7)
raise Exception[](#l3.8)
class DummyFTPHandler(asynchat.async_chat): @@ -121,7 +121,7 @@ class DummyFTPHandler(asynchat.async_cha self.push('550 command "%s" not understood.' %cmd) def handle_error(self):
raise[](#l3.16)
raise Exception[](#l3.17)
def push(self, data): asynchat.async_chat.push(self, data.encode('ascii') + b'\r\n') @@ -299,7 +299,7 @@ class DummyFTPServer(asyncore.dispatcher return 0 def handle_error(self):
raise[](#l3.25)
raise Exception[](#l3.26)
if ssl is not None: @@ -397,7 +397,7 @@ if ssl is not None: raise def handle_error(self):
raise[](#l3.34)
raise Exception[](#l3.35)
def close(self): if (isinstance(self.socket, ssl.SSLSocket) and @@ -673,7 +673,7 @@ class TestFTPClass(TestCase): self.assertRaises(StopIteration, next, self.client.mlsd()) set_data('') for x in self.client.mlsd():
self.fail("unexpected data %s" % data)[](#l3.43)
self.fail("unexpected data %s" % x)[](#l3.44)
def test_makeport(self): with self.client.makeport(): @@ -1053,19 +1053,8 @@ class TestTimeouts(TestCase): ftp.close() -class TestNetrcDeprecation(TestCase): -
- def test_deprecation(self):
with support.temp_cwd(), support.EnvironmentVarGuard() as env:[](#l3.55)
env['HOME'] = os.getcwd()[](#l3.56)
open('.netrc', 'w').close()[](#l3.57)
with self.assertWarns(DeprecationWarning):[](#l3.58)
ftplib.Netrc()[](#l3.59)
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -233,6 +233,7 @@ Godefroid Chapelle Brad Chapman Greg Chapman Mitch Chapman +Matt Chaput Yogesh Chaudhari David Chaum Nicolas Chauvat
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -180,6 +180,9 @@ Core and Builtins Library ------- +- Issue #6623: Remove deprecated Netrc class in the ftplib module. Patch by