]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Always use 'anonymous' if os.environ doesn't exist
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 19 Jan 1995 12:24:45 +0000 (12:24 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 19 Jan 1995 12:24:45 +0000 (12:24 +0000)
Lib/ftplib.py

index d1603037593216bdbb06e07c63746239adbfd732..7a414e6882a98a0f4604d273cac5ce21be750a6b 100644 (file)
@@ -2,6 +2,7 @@
 # (FTP), by J. Postel and J. Reynolds
 
 # Changes and improvements suggested by Steve Majewski
+# Modified by Jack to work on the mac.
 
 
 # Example:
@@ -220,11 +221,15 @@ class FTP:
                if not user: user = 'anonymous'
                if user == 'anonymous' and passwd in ('', '-'):
                        thishost = socket.gethostname()
-                       if os.environ.has_key('LOGNAME'):
-                               realuser = os.environ['LOGNAME']
-                       elif os.environ.has_key('USER'):
-                               realuser = os.environ['USER']
-                       else:
+                       try:
+                               if os.environ.has_key('LOGNAME'):
+                                       realuser = os.environ['LOGNAME']
+                               elif os.environ.has_key('USER'):
+                                       realuser = os.environ['USER']
+                               else:
+                                       realuser = 'anonymous'
+                       except AttributeError:
+                               # Not all systems have os.environ....
                                realuser = 'anonymous'
                        passwd = passwd + realuser + '@' + thishost
                resp = self.sendcmd('USER ' + user)