<s> import copy <EOL> from permission . compat import six <EOL> def autodiscover ( module_name = None ) : <EOL> """<STR_LIT>""" <EOL> from django . utils . module_loading import module_has_submodule <EOL> from permission . compat import import_module <EOL> from permission . conf import settings <EOL> module_name = module_name or settings . PERMISSION_AUTODISCOVER_MODULE_NAME <EOL> for app in settings . INSTALLED_APPS : <EOL> mod = import_module ( app ) <EOL> try : <EOL> discover ( app , module_name = module_name ) <EOL> except : <EOL> if module_has_submodule ( mod , module_name ) : <EOL> raise <EOL> def discover ( app , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> from permission . compat import import_module <EOL> from permission . compat import get_model <EOL> from permission . conf import settings <EOL> from permission . utils . logics import add_permission_logic <EOL> variable_name = settings . PERMISSION_AUTODISCOVER_VARIABLE_NAME <EOL> module_name = module_name or settings . PERMISSION_AUTODISCOVER_MODULE_NAME <EOL> m = import_module ( '<STR_LIT>' % ( app , module_name ) ) <EOL> if hasattr ( m , variable_name ) : <EOL> permission_logic_set = getattr ( m , variable_name ) <EOL> for model , permission_logic in permission_logic_set : <EOL> if isinstance ( model , six . string_types ) : <EOL> model = get_model ( * model . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) ) <EOL> add_permission_logic ( model , permission_logic ) </s>
