diff options
author | ankitjavalkar | 2015-04-30 11:21:49 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-04-30 11:29:35 +0530 |
commit | d8847656ba79e51c96c6e3650374aaf616c375dc (patch) | |
tree | 9e4ca3c29bc082cdd7b6775208544c2da9cee374 /testapp/exam/language_registry.py | |
parent | 18df6d88a2e1a9dfe7d05ca97b2d69ff0569e088 (diff) | |
download | online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.gz online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.bz2 online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.zip |
Code Review: Code Refactoring
Diffstat (limited to 'testapp/exam/language_registry.py')
-rw-r--r-- | testapp/exam/language_registry.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/testapp/exam/language_registry.py b/testapp/exam/language_registry.py index 4d56de2..8700d32 100644 --- a/testapp/exam/language_registry.py +++ b/testapp/exam/language_registry.py @@ -1,17 +1,31 @@ -#!/usr/bin/env python +from settings import language_register +registry = None -class LanguageRegistry(object): +def set_registry(): + globals registry = _LanguageRegistry() + +def get_registry(): + return registry + +class _LanguageRegistry(object): def __init__(self): - self._registry = {} + for language, module in language_register.iteritems(): + self._register[language] = None # Public Protocol ########## def get_class(self, language): - return self._registry[language] + if not self._register[language]: + self._register[language] = language_register[language] - # Public Protocol ########## - def register(self, language, cls): - self._registry[language] = cls + cls = self._register[language] + module_name, class_name = cls.split(".") + # load the module, will raise ImportError if module cannot be loaded + get_module = importlib.import_module(module_name) + # get the class, will raise AttributeError if class cannot be found + get_class = getattr(get_module, class_name) + return get_class + # def register(self, language, cls): + # self._register[language] = cls -registry = LanguageRegistry() |