(self)
Sets template values concerning the path to the service.

    Sets rootUrl and servicePath from the values given or defaults based on what
    is available. Verifies them for safeness.  The hierarchy of the possible
    inputs is:
      use rootUrl + servicePath as the best choice if it exists (v1new)
      or rpcPath
      or use baseUrl (v1)
      or use basePath (v1)
      or restBasePath (v0.3)
      or default to 'api/version'

    Raises:
      ValueError: if the values available are inconsistent or disallowed.
Sets template values concerning the path to the service.
Sets template values concerning the path to the service .
def _NormalizeUrlComponents(self):
    """Sets template values concerning the path to the service.

    Sets rootUrl and servicePath from the values given or defaults based on what
    is available. Verifies them for safeness.  The hierarchy of the possible
    inputs is:
      use rootUrl + servicePath as the best choice if it exists (v1new)
      or rpcPath
      or use baseUrl (v1)
      or use basePath (v1)
      or restBasePath (v0.3)
      or default to 'api/version'

    Raises:
      ValueError: if the values available are inconsistent or disallowed.
    """
    # If both rootUrl and servicePath exist, they equal what is in baseUrl.
    root_url = self.values.get('rootUrl')
    service_path = self.values.get('servicePath')
    rpc_path = self.values.get('rpcPath')
    if root_url:
      # oauth2 has a servicePath of "". This is wierd but OK for that API, but
      # it means we must explicitly check against None.
      if service_path is not None:
        base_url = root_url + service_path
      elif rpc_path:
        base_url = rpc_path
      else:
        raise ValueError('Neither servicePath nor rpcPath is defined.')
    else:
      base_url = self.values.get('baseUrl')

    # If we have a full path ('https://superman.appspot.com/kryptonite/hurts'),
    # then go with that, otherwise just use the various things which might
    # hint at the servicePath.
    best_path = (base_url
                 or self.values.get('basePath')
                 or self.values.get('restBasePath')
                 or '/%s/%s/' % (self.values['name'], self.values['version']))
    if best_path.find('..') >= 0:
      raise ValueError('api path must not contain ".." (%s)' % best_path)
    # And let urlparse to the grunt work of normalizing and parsing.
    url_parts = urlparse.urlparse(best_path)

    scheme = url_parts.scheme or 'https'
    service_host = url_parts.netloc or _DEFAULT_SERVICE_HOST
    base_path = url_parts.path
    if not root_url:
      self._api.SetTemplateValue('rootUrl', '%s://%s/' % (scheme, service_host))
    if service_path is None:
      self._api.SetTemplateValue('servicePath', base_path[1:])

    # Make sure template writers do not revert
    self._api.DeleteTemplateValue('baseUrl')
    self._api.DeleteTemplateValue('basePath')
    self._api.DeleteTemplateValue('serviceHost')
def _NormalizeUrlComponents ( self ) : # If both rootUrl and servicePath exist, they equal what is in baseUrl. root_url = self . values . get ( 'rootUrl' ) service_path = self . values . get ( 'servicePath' ) rpc_path = self . values . get ( 'rpcPath' ) if root_url : # oauth2 has a servicePath of "". This is wierd but OK for that API, but # it means we must explicitly check against None. if service_path is not None : base_url = root_url + service_path elif rpc_path : base_url = rpc_path else : raise ValueError ( 'Neither servicePath nor rpcPath is defined.' ) else : base_url = self . values . get ( 'baseUrl' ) # If we have a full path ('https://superman.appspot.com/kryptonite/hurts'), # then go with that, otherwise just use the various things which might # hint at the servicePath. best_path = ( base_url or self . values . get ( 'basePath' ) or self . values . get ( 'restBasePath' ) or '/%s/%s/' % ( self . values [ 'name' ] , self . values [ 'version' ] ) ) if best_path . find ( '..' ) >= 0 : raise ValueError ( 'api path must not contain ".." (%s)' % best_path ) # And let urlparse to the grunt work of normalizing and parsing. url_parts = urlparse . urlparse ( best_path ) scheme = url_parts . scheme or 'https' service_host = url_parts . netloc or _DEFAULT_SERVICE_HOST base_path = url_parts . path if not root_url : self . _api . SetTemplateValue ( 'rootUrl' , '%s://%s/' % ( scheme , service_host ) ) if service_path is None : self . _api . SetTemplateValue ( 'servicePath' , base_path [ 1 : ] ) # Make sure template writers do not revert self . _api . DeleteTemplateValue ( 'baseUrl' ) self . _api . DeleteTemplateValue ( 'basePath' ) self . _api . DeleteTemplateValue ( 'serviceHost' )