def get()

in server/scripts/redirector.py [0:0]


  def get(self, *args, **kwargs):
    """The main entry point for handling the URL for those with ApiDocs as the
    handler. See http://webapp-improved.appspot.com/api/webapp2.html?highlight=
    redirecthandler#webapp2.RedirectHandler.get.

    Arguments:
    - args: Positional arguments passed to this URL handler
    - kwargs: Dictionary arguments passed to the hander; expecting at least one
      item in the dictionary with a key of 'path', which was populated from the
      regular expression matching in Route."""
    channel = self.get_channel()

    # this is serving all paths, so check to make sure version is valid pattern
    # else redirect to stable
    # /dev/1.15.0-dev.5.1/index.html
    if channel:
      length = len(channel) + 2
    else:
      length = 1
    request = self.request.path[length:]

    index = request.find('/')
    if index != -1:
      version_num = request[:index]
      match = re.match(r'^-?[0-9]+$', version_num)
      if match:
        if int(version_num) > 136051:
          path = request[index+1:]
          if not channel:
            return self.redirect('/be/%s/%s' % (version_num, path))
        else:
          return self.redirect('/stable')
      else:
        match = re.match(r'(\d+\.){2}\d+([\+-]([\.a-zA-Z0-9-\+])*)?', version_num)
        latest = self.get_latest_version(channel or 'stable')
        if match:
          if not channel:
            return self.redirect('/stable/%s/index.html' % latest)
        else:
          return self.redirect('/%s/%s/%s' % (channel or 'stable', latest, request))
    else:
      match = re.match(r'(\d+\.){2}\d+([\+-]([\.a-zA-Z0-9-\+])*)?', request)
      if match:
        return self.redirect('/%s/index.html' % request)
      else:
        return self.redirect('/stable')

    my_path = self.resolve_doc_path(channel)

    gcs_path = '/gs%s' % my_path
    if not gcs_path:
      self.error(404)
      return

    gs_key = blobstore.create_gs_key(gcs_path)
    age = self.get_cache_age(gcs_path)

    self.response.headers['Cache-Control'] = 'max-age=' + \
       str(age) + ',s-maxage=' + str(age)

    self.response.headers['Access-Control-Allow-Origin'] = '*'

    # is there a better way to check if a file exists in cloud storage?
    # AE will serve a 500 if the file doesn't exist, but that should
    # be a 404

    path_exists = memcache.get(gcs_path)
    if path_exists == "1":
        self.send_blob(gs_key)
    else:
      try:
        # just check for existence
        cloudstorage.open(my_path, 'r').close()
        memcache.add(key=gcs_path, value="1", time=ONE_DAY)
        self.send_blob(gs_key)
      except Exception:
        memcache.add(key=gcs_path, value="0", time=ONE_DAY)
        logging.debug('Could not open ' + gcs_path + ', sending 404')
        self.error(404)