Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: third_party/google-endpoints/setuptools/command/upload.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/google-endpoints/setuptools/command/upload.py
diff --git a/third_party/google-endpoints/setuptools/command/upload.py b/third_party/google-endpoints/setuptools/command/upload.py
new file mode 100644
index 0000000000000000000000000000000000000000..484baa5a538a3b4828ddff54bb4a2f362999675c
--- /dev/null
+++ b/third_party/google-endpoints/setuptools/command/upload.py
@@ -0,0 +1,38 @@
+import getpass
+from distutils.command import upload as orig
+
+
+class upload(orig.upload):
+ """
+ Override default upload behavior to obtain password
+ in a variety of different ways.
+ """
+
+ def finalize_options(self):
+ orig.upload.finalize_options(self)
+ # 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):
+ """
+ Attempt to load password from keyring. Suppress Exceptions.
+ """
+ try:
+ keyring = __import__('keyring')
+ return keyring.get_password(self.repository, self.username)
+ except Exception:
+ pass
+
+ def _prompt_for_password(self):
+ """
+ Prompt for a password on the tty. Suppress Exceptions.
+ """
+ try:
+ return getpass.getpass()
+ except (Exception, KeyboardInterrupt):
+ pass

Powered by Google App Engine
This is Rietveld 408576698