• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3# found in the LICENSE file.
4
5import json
6import logging
7
8from google.appengine.api import urlfetch
9from google.appengine.runtime import apiproxy_errors
10
11from base import constants
12
13
14def BuildUrl(master_name, url):
15  return '%s/%s/%s' % (constants.BUILDBOT_BASE_URL, master_name, url)
16
17
18def FetchData(url):
19  try:
20    return json.loads(FetchText(url))
21  except ValueError:
22    logging.warning('Data is corrupt: %s', url)
23    raise
24
25
26def FetchText(url):
27  logging.debug('Retrieving %s', url)
28  try:
29    return urlfetch.fetch(url).content
30  except (apiproxy_errors.DeadlineExceededError, urlfetch.DownloadError,
31          urlfetch.InternalTransientError):
32    # Could be intermittent; try again.
33    try:
34      return urlfetch.fetch(url).content
35    except:
36      logging.error('Error retrieving URL: %s', url)
37      raise
38  except:
39    logging.error('Error retrieving URL: %s', url)
40    raise
41