def compile_uri_template(template):
 if (not isinstance(template, six.string_types)):
  raise TypeError('uri_template is not a string')
 if (not template.startswith('/')):
  raise ValueError("uri_template must start with '/'")
 if ('//' in template):
  raise ValueError("uri_template may not contain '//'")
 if ((template != '/') and template.endswith('/')):
  template = template[:(-1)]
 expression_pattern = '{([a-zA-Z]\\w*)}'
 fields = set(re.findall(expression_pattern, template))
 escaped = re.sub('[\\.\\(\\)\\[\\]\\?\\*\\+\\^\\|]', '\\\\\\g<0>', template)
 pattern = re.sub(expression_pattern, '(?P<\\1>[^/]+)', escaped)
 pattern = (('\\A' + pattern) + '\\Z')
 return (fields, re.compile(pattern, re.IGNORECASE))

def compile_uri_template ( template ) : if ( not isinstance ( template , six . string_types ) ) : raise TypeError ( 'uri_template is not a string' ) if ( not template . startswith ( '/' ) ) : raise ValueError ( "uri_template must start with '/'" ) if ( '//' in template ) : raise ValueError ( "uri_template may not contain '//'" ) if ( ( template != '/' ) and template . endswith ( '/' ) ) : template = template [ : ( - 1 ) ] expression_pattern = '{([a-zA-Z]\\w*)}' fields = set ( re . findall ( expression_pattern , template ) ) escaped = re . sub ( '[\\.\\(\\)\\[\\]\\?\\*\\+\\^\\|]' , '\\\\\\g<0>' , template ) pattern = re . sub ( expression_pattern , '(?P<\\1>[^/]+)' , escaped ) pattern = ( ( '\\A' + pattern ) + '\\Z' ) return ( fields , re . compile ( pattern , re . IGNORECASE ) )
compile the given uri template string into a pattern matcher .