[Python-checkins] cpython: PEP8-ify ftplib.py: get rid of multiple statements on one line (if cond: ...)

giampaolo.rodola python-checkins at python.org
Thu Mar 7 13:51:33 CET 2013


http://hg.python.org/cpython/rev/d01870bc43b5
changeset:   82521:d01870bc43b5
user:        Giampaolo Rodola' <g.rodola at gmail.com>
date:        Thu Mar 07 13:51:20 2013 +0100
summary:
  PEP8-ify ftplib.py: get rid of multiple statements on one line (if cond: ...)

files:
  Lib/ftplib.py |  86 +++++++++++++++++++++++++-------------
  1 files changed, 57 insertions(+), 29 deletions(-)


diff --git a/Lib/ftplib.py b/Lib/ftplib.py
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -42,7 +42,7 @@
 import warnings
 from socket import _GLOBAL_DEFAULT_TIMEOUT
 
-__all__ = ["FTP","Netrc"]
+__all__ = ["FTP", "Netrc"]
 
 # Magic number from <socket.h>
 MSG_OOB = 0x1                           # Process data out of band
@@ -184,7 +184,8 @@
     # Internal: send one line to the server, appending CRLF
     def putline(self, line):
         line = line + CRLF
-        if self.debugging > 1: print('*put*', self.sanitize(line))
+        if self.debugging > 1:
+            print('*put*', self.sanitize(line))
         self.sock.sendall(line.encode(self.encoding))
 
     # Internal: send one command to the server (through putline())
@@ -198,9 +199,12 @@
         line = self.file.readline()
         if self.debugging > 1:
             print('*get*', self.sanitize(line))
-        if not line: raise EOFError
-        if line[-2:] == CRLF: line = line[:-2]
-        elif line[-1:] in CRLF: line = line[:-1]
+        if not line:
+            raise EOFError
+        if line[-2:] == CRLF:
+            line = line[:-2]
+        elif line[-1:] in CRLF:
+            line = line[:-1]
         return line
 
     # Internal: get a response from the server, which may possibly
@@ -223,7 +227,8 @@
     # Raise various errors if the response indicates an error
     def getresp(self):
         resp = self.getmultiline()
-        if self.debugging: print('*resp*', self.sanitize(resp))
+        if self.debugging:
+            print('*resp*', self.sanitize(resp))
         self.lastresp = resp[:3]
         c = resp[:1]
         if c in {'1', '2', '3'}:
@@ -247,7 +252,8 @@
         IP and Synch; that doesn't seem to work with the servers I've
         tried.  Instead, just send the ABOR command as OOB data.'''
         line = b'ABOR' + B_CRLF
-        if self.debugging > 1: print('*put urgent*', self.sanitize(line))
+        if self.debugging > 1:
+            print('*put urgent*', self.sanitize(line))
         self.sock.sendall(line, MSG_OOB)
         resp = self.getmultiline()
         if resp[:3] not in {'426', '225', '226'}:
@@ -388,9 +394,12 @@
 
     def login(self, user = '', passwd = '', acct = ''):
         '''Login, default anonymous.'''
-        if not user: user = 'anonymous'
-        if not passwd: passwd = ''
-        if not acct: acct = ''
+        if not user:
+            user = 'anonymous'
+        if not passwd:
+            passwd = ''
+        if not acct:
+            acct = ''
         if user == 'anonymous' and passwd in {'', '-'}:
             # If there is no anonymous ftp password specified
             # then we'll just use anonymous@
@@ -401,8 +410,10 @@
             #   host or country.
             passwd = passwd + 'anonymous@'
         resp = self.sendcmd('USER ' + user)
-        if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
-        if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
+        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)
         return resp
@@ -442,13 +453,15 @@
         Returns:
           The response code.
         """
-        if callback is None: callback = print_line
+        if callback is None:
+            callback = print_line
         resp = self.sendcmd('TYPE A')
         with self.transfercmd(cmd) as conn, \
                  conn.makefile('r', encoding=self.encoding) as fp:
             while 1:
                 line = fp.readline()
-                if self.debugging > 2: print('*retr*', repr(line))
+                if self.debugging > 2:
+                    print('*retr*', repr(line))
                 if not line:
                     break
                 if line[-2:] == CRLF:
@@ -477,9 +490,11 @@
         with self.transfercmd(cmd, rest) as conn:
             while 1:
                 buf = fp.read(blocksize)
-                if not buf: break
+                if not buf:
+                    break
                 conn.sendall(buf)
-                if callback: callback(buf)
+                if callback:
+                    callback(buf)
         return self.voidresp()
 
     def storlines(self, cmd, fp, callback=None):
@@ -498,12 +513,14 @@
         with self.transfercmd(cmd) as conn:
             while 1:
                 buf = fp.readline()
-                if not buf: break
+                if not buf:
+                    break
                 if buf[-2:] != B_CRLF:
                     if buf[-1] in B_CRLF: buf = buf[:-1]
                     buf = buf + B_CRLF
                 conn.sendall(buf)
-                if callback: callback(buf)
+                if callback:
+                    callback(buf)
         return self.voidresp()
 
     def acct(self, password):
@@ -768,14 +785,16 @@
             return self.voidresp()
 
         def retrlines(self, cmd, callback = None):
-            if callback is None: callback = print_line
+            if callback is None:
+                callback = print_line
             resp = self.sendcmd('TYPE A')
             conn = self.transfercmd(cmd)
             fp = conn.makefile('r', encoding=self.encoding)
             with fp, conn:
                 while 1:
                     line = fp.readline()
-                    if self.debugging > 2: print('*retr*', repr(line))
+                    if self.debugging > 2:
+                        print('*retr*', repr(line))
                     if not line:
                         break
                     if line[-2:] == CRLF:
@@ -793,9 +812,11 @@
             with self.transfercmd(cmd, rest) as conn:
                 while 1:
                     buf = fp.read(blocksize)
-                    if not buf: break
+                    if not buf:
+                        break
                     conn.sendall(buf)
-                    if callback: callback(buf)
+                    if callback:
+                        callback(buf)
                 # shutdown ssl layer
                 if isinstance(conn, ssl.SSLSocket):
                     conn.unwrap()
@@ -806,12 +827,15 @@
             with self.transfercmd(cmd) as conn:
                 while 1:
                     buf = fp.readline()
-                    if not buf: break
+                    if not buf:
+                        break
                     if buf[-2:] != B_CRLF:
-                        if buf[-1] in B_CRLF: buf = buf[:-1]
+                        if buf[-1] in B_CRLF:
+                            buf = buf[:-1]
                         buf = buf + B_CRLF
                     conn.sendall(buf)
-                    if callback: callback(buf)
+                    if callback:
+                        callback(buf)
                 # shutdown ssl layer
                 if isinstance(conn, ssl.SSLSocket):
                     conn.unwrap()
@@ -924,7 +948,8 @@
 
 def ftpcp(source, sourcename, target, targetname = '', type = 'I'):
     '''Copy file from one FTP-instance to another.'''
-    if not targetname: targetname = sourcename
+    if not targetname:
+        targetname = sourcename
     type = 'TYPE ' + type
     source.voidcmd(type)
     target.voidcmd(type)
@@ -934,9 +959,11 @@
     # transfer request.
     # So: STOR before RETR, because here the target is a "user".
     treply = target.sendcmd('STOR ' + targetname)
-    if treply[:3] not in {'125', '150'}: raise error_proto  # RFC 959
+    if treply[:3] not in {'125', '150'}:
+        raise error_proto  # RFC 959
     sreply = source.sendcmd('RETR ' + sourcename)
-    if sreply[:3] not in {'125', '150'}: raise error_proto  # RFC 959
+    if sreply[:3] not in {'125', '150'}:
+        raise error_proto  # RFC 959
     source.voidresp()
     target.voidresp()
 
@@ -968,7 +995,8 @@
         in_macro = 0
         while 1:
             line = fp.readline()
-            if not line: break
+            if not line:
+                break
             if in_macro and line.strip():
                 macro_lines.append(line)
                 continue

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list