#NEWLINE# def parse_bits( parser , bits , params , varargs , varkw , defaults , takes_context , name ) : #NEWLINE# #INDENT# '\n    Parse bits for template tag helpers simple_tag and inclusion_tag, in\n    particular by detecting syntax errors and by extracting positional and\n    keyword arguments.\n    ' #NEWLINE# if takes_context : #NEWLINE# #INDENT# if ( params [ 0 ] == 'context' ) : #NEWLINE# #INDENT# params = params [ 1 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' is decorated with takes_context=True so it must have a first argument of 'context'" % name ) ) #NEWLINE# #UNINDENT# #UNINDENT# args = [ ] #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# unhandled_params = list ( params ) #NEWLINE# for bit in bits : #NEWLINE# #INDENT# kwarg = token_kwargs ( [ bit ] , parser ) #NEWLINE# if kwarg : #NEWLINE# #INDENT# ( param , value ) = kwarg . popitem ( ) #NEWLINE# if ( ( varkw not in params ) and ( varkw is None ) ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' received unexpected keyword argument '%s'" % ( name , param ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param in kwargs ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' received multiple values for keyword argument '%s'" % ( name , param ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs [ str ( param ) ] = value #NEWLINE# if ( param in unhandled_params ) : #NEWLINE# #INDENT# unhandled_params . remove ( param ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if kwargs : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' received some positional argument(s) after some keyword argument(s)" % name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args . append ( parser . compile_filter ( bit ) ) #NEWLINE# try : #NEWLINE# #INDENT# unhandled_params . pop ( 0 ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# if ( varargs is None ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' received too many positional arguments" % name ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( defaults is not None ) : #NEWLINE# #INDENT# unhandled_params = unhandled_params [ : ( - len ( defaults ) ) ] #NEWLINE# #UNINDENT# if unhandled_params : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( "'%s' did not receive value(s) for the argument(s): %s" % ( name , ', ' . join ( ( ( "'%s'" % p ) for p in unhandled_params ) ) ) ) ) #NEWLINE# #UNINDENT# return ( args , kwargs )