def testPathMultiParams(self): self.assertEqual( ['bvalue', 'cvalue'], resource_util.GetParamsFromPath('//a/b/{bvalue}/c/{cvalue}')) self.assertEqual( ['bvalue', 'cvalue'], resource_util.GetParamsFromPath('//a/b/{bvalue}/c/{cvalue}/d')) self.assertEqual([ 'bvalue', 'cvalue' ], resource_util.GetParamsFromPath('//a/b/{bvalue}/c/{cvalue}:custom')) self.assertEqual(['bvalue', 'cvalue'], resource_util.GetParamsFromPath( '//a/b/{bvalue}/c/{cvalue}/d:custom'))
def _MakeResourceCollection(self, api_version, collection_name, path, flat_path=None): """Make resource collection object given its name and path.""" if flat_path == path: flat_path = None # Normalize base url so it includes api_version. url = self.base_url + path url_api_name, url_api_vesion, path = ( resource_util.SplitDefaultEndpointUrl(url)) if url_api_vesion != api_version: raise UnsupportedDiscoveryDoc( 'Collection {0} for version {1}/{2} is using url {3} ' 'with version {4}'.format(collection_name, self.api_name, api_version, url, url_api_vesion)) if flat_path: _, _, flat_path = resource_util.SplitDefaultEndpointUrl( self.base_url + flat_path) # Use url_api_name instead as it is assumed to be source of truth. # Also note that api_version not always equal to url_api_version, # this is the case where api_version is an alias. url = url[:-len(path)] return resource_util.CollectionInfo( url_api_name, api_version, url, self.docs_url, collection_name, path, {DEFAULT_PATH_NAME: flat_path} if flat_path else {}, resource_util.GetParamsFromPath(path))
def __init__(self, service, name, api_collection, method_config): self._service = service self._method_name = name self.collection = api_collection self.name = method_config.method_id dotted_path = self.collection.full_name + NAME_SEPARATOR if self.name.startswith(dotted_path): self.name = self.name[len(dotted_path):] self.path = _RemoveVersionPrefix( self.collection.api_version, method_config.relative_path) self.params = method_config.ordered_params if method_config.flat_path: self.detailed_path = _RemoveVersionPrefix( self.collection.api_version, method_config.flat_path) self.detailed_params = resource.GetParamsFromPath(method_config.flat_path) else: self.detailed_path = self.path self.detailed_params = self.params self.http_method = method_config.http_method self.request_field = method_config.request_field self.request_type = method_config.request_type_name self.response_type = method_config.response_type_name self._request_collection = self._RequestCollection() # Keep track of method query parameters self.query_params = method_config.query_params
def MakeResourceCollection(self, collection_name, path, enable_uri_parsing, api_version): _, url_api_version, _ = resource_util.SplitDefaultEndpointUrl( self.base_url) if url_api_version: base_url = self.base_url else: base_url = '{}{}/'.format(self.base_url, api_version) return resource_util.CollectionInfo( self.api_name, api_version, base_url, self.docs_url, collection_name, path, {}, resource_util.GetParamsFromPath(path), enable_uri_parsing)
def _ExtractResources(api_name, api_version, base_url, infos): """Extract resource definitions from discovery doc.""" collections = [] for name, info in infos.iteritems(): if name == 'methods': get_method = info.get('get') if get_method: method_id = get_method['id'] match = _METHOD_ID_RE.match(method_id) if match: collection_name = match.group('collection') request_type = ''.join([ s[0].upper() + s[1:] for s in re.findall(r'[^\._]+', collection_name) ]) + 'GetRequest' # Remove api name from collection. It might not match passed in, or # even api name in url. We choose to use api name as defined by url. collection_name = collection_name.split('.', 1)[1] flat_path = get_method.get('flatPath') path = get_method.get('path') if flat_path == path: flat_path = None # Normalize base url so it includes api_version. url = base_url + path url_api_name, _, path = resource_util.SplitDefaultEndpointUrl( url) if flat_path: _, _, flat_path = resource_util.SplitDefaultEndpointUrl( base_url + flat_path) # Use url_api_name instead as it is assumed to be source of truth. # Also note that api_version not always equal to url_api_version, # this is the case where api_version is an alias. url = url[:-len(path)] collection_info = resource_util.CollectionInfo( url_api_name, api_version, url, collection_name, request_type, path, {_DEFAULT_PATH_NAME: flat_path} if flat_path else {}, resource_util.GetParamsFromPath(path)) collections.append(collection_info) else: subresource_collections = _ExtractResources( api_name, api_version, base_url, info) collections.extend(subresource_collections) return collections
def MakeResourceCollection(self, collection_name, path, enable_uri_parsing, api_version): return resource_util.CollectionInfo( self.api_name, api_version, self.base_url, self.docs_url, collection_name, path, {}, resource_util.GetParamsFromPath(path), enable_uri_parsing)
def MakeResourceCollection(self, collection_name, path, api_version=None): api_version = api_version or self.api_verison return resource_util.CollectionInfo( self.api_name, api_version, self.base_url, collection_name, path, {}, resource_util.GetParamsFromPath(path))
def testPathSingleOnlyParams(self): self.assertEqual(['bvalue'], resource_util.GetParamsFromPath('{+bvalue}')) self.assertEqual(['bvalue'], resource_util.GetParamsFromPath('{+bvalue}:custom'))
def testPathSingleParams(self): self.assertEqual(['bvalue'], resource_util.GetParamsFromPath('//a/b/{bvalue}/c'))
def testPathWithNoParams(self): self.assertEqual([], resource_util.GetParamsFromPath('//a/b/c'))
def testEmptyPath(self): self.assertEqual([], resource_util.GetParamsFromPath(''))