<s> import os <EOL> from jinja2 import nodes <EOL> from jinja2 . ext import Extension <EOL> from jac . base import Compressor <EOL> from jac . compat import u <EOL> class CompressorExtension ( Extension ) : <EOL> tags = set ( [ '<STR_LIT>' ] ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CompressorExtension , self ) . __init__ ( * args , ** kwargs ) <EOL> self . compressor = Compressor ( environment = self . environment ) <EOL> def parse ( self , parser ) : <EOL> configs = self . compressor . get_configs_from_environment ( self . environment ) <EOL> self . compressor . config . update ( ** configs ) <EOL> lineno = next ( parser . stream ) . lineno <EOL> args = [ parser . parse_expression ( ) ] <EOL> body = parser . parse_statements ( [ '<STR_LIT>' ] , drop_needle = True ) <EOL> if len ( body ) > <NUM_LIT:1> : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> if hasattr ( self . environment , '<STR_LIT>' ) and self . environment . compressor_offline_compress : <EOL> return nodes . CallBlock ( self . call_method ( '<STR_LIT>' , args ) , [ ] , [ ] , body ) . set_lineno ( lineno ) <EOL> else : <EOL> return nodes . CallBlock ( self . call_method ( '<STR_LIT>' , args ) , [ ] , [ ] , body ) . set_lineno ( lineno ) <EOL> def _compress_block ( self , compression_type , caller ) : <EOL> html = caller ( ) <EOL> return self . compressor . compress ( html , compression_type ) <EOL> def _display_block ( self , compression_type , caller ) : <EOL> html = caller ( ) <EOL> html_hash = self . compressor . make_hash ( html ) <EOL> filename = os . path . join ( u ( '<STR_LIT>' ) . format ( <EOL> hash = html_hash , <EOL> extension = compression_type , <EOL> ) ) <EOL> static_prefix = u ( self . compressor . config . compressor_static_prefix ) <EOL> return self . compressor . render_element ( os . path . join ( static_prefix , filename ) , compression_type ) <EOL> def set ( self , key , val ) : <EOL> self . compressor . config . set ( key , val ) </s>
