<s> """<STR_LIT>""" <EOL> import copy <EOL> import inspect <EOL> import os <EOL> import pkgutil <EOL> import feconf <EOL> import utils <EOL> class BaseValueGenerator ( object ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def id ( self ) : <EOL> return self . __class__ . __name__ <EOL> @ classmethod <EOL> def get_html_template ( cls ) : <EOL> return utils . get_file_contents ( os . path . join ( <EOL> os . getcwd ( ) , feconf . VALUE_GENERATORS_DIR , '<STR_LIT>' , <EOL> '<STR_LIT>' % cls . __name__ ) ) <EOL> @ classmethod <EOL> def get_js_template ( cls ) : <EOL> return utils . get_file_contents ( os . path . join ( <EOL> os . getcwd ( ) , feconf . VALUE_GENERATORS_DIR , '<STR_LIT>' , <EOL> '<STR_LIT>' % cls . __name__ ) ) <EOL> def generate_value ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Registry ( object ) : <EOL> """<STR_LIT>""" <EOL> value_generators_dict = { } <EOL> @ classmethod <EOL> def _refresh_registry ( cls ) : <EOL> cls . value_generators_dict . clear ( ) <EOL> value_generator_paths = [ os . path . join ( <EOL> os . getcwd ( ) , feconf . VALUE_GENERATORS_DIR , '<STR_LIT>' ) ] <EOL> for loader , name , _ in pkgutil . iter_modules ( <EOL> path = value_generator_paths ) : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> continue <EOL> module = loader . find_module ( name ) . load_module ( name ) <EOL> for name , clazz in inspect . getmembers ( module , inspect . isclass ) : <EOL> if issubclass ( clazz , BaseValueGenerator ) : <EOL> if clazz . __name__ in cls . value_generators_dict : <EOL> raise Exception ( <EOL> '<STR_LIT>' <EOL> % clazz . __name__ ) <EOL> cls . value_generators_dict [ clazz . __name__ ] = clazz <EOL> @ classmethod <EOL> def get_all_generator_classes ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . _refresh_registry ( ) <EOL> return copy . deepcopy ( cls . value_generators_dict ) <EOL> @ classmethod <EOL> def get_generator_class_by_id ( cls , generator_id ) : <EOL> """<STR_LIT>""" <EOL> if generator_id not in cls . value_generators_dict : <EOL> cls . _refresh_registry ( ) <EOL> return cls . value_generators_dict [ generator_id ] </s>
