From 083cd45914fcf593cb2e5eeefbf987d30f74135a Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Mon, 3 Sep 2012 17:37:18 +0000 Subject: [PATCH] Fix apply_issue.py to work on python 2.6 with anonymous request. Fix RawCheckout support in apply_issue.py. TBR=rogerta@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/10908063 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@154703 0039d316-1c4b-4281-b951-d872f2087c98 --- apply_issue.py | 9 ++++++--- rietveld.py | 4 ++++ third_party/upload.py | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apply_issue.py b/apply_issue.py index 3d606466e..22018742d 100755 --- a/apply_issue.py +++ b/apply_issue.py @@ -59,8 +59,11 @@ def main(): obj = rietveld.Rietveld(options.server, '', None) try: properties = obj.get_issue_properties(options.issue, False) - except rietveld.upload.ClientLoginError: - # Requires login. + except rietveld.upload.ClientLoginError, e: + if sys.stdout.closed: + print >> sys.stderr, 'Accessing the issue requires login.' + return 1 + print('Accessing the issue requires login.') obj = rietveld.Rietveld(options.server, None, None) properties = obj.get_issue_properties(options.issue, False) @@ -86,7 +89,7 @@ def main(): elif scm_type == 'git': scm_obj = checkout.GitCheckoutBase(options.root_dir, None, None) elif scm_type == None: - scm_obj = checkout.RawCheckout(options.root_dir, None) + scm_obj = checkout.RawCheckout(options.root_dir, None, None) else: parser.error('Couldn\'t determine the scm') diff --git a/rietveld.py b/rietveld.py index fd00e93ab..ee8f00a87 100644 --- a/rietveld.py +++ b/rietveld.py @@ -47,8 +47,12 @@ class Rietveld(object): extra_headers=extra_headers or {}) else: if email == '': + # If email is given as an empty string, then assume we want to make + # requests that do not need authentication. Bypass authentication by + # setting the flag to True. get_creds = lambda: (email, None) self.rpc_server = upload.HttpRpcServer(url, get_creds) + self.rpc_server.authenticated = True else: self.rpc_server = upload.GetRpcServer(url, email) diff --git a/third_party/upload.py b/third_party/upload.py index 581ab4d8c..abd17c742 100755 --- a/third_party/upload.py +++ b/third_party/upload.py @@ -165,8 +165,13 @@ class ClientLoginError(urllib2.HTTPError): def __init__(self, url, code, msg, headers, args): urllib2.HTTPError.__init__(self, url, code, msg, headers, None) self.args = args + self._reason = args["Error"] self.info = args.get("Info", None) + @property + def reason(self): + return self._reason + class AbstractRpcServer(object): """Provides a common interface for a simple RPC server."""