<s> from inspect import getargspec <EOL> from django . template import Library , base <EOL> from . . import get_option <EOL> register = Library ( ) <EOL> def optional_assignment_tag ( func = None , takes_context = None , name = None ) : <EOL> """<STR_LIT>""" <EOL> def dec ( func ) : <EOL> params , varargs , varkw , defaults = getargspec ( func ) <EOL> class AssignmentNode ( base . TagHelperNode ) : <EOL> def __init__ ( self , takes_context , args , kwargs , target_var = None ) : <EOL> super ( AssignmentNode , self ) . __init__ ( takes_context , args , kwargs ) <EOL> self . target_var = target_var <EOL> def render ( self , context ) : <EOL> resolved_args , resolved_kwargs = self . get_resolved_arguments ( context ) <EOL> output = func ( * resolved_args , ** resolved_kwargs ) <EOL> if self . target_var is None : <EOL> return output <EOL> else : <EOL> context [ self . target_var ] = output <EOL> return '<STR_LIT>' <EOL> function_name = ( name or <EOL> getattr ( func , '<STR_LIT>' , func ) . __name__ ) <EOL> def compile_func ( parser , token ) : <EOL> bits = token . split_contents ( ) [ <NUM_LIT:1> : ] <EOL> if len ( bits ) < <NUM_LIT:2> or bits [ - <NUM_LIT:2> ] != '<STR_LIT>' : <EOL> target_var = None <EOL> else : <EOL> target_var = bits [ - <NUM_LIT:1> ] <EOL> bits = bits [ : - <NUM_LIT:2> ] <EOL> args , kwargs = base . parse_bits ( parser , bits , params , <EOL> varargs , varkw , defaults , takes_context , function_name ) <EOL> return AssignmentNode ( takes_context , args , kwargs , target_var ) <EOL> compile_func . __doc__ = func . __doc__ <EOL> register . tag ( function_name , compile_func ) <EOL> return func <EOL> if func is None : <EOL> return dec <EOL> elif callable ( func ) : <EOL> return dec ( func ) <EOL> else : <EOL> raise base . TemplateSyntaxError ( "<STR_LIT>" ) <EOL> @ optional_assignment_tag ( name = '<STR_LIT>' ) <EOL> def do_get_option ( option_name , default = None ) : <EOL> """<STR_LIT>""" <EOL> return get_option ( option_name , default = default ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def do_get_option_filter ( option_name , default = None ) : <EOL> """<STR_LIT>""" <EOL> return get_option ( option_name , default = default ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def do_or_option_filter ( value , option_name ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> value = get_option ( option_name ) <EOL> return value </s>
