#NEWLINE# def parse_invocation( self , invocation , controller_tag ) : #NEWLINE# #INDENT# '\n        Given an invocation string, determine which part is the path, the program,\n        and the args.\n        ' #NEWLINE# if invocation . endswith ( '/' ) : #NEWLINE# #INDENT# invocation = invocation [ : ( - 1 ) ] #NEWLINE# #UNINDENT# if ( not invocation . startswith ( '/' ) ) : #NEWLINE# #INDENT# invocation = ( '/' + invocation ) #NEWLINE# #UNINDENT# if ( invocation == '' ) : #NEWLINE# #INDENT# invocation = '/' #NEWLINE# #UNINDENT# all_programs = self . get_urls ( controllers = [ controller_tag ] ) #NEWLINE# matching_paths = set ( ) #NEWLINE# for program_path in sorted ( all_programs ) : #NEWLINE# #INDENT# if invocation . startswith ( program_path ) : #NEWLINE# #INDENT# matching_paths . add ( program_path ) #NEWLINE# #UNINDENT# #UNINDENT# longest = '' #NEWLINE# for path in matching_paths : #NEWLINE# #INDENT# longest = ( path if ( len ( path ) > len ( longest ) ) else longest ) #NEWLINE# #UNINDENT# matching_path = longest #NEWLINE# program = self . get_program ( matching_path , controller = controller_tag ) #NEWLINE# if ( not matching_path ) : #NEWLINE# #INDENT# raise ProgramNotFound ( ( "Can't find %s" % invocation ) ) #NEWLINE# #UNINDENT# program_name = matching_path . split ( '/' ) [ ( - 1 ) ] #NEWLINE# path = ( '/' . join ( matching_path . split ( '/' ) [ : ( - 1 ) ] ) + '/' ) #NEWLINE# args_fragment = invocation [ len ( matching_path ) : ] #NEWLINE# superformat = None #NEWLINE# if args_fragment . startswith ( '.' ) : #NEWLINE# #INDENT# superformat = args_fragment . split ( '/' ) [ 0 ] [ 1 : ] #NEWLINE# args = args_fragment . split ( '/' ) [ 1 : ] #NEWLINE# args_fragment = '/' . join ( args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args = ( args_fragment . split ( '/' ) [ 1 : ] if args_fragment else [ ] ) #NEWLINE# args_fragment = ( args_fragment [ 1 : ] if ( args_fragment and ( args_fragment [ 0 ] == '/' ) ) else args_fragment ) #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'program' : program , #NEWLINE# 'program_name' : program_name , #NEWLINE# 'superformat' : superformat , #NEWLINE# 'superformat_mime' : super_accept_to_mimetype ( superformat ) , #NEWLINE# 'args' : args , #NEWLINE# 'raw_args' : args_fragment , #NEWLINE# 'path' : path , #NEWLINE# 'invocation' : invocation , #NEWLINE# #UNINDENT# }