summaryrefslogtreecommitdiff
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py47
1 files changed, 23 insertions, 24 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 634bbde7ad..cfc51ba26f 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -212,16 +212,16 @@ class FTP:
if c in ('1', '2', '3'):
return resp
if c == '4':
- raise error_temp, resp
+ raise error_temp(resp)
if c == '5':
- raise error_perm, resp
- raise error_proto, resp
+ raise error_perm(resp)
+ raise error_proto(resp)
def voidresp(self):
"""Expect a response beginning with '2'."""
resp = self.getresp()
if resp[0] != '2':
- raise error_reply, resp
+ raise error_reply(resp)
return resp
def abort(self):
@@ -234,7 +234,7 @@ class FTP:
self.sock.sendall(line, MSG_OOB)
resp = self.getmultiline()
if resp[:3] not in ('426', '226'):
- raise error_proto, resp
+ raise error_proto(resp)
def sendcmd(self, cmd):
'''Send a command and return the response.'''
@@ -264,7 +264,7 @@ class FTP:
if self.af == socket.AF_INET6:
af = 2
if af == 0:
- raise error_proto, 'unsupported address family'
+ raise error_proto('unsupported address family')
fields = ['', repr(af), host, repr(port), '']
cmd = 'EPRT ' + '|'.join(fields)
return self.voidcmd(cmd)
@@ -285,7 +285,7 @@ class FTP:
continue
break
if not sock:
- raise socket.error, msg
+ raise socket.error(msg)
sock.listen(1)
port = sock.getsockname()[1] # Get proper port
host = self.sock.getsockname()[0] # Get proper host
@@ -333,7 +333,7 @@ class FTP:
if resp[0] == '2':
resp = self.getresp()
if resp[0] != '1':
- raise error_reply, resp
+ raise error_reply(resp)
else:
sock = self.makeport()
if rest is not None:
@@ -343,7 +343,7 @@ class FTP:
if resp[0] == '2':
resp = self.getresp()
if resp[0] != '1':
- raise error_reply, resp
+ raise error_reply(resp)
conn, sockaddr = sock.accept()
if resp[:3] == '150':
# this is conditional in case we received a 125
@@ -372,7 +372,7 @@ class FTP:
if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
if resp[0] != '2':
- raise error_reply, resp
+ raise error_reply(resp)
return resp
def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
@@ -477,7 +477,7 @@ class FTP:
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
if resp[0] != '3':
- raise error_reply, resp
+ raise error_reply(resp)
return self.voidcmd('RNTO ' + toname)
def delete(self, filename):
@@ -486,9 +486,9 @@ class FTP:
if resp[:3] in ('250', '200'):
return resp
elif resp[:1] == '5':
- raise error_perm, resp
+ raise error_perm(resp)
else:
- raise error_reply, resp
+ raise error_reply(resp)
def cwd(self, dirname):
'''Change to a directory.'''
@@ -550,7 +550,7 @@ def parse150(resp):
be present in the 150 message.
'''
if resp[:3] != '150':
- raise error_reply, resp
+ raise error_reply(resp)
global _150_re
if _150_re is None:
import re
@@ -573,14 +573,14 @@ def parse227(resp):
Return ('host.addr.as.numbers', port#) tuple.'''
if resp[:3] != '227':
- raise error_reply, resp
+ raise error_reply(resp)
global _227_re
if _227_re is None:
import re
_227_re = re.compile(r'(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)')
m = _227_re.search(resp)
if not m:
- raise error_proto, resp
+ raise error_proto(resp)
numbers = m.groups()
host = '.'.join(numbers[:4])
port = (int(numbers[4]) << 8) + int(numbers[5])
@@ -593,17 +593,17 @@ def parse229(resp, peer):
Return ('host.addr.as.numbers', port#) tuple.'''
if resp[:3] != '229':
- raise error_reply, resp
+ raise error_reply(resp)
left = resp.find('(')
- if left < 0: raise error_proto, resp
+ if left < 0: raise error_proto(resp)
right = resp.find(')', left + 1)
if right < 0:
- raise error_proto, resp # should contain '(|||port|)'
+ raise error_proto(resp) # should contain '(|||port|)'
if resp[left + 1] != resp[right - 1]:
- raise error_proto, resp
+ raise error_proto(resp)
parts = resp[left + 1:right].split(resp[left+1])
if len(parts) != 5:
- raise error_proto, resp
+ raise error_proto(resp)
host = peer[0]
port = int(parts[3])
return host, port
@@ -615,7 +615,7 @@ def parse257(resp):
Returns the directoryname in the 257 reply.'''
if resp[:3] != '257':
- raise error_reply, resp
+ raise error_reply(resp)
if resp[3:5] != ' "':
return '' # Not compliant to RFC 959, but UNIX ftpd does this
dirname = ''
@@ -674,8 +674,7 @@ class Netrc:
filename = os.path.join(os.environ["HOME"],
".netrc")
else:
- raise IOError, \
- "specify file to load or set $HOME"
+ raise IOError("specify file to load or set $HOME")
self.__hosts = {}
self.__macros = {}
fp = open(filename, "r")