]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
don't show print passwords in debug output
authorGuido van Rossum <guido@python.org>
Fri, 5 May 1995 15:54:14 +0000 (15:54 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 5 May 1995 15:54:14 +0000 (15:54 +0000)
Lib/ftplib.py

index a25d467cb156589c0af7d36a402faeaf79389b12..a78f06b05df34e3911a9a6487b6303d81d8e6890 100644 (file)
@@ -95,7 +95,8 @@ class FTP:
        # Get the welcome message from the server
        # (this is read and squirreled away by connect())
        def getwelcome(self):
-               if self.debugging: print '*welcome*', `self.welcome`
+               if self.debugging:
+                       print '*welcome*', self.sanitize(self.welcome)
                return self.welcome
 
        # Set the debugging level.  Argument level means:
@@ -106,15 +107,24 @@ class FTP:
                self.debugging = level
        debug = set_debuglevel
 
+       # Internal: "sanitize" a string for printing
+       def sanitize(self, s):
+               if s[:5] == 'pass ' or s[:5] == 'PASS ':
+                       i = len(s)
+                       while i > 5 and s[i-1] in '\r\n':
+                               i = i-1
+                       s = s[:5] + '*'*(i-5) + s[i:]
+               return `s`
+
        # Internal: send one line to the server, appending CRLF
        def putline(self, line):
                line = line + CRLF
-               if self.debugging > 1: print '*put*', `line`
+               if self.debugging > 1: print '*put*', self.sanitize(line)
                self.sock.send(line)
 
        # Internal: send one command to the server (through putline())
        def putcmd(self, line):
-               if self.debugging: print '*cmd*', `line`
+               if self.debugging: print '*cmd*', self.sanitize(line)
                self.putline(line)
 
        # Internal: return one line from the server, stripping CRLF.
@@ -122,7 +132,7 @@ class FTP:
        def getline(self):
                line = self.file.readline()
                if self.debugging > 1:
-                       print '*get*', `line`
+                       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]
@@ -148,7 +158,7 @@ class FTP:
        # Raise various errors if the response indicates an error
        def getresp(self):
                resp = self.getmultiline()
-               if self.debugging: print '*resp*', `resp`
+               if self.debugging: print '*resp*', self.sanitize(resp)
                self.lastresp = resp[:3]
                c = resp[:1]
                if c == '4':
@@ -171,7 +181,7 @@ class FTP:
        # tried.  Instead, just send the ABOR command as OOB data.
        def abort(self):
                line = 'ABOR' + CRLF
-               if self.debugging > 1: print '*put urgent*', `line`
+               if self.debugging > 1: print '*put urgent*', self.sanitize(line)
                self.sock.send(line, MSG_OOB)
                resp = self.getmultiline()
                if resp[:3] not in ('426', '226'):