<s> from jinja2 import nodes , TemplateAssertionError , Markup as mark_safe <EOL> from jinja2 . ext import Extension <EOL> from mediagenerator . generators . bundles . utils import _render_include_media <EOL> class MediaExtension ( Extension ) : <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def __init__ ( self , environment ) : <EOL> self . environment = environment <EOL> def parse ( self , parser ) : <EOL> token = parser . stream . next ( ) <EOL> args = [ parser . parse_expression ( ) ] <EOL> kwargs = [ ] <EOL> while parser . stream . current . type != '<STR_LIT>' : <EOL> if kwargs : <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> if parser . stream . skip_if ( '<STR_LIT>' ) : <EOL> break <EOL> name = parser . stream . expect ( '<STR_LIT:name>' ) <EOL> if name . value in kwargs : <EOL> parser . fail ( '<STR_LIT>' % <EOL> name . value , name . lineno , <EOL> exc = TemplateAssertionError ) <EOL> parser . stream . expect ( '<STR_LIT>' ) <EOL> key = name . value <EOL> value = parser . parse_expression ( ) <EOL> kwargs . append ( nodes . Keyword ( key , value , <EOL> lineno = value . lineno ) ) <EOL> return nodes . Output ( [ self . call_method ( '<STR_LIT>' , args , kwargs ) ] ) . set_lineno ( token . lineno ) <EOL> def _render ( self , bundle , ** variation ) : <EOL> return mark_safe ( _render_include_media ( bundle , variation ) ) </s>
