OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 | 4 |
5 """Functions for getting commit information from Gitiles.""" | 5 """Functions for getting commit information from Gitiles.""" |
6 | 6 |
7 import base64 | 7 import base64 |
8 import json | 8 import json |
9 | 9 |
10 from google.appengine.api import urlfetch | 10 from google.appengine.api import urlfetch |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 def _Request(url): | 93 def _Request(url): |
94 """Requests a URL with one retry.""" | 94 """Requests a URL with one retry.""" |
95 try: | 95 try: |
96 return _RequestAndProcessHttpErrors(url) | 96 return _RequestAndProcessHttpErrors(url) |
97 except urlfetch.Error: # Maybe it's a transient error. Retry once. | 97 except urlfetch.Error: # Maybe it's a transient error. Retry once. |
98 return _RequestAndProcessHttpErrors(url) | 98 return _RequestAndProcessHttpErrors(url) |
99 | 99 |
100 | 100 |
101 def _RequestAndProcessHttpErrors(url): | 101 def _RequestAndProcessHttpErrors(url): |
102 """Requests a URL, converting HTTP errors to Python exceptions.""" | 102 """Requests a URL, converting HTTP errors to Python exceptions.""" |
103 response = urlfetch.fetch(url) | 103 response = urlfetch.fetch(url, deadline=10) |
104 | 104 |
105 if response.status_code == 404: | 105 if response.status_code == 404: |
106 raise NotFoundError('Server returned HTTP code %d for %s' % | 106 raise NotFoundError('Server returned HTTP code %d for %s' % |
107 (response.status_code, url)) | 107 (response.status_code, url)) |
108 elif response.status_code != 200: | 108 elif response.status_code != 200: |
109 raise urlfetch.Error('Server returned HTTP code %d for %s' % | 109 raise urlfetch.Error('Server returned HTTP code %d for %s' % |
110 (response.status_code, url)) | 110 (response.status_code, url)) |
111 | 111 |
112 return response.content | 112 return response.content |
OLD | NEW |