#NEWLINE# def _name_from_project_path( path , project , template ) : #NEWLINE# #INDENT# "Validate a URI path and get the leaf object's name.\n\n    :type path: string\n    :param path: URI path containing the name.\n\n    :type project: string\n    :param project: The project associated with the request. It is\n                    included for validation purposes.\n\n    :type template: string\n    :param template: Template regex describing the expected form of the path.\n                     The regex must have two named groups, 'project' and\n                     'name'.\n\n    :rtype: string\n    :returns: Name parsed from ``path``.\n    :raises: :class:`ValueError` if the ``path`` is ill-formed or if\n             the project from the ``path`` does not agree with the\n             ``project`` passed in.\n    " #NEWLINE# if isinstance ( template , str ) : #NEWLINE# #INDENT# template = re . compile ( template ) #NEWLINE# #UNINDENT# match = template . match ( path ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# raise ValueError ( ( 'path "%s" did not match expected pattern "%s"' % ( path , template . pattern ) ) ) #NEWLINE# #UNINDENT# found_project = match . group ( 'project' ) #NEWLINE# if ( found_project != project ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Project from client (%s) should agree with project from resource(%s).' % ( project , found_project ) ) ) #NEWLINE# #UNINDENT# return match . group ( 'name' )