<s> """<STR_LIT>""" <EOL> import json <EOL> import logging <EOL> from tornado import escape <EOL> from tornado import httpclient <EOL> from tornado import template <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> class CouchDBLoader ( template . BaseLoader ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , base_url , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( CouchDBLoader , self ) . __init__ ( '<STR_LIT:/>' , ** kwargs ) <EOL> self . _base_url = base_url . rstrip ( '<STR_LIT:/>' ) <EOL> LOGGER . info ( '<STR_LIT>' , self . _base_url ) <EOL> self . _http_client = httpclient . HTTPClient ( ) <EOL> def load ( self , name , parent_path = None ) : <EOL> """<STR_LIT>""" <EOL> if name not in self . templates : <EOL> self . templates [ name ] = self . _create_template ( name ) <EOL> return self . templates [ name ] <EOL> def _create_template ( self , name ) : <EOL> """<STR_LIT>""" <EOL> url = '<STR_LIT>' % ( self . _base_url , escape . url_escape ( name ) ) <EOL> LOGGER . debug ( '<STR_LIT>' , url ) <EOL> response = self . _http_client . fetch ( url ) <EOL> data = json . loads ( response . body , ensure_ascii = False ) <EOL> return template . Template ( data [ '<STR_LIT>' ] , name = name , loader = self ) </s>
