<s> from django import template <EOL> from django . template . base import FilterExpression <EOL> from . . siteblocksapp import SiteBlocks <EOL> register = template . Library ( ) <EOL> siteblocks = SiteBlocks ( ) <EOL> @ register . tag <EOL> def siteblock ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> tokens = token . split_contents ( ) <EOL> tokens_num = len ( tokens ) <EOL> if tokens_num not in ( <NUM_LIT:2> , <NUM_LIT:4> ) : <EOL> raise template . TemplateSyntaxError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % tokens [ <NUM_LIT:0> ] ) <EOL> block_alias = parser . compile_filter ( tokens [ <NUM_LIT:1> ] ) <EOL> as_var = None <EOL> tokens = tokens [ <NUM_LIT:2> : ] <EOL> if len ( tokens ) >= <NUM_LIT:2> and tokens [ - <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> as_var = tokens [ - <NUM_LIT:1> ] <EOL> return siteblockNode ( block_alias , as_var ) <EOL> class siteblockNode ( template . Node ) : <EOL> def __init__ ( self , block_alias , as_var = None ) : <EOL> self . block_alias = block_alias <EOL> self . as_var = as_var <EOL> def render ( self , context ) : <EOL> block_alias = self . block_alias <EOL> if isinstance ( self . block_alias , FilterExpression ) : <EOL> block_alias = block_alias . resolve ( context ) <EOL> contents = siteblocks . get ( block_alias , context ) <EOL> if self . as_var is not None : <EOL> context [ self . as_var ] = contents <EOL> return '<STR_LIT>' <EOL> return contents </s>
