<s> import os <EOL> import json <EOL> import sys <EOL> import codecs <EOL> from . _base import BaseFinder , BaseLoader , InvalidJsonError <EOL> class JsonFinder ( BaseFinder ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . ext_name = "<STR_LIT>" <EOL> super ( JsonFinder , self ) . __init__ ( * args , ** kwargs ) <EOL> def find_module ( self , fullname , path = None ) : <EOL> cfg_file = self . get_cfg_filepath ( fullname ) <EOL> if os . path . isfile ( cfg_file + self . ext_name ) : <EOL> return JsonLoader ( cfg_file + self . ext_name ) <EOL> else : <EOL> return None <EOL> class JsonLoader ( BaseLoader ) : <EOL> def __init__ ( self , cfg_file , * args , ** kwargs ) : <EOL> self . e = None <EOL> self . err_msg = None <EOL> self . cfg_file = cfg_file <EOL> super ( JsonLoader , self ) . __init__ ( * args , ** kwargs ) <EOL> def load_module ( self , fullname ) : <EOL> """<STR_LIT>""" <EOL> mod = super ( JsonLoader , self ) . load_module ( fullname ) <EOL> try : <EOL> with codecs . open ( self . cfg_file , '<STR_LIT:r>' , '<STR_LIT:utf-8>' ) as f : <EOL> mod . __dict__ . update ( json . load ( f ) ) <EOL> except ValueError : <EOL> self . e = "<STR_LIT>" <EOL> self . err_msg = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if self . e == "<STR_LIT>" : <EOL> err_msg = "<STR_LIT>" <EOL> err_msg += self . cfg_file + '<STR_LIT:\n>' <EOL> err_msg += str ( self . err_msg ) <EOL> raise InvalidJsonError ( err_msg ) <EOL> return mod </s>
