<s> """<STR_LIT>""" <EOL> import json <EOL> import os <EOL> import jinja2 <EOL> from shpkpr import exceptions <EOL> from shpkpr import template_filters <EOL> class InvalidJSONError ( exceptions . ShpkprException ) : <EOL> """<STR_LIT>""" <EOL> exit_code = <NUM_LIT:2> <EOL> def format_message ( self ) : <EOL> return '<STR_LIT>' <EOL> class UndefinedError ( exceptions . ShpkprException ) : <EOL> """<STR_LIT>""" <EOL> exit_code = <NUM_LIT:2> <EOL> def format_message ( self ) : <EOL> return '<STR_LIT>' % self . message <EOL> class MissingTemplateError ( exceptions . ShpkprException ) : <EOL> """<STR_LIT>""" <EOL> exit_code = <NUM_LIT:2> <EOL> def format_message ( self ) : <EOL> return '<STR_LIT>' % self . message <EOL> def load_values_from_environment ( prefix = "<STR_LIT>" , overrides = None ) : <EOL> """<STR_LIT>""" <EOL> values = { } <EOL> prefix = prefix + "<STR_LIT:_>" if prefix and not prefix . endswith ( "<STR_LIT:_>" ) else prefix <EOL> for k , v in os . environ . items ( ) : <EOL> if k . startswith ( prefix ) : <EOL> values [ k . replace ( prefix , "<STR_LIT>" , <NUM_LIT:1> ) ] = v <EOL> try : <EOL> for k , v in overrides . items ( ) : <EOL> values [ k ] = v <EOL> except AttributeError : <EOL> pass <EOL> return values <EOL> @ exceptions . rewrap ( ValueError , InvalidJSONError ) <EOL> @ exceptions . rewrap ( jinja2 . UndefinedError , UndefinedError ) <EOL> @ exceptions . rewrap ( jinja2 . TemplateNotFound , MissingTemplateError ) <EOL> def render_json_template ( template_path , template_name , ** values ) : <EOL> """<STR_LIT>""" <EOL> template_env = jinja2 . Environment ( <EOL> undefined = jinja2 . StrictUndefined , <EOL> loader = jinja2 . FileSystemLoader ( template_path ) , <EOL> ) <EOL> template_env . filters [ '<STR_LIT>' ] = template_filters . filter_items <EOL> template_env . filters [ '<STR_LIT>' ] = template_filters . require_int <EOL> template_env . filters [ '<STR_LIT>' ] = template_filters . require_float <EOL> template = template_env . get_template ( template_name ) <EOL> rendered_template = template . render ( _all_env = values , ** values ) <EOL> return json . loads ( rendered_template ) </s>
