#NEWLINE# def parse_macro_params( token ) : #NEWLINE# #INDENT# '\n    Common parsing logic for both use_macro and macro_block\n    ' #NEWLINE# try : #NEWLINE# #INDENT# bits = token . split_contents ( ) #NEWLINE# ( tag_name , macro_name , values ) = ( bits [ 0 ] , bits [ 1 ] , bits [ 2 : ] ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# raise template . TemplateSyntaxError ( '{0} tag requires at least one argument (macro name)' . format ( token . contents . split ( ) [ 0 ] ) ) #NEWLINE# #UNINDENT# args = [ ] #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# kwarg_regex = '^([A-Za-z_][\\w_]*)=(".*"|{0}.*{0}|[A-Za-z_][\\w_]*)$' . format ( "'" ) #NEWLINE# arg_regex = '^([A-Za-z_][\\w_]*|".*"|{0}.*{0}|(\\d+))$' . format ( "'" ) #NEWLINE# for value in values : #NEWLINE# #INDENT# kwarg_match = regex_match ( kwarg_regex , value ) #NEWLINE# if kwarg_match : #NEWLINE# #INDENT# kwargs [ kwarg_match . groups ( ) [ 0 ] ] = template . Variable ( kwarg_match . groups ( ) [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# arg_match = regex_match ( arg_regex , value ) #NEWLINE# if arg_match : #NEWLINE# #INDENT# args . append ( template . Variable ( arg_match . groups ( ) [ 0 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise template . TemplateSyntaxError ( 'Malformed arguments to the {0} tag.' . format ( tag_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( tag_name , macro_name , args , macro_name )