prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  upload command doesn't prompt for password; raises TypeError
  # Problem statement
  
  If the `~/.pypirc` file does not contain a password like so:
  
  ``` ini
  [distutils]
  index-servers = 
      pypitest
  
  [pypitest]
  repository = https://testpypi.python.org/pypi
  username = my_username
  ; Note the lack of a password
  ```
  
  Then uploading the package
  
  ```
  python setup.py sdist upload -r pypitest
  ```
  
  Fails to prompt the user for his password and instead raises a TypeError (output truncated)
  
  ```
  running upload
  Traceback (most recent call last):
    File "setup.py", line 16, in <module>
      keywords=["test", "hello"]
    File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
      dist.run_commands()
    File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
      self.run_command(cmd)
    File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
      cmd_obj.run()
    File "/usr/lib/python2.7/distutils/command/upload.py", line 60, in run
      self.upload_file(command, pyversion, filename)
    File "/usr/lib/python2.7/distutils/command/upload.py", line 135, in upload_file
      self.password)
  TypeError: cannot concatenate 'str' and 'NoneType' objects
  ```
  
  **This is different** than the behavior of the `register` command, which prompts the user for a password before continuing.
  
  ```
  python setup.py sdist register -r pypitest
  ```
  
  (output truncated)
  
  ```
  Creating tar archive
  removing 'HelloPyPi-0.0.1.dev0' (and everything under it)
  running register
  Password: 
  ```
  
  > Note that the `register` and the `upload` command exhibit the proper behavior **if you store your password in `~/.pypirc`**, but not if the password is omitted.
  # Okay, so...?
  
  I am aware that you can run
  
  ```
  python setup.py sdist register -r pypitest upload -r pypitest
  ```
  
  As a workaround, but it stands to reason that **if you can register a package without uploading it, then you should also be able to upload a package without registering it**, regardless of if a password has been specified in your `~/.pypirc` file.
  # Steps to reproduce
  1. Remove your pypi password from `~/.pypirc`
  2. Find a project that you wish to upload to a pypi server (I used [my example repository](https://github.com/brookskindle/hellopypi) for this)
  3. Run `python setup.py sdist upload -r target_pypi_server`
  # Setuptools version
  
  setuptools (20.9.0) -- from `pip list` in my virtualenv
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `setuptools/command/upload.py`
  Content:
  ```
  1 from distutils.command import upload as orig
  2 
  3 
  4 class upload(orig.upload):
  5     """
  6     Override default upload behavior to look up password
  7     in the keyring if available.
  8     """
  9 
  10     def finalize_options(self):
  11         orig.upload.finalize_options(self)
  12         self.password or self._load_password_from_keyring()
  13 
  14     def _load_password_from_keyring(self):
  15         """
  16         Attempt to load password from keyring. Suppress Exceptions.
  17         """
  18         try:
  19             keyring = __import__('keyring')
  20             self.password = keyring.get_password(self.repository,
  21                 self.username)
  22         except Exception:
  23             pass
  24
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py
  --- a/setuptools/command/upload.py
  +++ b/setuptools/command/upload.py
  @@ -3,13 +3,18 @@
   
   class upload(orig.upload):
       """
  -    Override default upload behavior to look up password
  -    in the keyring if available.
  +    Override default upload behavior to obtain password
  +    in a variety of different ways.
       """
   
       def finalize_options(self):
           orig.upload.finalize_options(self)
  -        self.password or self._load_password_from_keyring()
  +        # Attempt to obtain password. Short circuit evaluation at the first
  +        # sign of success.
  +        self.password = (
  +            self.password or self._load_password_from_keyring() or
  +            self._prompt_for_password()
  +        )
   
       def _load_password_from_keyring(self):
           """
  @@ -17,7 +22,22 @@
           """
           try:
               keyring = __import__('keyring')
  -            self.password = keyring.get_password(self.repository,
  -                self.username)
  +            password = keyring.get_password(self.repository, self.username)
           except Exception:
  -            pass
  +            password = None
  +        finally:
  +            return password
  +
  +    def _prompt_for_password(self):
  +        """
  +        Prompt for a password on the tty. Suppress Exceptions.
  +        """
  +        password = None
  +        try:
  +            import getpass
  +            while not password:
  +                password = getpass.getpass()
  +        except (Exception, KeyboardInterrupt):
  +            password = None
  +        finally:
  +            return password
  
verification_info: {"golden_diff": "diff --git a/setuptools/command/upload.py b/setuptools/command/upload.py\n--- a/setuptools/command/upload.py\n+++ b/setuptools/command/upload.py\n@@ -3,13 +3,18 @@\n \n class upload(orig.upload):\n     \"\"\"\n-    Override default upload behavior to look up password\n-    in the keyring if available.\n+    Override default upload behavior to obtain password\n+    in a variety of different ways.\n     \"\"\"\n \n     def finalize_options(self):\n         orig.upload.finalize_options(self)\n-        self.password or self._load_password_from_keyring()\n+        # Attempt to obtain password. Short circuit evaluation at the first\n+        # sign of success.\n+        self.password = (\n+            self.password or self._load_password_from_keyring() or\n+            self._prompt_for_password()\n+        )\n \n     def _load_password_from_keyring(self):\n         \"\"\"\n@@ -17,7 +22,22 @@\n         \"\"\"\n         try:\n             keyring = __import__('keyring')\n-            self.password = keyring.get_password(self.repository,\n-                self.username)\n+            password = keyring.get_password(self.repository, self.username)\n         except Exception:\n-            pass\n+            password = None\n+        finally:\n+            return password\n+\n+    def _prompt_for_password(self):\n+        \"\"\"\n+        Prompt for a password on the tty. Suppress Exceptions.\n+        \"\"\"\n+        password = None\n+        try:\n+            import getpass\n+            while not password:\n+                password = getpass.getpass()\n+        except (Exception, KeyboardInterrupt):\n+            password = None\n+        finally:\n+            return password\n", "issue": "upload command doesn't prompt for password; raises TypeError\n# Problem statement\n\nIf the `~/.pypirc` file does not contain a password like so:\n\n``` ini\n[distutils]\nindex-servers = \n    pypitest\n\n[pypitest]\nrepository = https://testpypi.python.org/pypi\nusername = my_username\n; Note the lack of a password\n```\n\nThen uploading the package\n\n```\npython setup.py sdist upload -r pypitest\n```\n\nFails to prompt the user for his password and instead raises a TypeError (output truncated)\n\n```\nrunning upload\nTraceback (most recent call last):\n  File \"setup.py\", line 16, in <module>\n    keywords=[\"test\", \"hello\"]\n  File \"/usr/lib/python2.7/distutils/core.py\", line 151, in setup\n    dist.run_commands()\n  File \"/usr/lib/python2.7/distutils/dist.py\", line 953, in run_commands\n    self.run_command(cmd)\n  File \"/usr/lib/python2.7/distutils/dist.py\", line 972, in run_command\n    cmd_obj.run()\n  File \"/usr/lib/python2.7/distutils/command/upload.py\", line 60, in run\n    self.upload_file(command, pyversion, filename)\n  File \"/usr/lib/python2.7/distutils/command/upload.py\", line 135, in upload_file\n    self.password)\nTypeError: cannot concatenate 'str' and 'NoneType' objects\n```\n\n**This is different** than the behavior of the `register` command, which prompts the user for a password before continuing.\n\n```\npython setup.py sdist register -r pypitest\n```\n\n(output truncated)\n\n```\nCreating tar archive\nremoving 'HelloPyPi-0.0.1.dev0' (and everything under it)\nrunning register\nPassword: \n```\n\n> Note that the `register` and the `upload` command exhibit the proper behavior **if you store your password in `~/.pypirc`**, but not if the password is omitted.\n# Okay, so...?\n\nI am aware that you can run\n\n```\npython setup.py sdist register -r pypitest upload -r pypitest\n```\n\nAs a workaround, but it stands to reason that **if you can register a package without uploading it, then you should also be able to upload a package without registering it**, regardless of if a password has been specified in your `~/.pypirc` file.\n# Steps to reproduce\n1. Remove your pypi password from `~/.pypirc`\n2. Find a project that you wish to upload to a pypi server (I used [my example repository](https://github.com/brookskindle/hellopypi) for this)\n3. Run `python setup.py sdist upload -r target_pypi_server`\n# Setuptools version\n\nsetuptools (20.9.0) -- from `pip list` in my virtualenv\n\n", "before_files": [{"content": "from distutils.command import upload as orig\n\n\nclass upload(orig.upload):\n    \"\"\"\n    Override default upload behavior to look up password\n    in the keyring if available.\n    \"\"\"\n\n    def finalize_options(self):\n        orig.upload.finalize_options(self)\n        self.password or self._load_password_from_keyring()\n\n    def _load_password_from_keyring(self):\n        \"\"\"\n        Attempt to load password from keyring. Suppress Exceptions.\n        \"\"\"\n        try:\n            keyring = __import__('keyring')\n            self.password = keyring.get_password(self.repository,\n                self.username)\n        except Exception:\n            pass\n", "path": "setuptools/command/upload.py"}], "after_files": [{"content": "from distutils.command import upload as orig\n\n\nclass upload(orig.upload):\n    \"\"\"\n    Override default upload behavior to obtain password\n    in a variety of different ways.\n    \"\"\"\n\n    def finalize_options(self):\n        orig.upload.finalize_options(self)\n        # Attempt to obtain password. Short circuit evaluation at the first\n        # sign of success.\n        self.password = (\n            self.password or self._load_password_from_keyring() or\n            self._prompt_for_password()\n        )\n\n    def _load_password_from_keyring(self):\n        \"\"\"\n        Attempt to load password from keyring. Suppress Exceptions.\n        \"\"\"\n        try:\n            keyring = __import__('keyring')\n            password = keyring.get_password(self.repository, self.username)\n        except Exception:\n            password = None\n        finally:\n            return password\n\n    def _prompt_for_password(self):\n        \"\"\"\n        Prompt for a password on the tty. Suppress Exceptions.\n        \"\"\"\n        password = None\n        try:\n            import getpass\n            while not password:\n                password = getpass.getpass()\n        except (Exception, KeyboardInterrupt):\n            password = None\n        finally:\n            return password\n", "path": "setuptools/command/upload.py"}]}