<s> import tokenize <EOL> import warnings <EOL> from django import template <EOL> from django_assets import Bundle <EOL> from django_assets . env import get_env <EOL> from webassets import six <EOL> from webassets . exceptions import ImminentDeprecationWarning <EOL> def parse_debug_value ( value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , bool ) : <EOL> return value <EOL> try : <EOL> from webassets . env import parse_debug_value <EOL> return parse_debug_value ( value ) <EOL> except ValueError : <EOL> raise template . TemplateSyntaxError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % value ) <EOL> class AssetsNode ( template . Node ) : <EOL> BundleClass = Bundle <EOL> def __init__ ( self , filters , depends , output , debug , files , childnodes ) : <EOL> self . childnodes = childnodes <EOL> self . output = output <EOL> self . files = files <EOL> self . depends = depends <EOL> self . filters = filters <EOL> self . debug = debug <EOL> def resolve ( self , context = { } ) : <EOL> """<STR_LIT>""" <EOL> def resolve_var ( x ) : <EOL> if x is None : <EOL> return None <EOL> else : <EOL> try : <EOL> return template . Variable ( x ) . resolve ( context ) <EOL> except template . VariableDoesNotExist : <EOL> raise <EOL> def resolve_depends ( x ) : <EOL> value = resolve_var ( x ) <EOL> if isinstance ( value , six . text_type ) : <EOL> value = value . split ( '<STR_LIT:U+002C>' ) <EOL> return value <EOL> def resolve_bundle ( name ) : <EOL> try : <EOL> return get_env ( ) [ name ] <EOL> except KeyError : <EOL> return name <EOL> return self . BundleClass ( <EOL> * [ resolve_bundle ( resolve_var ( f ) ) for f in self . files ] , <EOL> ** { '<STR_LIT>' : resolve_var ( self . output ) , <EOL> '<STR_LIT>' : resolve_var ( self . filters ) , <EOL> '<STR_LIT>' : resolve_depends ( self . depends ) , <EOL> '<STR_LIT>' : parse_debug_value ( resolve_var ( self . debug ) ) } ) <EOL> def render ( self , context ) : <EOL> bundle = self . resolve ( context ) <EOL> result = u"<STR_LIT>" <EOL> with bundle . bind ( get_env ( ) ) : <EOL> for url in bundle . urls ( ) : <EOL> context . update ( { '<STR_LIT>' : url , '<STR_LIT>' : bundle . extra } ) <EOL> try : <EOL> result += self . childnodes . render ( context ) <EOL> finally : <EOL> context . pop ( ) <EOL> return result <EOL> def assets ( parser , token ) : <EOL> filters = None <EOL> output = None <EOL> debug = None <EOL> depends = None <EOL> files = [ ] <EOL> args = token . split_contents ( ) [ <NUM_LIT:1> : ] <EOL> for arg in args : <EOL> if arg [ - <NUM_LIT:1> ] == '<STR_LIT:U+002C>' : <EOL> arg = arg [ : - <NUM_LIT:1> ] <EOL> if not arg : <EOL> continue <EOL> arg = arg . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> if len ( arg ) == <NUM_LIT:1> : <EOL> name = None <EOL> value = arg [ <NUM_LIT:0> ] <EOL> else : <EOL> name , value = arg <EOL> if name == '<STR_LIT>' : <EOL> output = value <EOL> elif name == '<STR_LIT>' : <EOL> debug = value <EOL> elif name == '<STR_LIT>' : <EOL> filters = value <EOL> elif name == '<STR_LIT>' : <EOL> filters = value <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ImminentDeprecationWarning ) <EOL> elif name == '<STR_LIT>' : <EOL> depends = value <EOL> elif name is None : <EOL> files . append ( value ) <EOL> else : <EOL> raise template . TemplateSyntaxError ( '<STR_LIT>' % name ) <EOL> childnodes = parser . parse ( ( "<STR_LIT>" , ) ) <EOL> parser . delete_first_token ( ) <EOL> return AssetsNode ( filters , depends , output , debug , files , childnodes ) <EOL> try : <EOL> from coffin . template import Library as CoffinLibrary <EOL> except ImportError : <EOL> register = template . Library ( ) <EOL> else : <EOL> register = CoffinLibrary ( ) <EOL> from webassets . ext . jinja2 import AssetsExtension <EOL> from django_assets . env import get_env <EOL> register . tag ( AssetsExtension , environment = { '<STR_LIT>' : get_env ( ) } ) <EOL> register . tag ( '<STR_LIT>' , assets ) </s>
