<s> from . lookups import LookupDoesNotExist , ExtraFieldLookup <EOL> from . import lookups as lookups_module <EOL> from . resolver import resolver <EOL> import inspect <EOL> def create_lookup ( lookup_def ) : <EOL> for _ , cls in inspect . getmembers ( lookups_module ) : <EOL> if inspect . isclass ( cls ) and issubclass ( cls , ExtraFieldLookup ) and cls . matches_lookup_def ( lookup_def ) : <EOL> return cls ( ) <EOL> raise LookupDoesNotExist ( '<STR_LIT>' % lookup_def ) <EOL> def register_index ( model , mapping ) : <EOL> for field_name , lookups in mapping . items ( ) : <EOL> if not isinstance ( lookups , ( list , tuple ) ) : <EOL> lookups = ( lookups , ) <EOL> for lookup in lookups : <EOL> lookup_def = None <EOL> if not isinstance ( lookup , ExtraFieldLookup ) : <EOL> lookup_def = lookup <EOL> lookup = create_lookup ( lookup_def ) <EOL> lookup . contribute ( model , field_name , lookup_def ) <EOL> resolver . create_index ( lookup ) </s>
