def _validate_descriptors(cls, attrs): SchemaProperties._validate_descriptors(attrs) if attrs.get('indexes'): for index in attrs['indexes']: if 'fields' not in index: raise BadIndexError( "`fields` key must be specify in indexes") if not index.get('check', True): continue for key, value in index.iteritems(): if key == "fields": if isinstance(value, basestring): if value not in attrs['_namespaces'] and value not in STRUCTURE_KEYWORDS: raise ValueError( "Error in indexes: can't find %s in skeleton or optional" % value ) elif isinstance(value, list): for val in value: if isinstance(val, tuple): field, direction = val if field not in attrs['_namespaces'] and field not in STRUCTURE_KEYWORDS: raise ValueError( "Error in indexes: can't find %s in skeleton or optional" % field ) if not direction in [pymongo.DESCENDING, pymongo.ASCENDING, pymongo.OFF, pymongo.ALL, pymongo.GEO2D]: raise BadIndexError( "index direction must be INDEX_DESCENDING, INDEX_ASCENDING, INDEX_OFF, INDEX_ALL or INDEX_GEO2D. Got %s" % direction) else: raise BadIndexError( "fields must be a string or a list of tuples (got %s instead)" % type(value)) else: raise BadIndexError( "fields must be a string or a list of tuples (got %s instead)" % type(value))
def __new__(cls, name, bases, attrs): for base in bases: parent = base.__mro__[0] if getattr(parent, 'skeleton', None) or getattr(parent, 'optional', None): if parent.indexes: if 'indexes' not in attrs: attrs['indexes'] = [] for index in attrs['indexes']+parent.indexes: if index not in attrs['indexes']: attrs['indexes'].append(index) return SchemaProperties.__new__(cls, name, bases, attrs)