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

Side by Side Diff: rietveld.py

Issue 9536014: Fix workaround for ErrorExit(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 """Defines class Rietveld to easily access a rietveld instance. 4 """Defines class Rietveld to easily access a rietveld instance.
5 5
6 Security implications: 6 Security implications:
7 7
8 The following hypothesis are made: 8 The following hypothesis are made:
9 - Rietveld enforces: 9 - Rietveld enforces:
10 - Nobody else than issue owner can upload a patch set 10 - Nobody else than issue owner can upload a patch set
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 """Sends a POST/GET to Rietveld. Returns the response body.""" 313 """Sends a POST/GET to Rietveld. Returns the response body."""
314 try: 314 try:
315 # Sadly, upload.py calls ErrorExit() which does a sys.exit(1) on HTTP 315 # Sadly, upload.py calls ErrorExit() which does a sys.exit(1) on HTTP
316 # 500 in AbstractRpcServer.Send(). 316 # 500 in AbstractRpcServer.Send().
317 old_error_exit = upload.ErrorExit 317 old_error_exit = upload.ErrorExit
318 def trap_http_500(msg): 318 def trap_http_500(msg):
319 """Converts an incorrect ErrorExit() call into a HTTPError exception.""" 319 """Converts an incorrect ErrorExit() call into a HTTPError exception."""
320 m = re.search(r'(50\d) Server Error', msg) 320 m = re.search(r'(50\d) Server Error', msg)
321 if m: 321 if m:
322 # Fake an HTTPError exception. Cheezy. :( 322 # Fake an HTTPError exception. Cheezy. :(
323 raise urllib2.HTTPError( 323 raise urllib2.HTTPError(request_path, m.group(1), msg, None, None)
324 request_path, m.group(1), e.args[0], None, None)
325 old_error_exit(msg) 324 old_error_exit(msg)
326 upload.ErrorExit = trap_http_500 325 upload.ErrorExit = trap_http_500
327 326
328 maxtries = 5 327 maxtries = 5
329 for retry in xrange(maxtries): 328 for retry in xrange(maxtries):
330 try: 329 try:
331 logging.debug('%s' % request_path) 330 logging.debug('%s' % request_path)
332 result = self.rpc_server.Send(request_path, **kwargs) 331 result = self.rpc_server.Send(request_path, **kwargs)
333 # Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content. 332 # Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content.
334 # How nice. 333 # How nice.
335 return result 334 return result
336 except urllib2.HTTPError, e: 335 except urllib2.HTTPError, e:
337 if retry >= (maxtries - 1): 336 if retry >= (maxtries - 1):
338 raise 337 raise
339 if e.code not in (500, 502, 503): 338 if e.code not in (500, 502, 503):
340 raise 339 raise
341 except urllib2.URLError, e: 340 except urllib2.URLError, e:
342 if retry >= (maxtries - 1): 341 if retry >= (maxtries - 1):
343 raise 342 raise
344 if not 'Name or service not known' in e.reason: 343 if not 'Name or service not known' in e.reason:
345 # Usually internal GAE flakiness. 344 # Usually internal GAE flakiness.
346 raise 345 raise
347 # If reaching this line, loop again. Uses a small backoff. 346 # If reaching this line, loop again. Uses a small backoff.
348 time.sleep(1+maxtries*2) 347 time.sleep(1+maxtries*2)
349 finally: 348 finally:
350 upload.ErrorExit = old_error_exit 349 upload.ErrorExit = old_error_exit
351 350
352 # DEPRECATED. 351 # DEPRECATED.
353 Send = get 352 Send = get
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698