Skip to content

Commit 94c56a1

Browse files
committed
PEP8-ify ftplib.py: get rid of multiple statements on one line (if cond: ...)
1 parent e8d4d51 commit 94c56a1

File tree

1 file changed

+57
-29
lines changed

1 file changed

+57
-29
lines changed

Lib/ftplib.py

+57-29
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import warnings
4343
from socket import _GLOBAL_DEFAULT_TIMEOUT
4444

45-
__all__ = ["FTP","Netrc"]
45+
__all__ = ["FTP", "Netrc"]
4646

4747
# Magic number from <socket.h>
4848
MSG_OOB = 0x1 # Process data out of band
@@ -184,7 +184,8 @@ def sanitize(self, s):
184184
# Internal: send one line to the server, appending CRLF
185185
def putline(self, line):
186186
line = line + CRLF
187-
if self.debugging > 1: print('*put*', self.sanitize(line))
187+
if self.debugging > 1:
188+
print('*put*', self.sanitize(line))
188189
self.sock.sendall(line.encode(self.encoding))
189190

190191
# Internal: send one command to the server (through putline())
@@ -198,9 +199,12 @@ def getline(self):
198199
line = self.file.readline()
199200
if self.debugging > 1:
200201
print('*get*', self.sanitize(line))
201-
if not line: raise EOFError
202-
if line[-2:] == CRLF: line = line[:-2]
203-
elif line[-1:] in CRLF: line = line[:-1]
202+
if not line:
203+
raise EOFError
204+
if line[-2:] == CRLF:
205+
line = line[:-2]
206+
elif line[-1:] in CRLF:
207+
line = line[:-1]
204208
return line
205209

206210
# Internal: get a response from the server, which may possibly
@@ -223,7 +227,8 @@ def getmultiline(self):
223227
# Raise various errors if the response indicates an error
224228
def getresp(self):
225229
resp = self.getmultiline()
226-
if self.debugging: print('*resp*', self.sanitize(resp))
230+
if self.debugging:
231+
print('*resp*', self.sanitize(resp))
227232
self.lastresp = resp[:3]
228233
c = resp[:1]
229234
if c in {'1', '2', '3'}:
@@ -247,7 +252,8 @@ def abort(self):
247252
IP and Synch; that doesn't seem to work with the servers I've
248253
tried. Instead, just send the ABOR command as OOB data.'''
249254
line = b'ABOR' + B_CRLF
250-
if self.debugging > 1: print('*put urgent*', self.sanitize(line))
255+
if self.debugging > 1:
256+
print('*put urgent*', self.sanitize(line))
251257
self.sock.sendall(line, MSG_OOB)
252258
resp = self.getmultiline()
253259
if resp[:3] not in {'426', '225', '226'}:
@@ -388,9 +394,12 @@ def transfercmd(self, cmd, rest=None):
388394

389395
def login(self, user = '', passwd = '', acct = ''):
390396
'''Login, default anonymous.'''
391-
if not user: user = 'anonymous'
392-
if not passwd: passwd = ''
393-
if not acct: acct = ''
397+
if not user:
398+
user = 'anonymous'
399+
if not passwd:
400+
passwd = ''
401+
if not acct:
402+
acct = ''
394403
if user == 'anonymous' and passwd in {'', '-'}:
395404
# If there is no anonymous ftp password specified
396405
# then we'll just use anonymous@
@@ -401,8 +410,10 @@ def login(self, user = '', passwd = '', acct = ''):
401410
# host or country.
402411
passwd = passwd + 'anonymous@'
403412
resp = self.sendcmd('USER ' + user)
404-
if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
405-
if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
413+
if resp[0] == '3':
414+
resp = self.sendcmd('PASS ' + passwd)
415+
if resp[0] == '3':
416+
resp = self.sendcmd('ACCT ' + acct)
406417
if resp[0] != '2':
407418
raise error_reply(resp)
408419
return resp
@@ -442,13 +453,15 @@ def retrlines(self, cmd, callback = None):
442453
Returns:
443454
The response code.
444455
"""
445-
if callback is None: callback = print_line
456+
if callback is None:
457+
callback = print_line
446458
resp = self.sendcmd('TYPE A')
447459
with self.transfercmd(cmd) as conn, \
448460
conn.makefile('r', encoding=self.encoding) as fp:
449461
while 1:
450462
line = fp.readline()
451-
if self.debugging > 2: print('*retr*', repr(line))
463+
if self.debugging > 2:
464+
print('*retr*', repr(line))
452465
if not line:
453466
break
454467
if line[-2:] == CRLF:
@@ -477,9 +490,11 @@ def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
477490
with self.transfercmd(cmd, rest) as conn:
478491
while 1:
479492
buf = fp.read(blocksize)
480-
if not buf: break
493+
if not buf:
494+
break
481495
conn.sendall(buf)
482-
if callback: callback(buf)
496+
if callback:
497+
callback(buf)
483498
return self.voidresp()
484499

485500
def storlines(self, cmd, fp, callback=None):
@@ -498,12 +513,14 @@ def storlines(self, cmd, fp, callback=None):
498513
with self.transfercmd(cmd) as conn:
499514
while 1:
500515
buf = fp.readline()
501-
if not buf: break
516+
if not buf:
517+
break
502518
if buf[-2:] != B_CRLF:
503519
if buf[-1] in B_CRLF: buf = buf[:-1]
504520
buf = buf + B_CRLF
505521
conn.sendall(buf)
506-
if callback: callback(buf)
522+
if callback:
523+
callback(buf)
507524
return self.voidresp()
508525

509526
def acct(self, password):
@@ -768,14 +785,16 @@ def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
768785
return self.voidresp()
769786

770787
def retrlines(self, cmd, callback = None):
771-
if callback is None: callback = print_line
788+
if callback is None:
789+
callback = print_line
772790
resp = self.sendcmd('TYPE A')
773791
conn = self.transfercmd(cmd)
774792
fp = conn.makefile('r', encoding=self.encoding)
775793
with fp, conn:
776794
while 1:
777795
line = fp.readline()
778-
if self.debugging > 2: print('*retr*', repr(line))
796+
if self.debugging > 2:
797+
print('*retr*', repr(line))
779798
if not line:
780799
break
781800
if line[-2:] == CRLF:
@@ -793,9 +812,11 @@ def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
793812
with self.transfercmd(cmd, rest) as conn:
794813
while 1:
795814
buf = fp.read(blocksize)
796-
if not buf: break
815+
if not buf:
816+
break
797817
conn.sendall(buf)
798-
if callback: callback(buf)
818+
if callback:
819+
callback(buf)
799820
# shutdown ssl layer
800821
if isinstance(conn, ssl.SSLSocket):
801822
conn.unwrap()
@@ -806,12 +827,15 @@ def storlines(self, cmd, fp, callback=None):
806827
with self.transfercmd(cmd) as conn:
807828
while 1:
808829
buf = fp.readline()
809-
if not buf: break
830+
if not buf:
831+
break
810832
if buf[-2:] != B_CRLF:
811-
if buf[-1] in B_CRLF: buf = buf[:-1]
833+
if buf[-1] in B_CRLF:
834+
buf = buf[:-1]
812835
buf = buf + B_CRLF
813836
conn.sendall(buf)
814-
if callback: callback(buf)
837+
if callback:
838+
callback(buf)
815839
# shutdown ssl layer
816840
if isinstance(conn, ssl.SSLSocket):
817841
conn.unwrap()
@@ -924,7 +948,8 @@ def print_line(line):
924948

925949
def ftpcp(source, sourcename, target, targetname = '', type = 'I'):
926950
'''Copy file from one FTP-instance to another.'''
927-
if not targetname: targetname = sourcename
951+
if not targetname:
952+
targetname = sourcename
928953
type = 'TYPE ' + type
929954
source.voidcmd(type)
930955
target.voidcmd(type)
@@ -934,9 +959,11 @@ def ftpcp(source, sourcename, target, targetname = '', type = 'I'):
934959
# transfer request.
935960
# So: STOR before RETR, because here the target is a "user".
936961
treply = target.sendcmd('STOR ' + targetname)
937-
if treply[:3] not in {'125', '150'}: raise error_proto # RFC 959
962+
if treply[:3] not in {'125', '150'}:
963+
raise error_proto # RFC 959
938964
sreply = source.sendcmd('RETR ' + sourcename)
939-
if sreply[:3] not in {'125', '150'}: raise error_proto # RFC 959
965+
if sreply[:3] not in {'125', '150'}:
966+
raise error_proto # RFC 959
940967
source.voidresp()
941968
target.voidresp()
942969

@@ -968,7 +995,8 @@ def __init__(self, filename=None):
968995
in_macro = 0
969996
while 1:
970997
line = fp.readline()
971-
if not line: break
998+
if not line:
999+
break
9721000
if in_macro and line.strip():
9731001
macro_lines.append(line)
9741002
continue

0 commit comments

Comments
 (0)