Beispiel #1
0
 def _validate_descriptors(cls, attrs):
     SchemaProperties._validate_descriptors(attrs)
     # validate index descriptor
     if attrs.get('migration_handler') and attrs.get('use_schemaless'):
         raise OptionConflictError('You cannot set a migration_handler with use_schemaless set to True')
     if attrs.get('indexes'):
         for index in attrs['indexes']:
             if index.get('check', True):
                 if 'fields' not in index:
                     raise BadIndexError(
                       "'fields' key must be specify in indexes")
                 for key, value in index.iteritems():
                     if key not in ['fields', 'ttl', 'check', 'unique', 'sparse', 'dropDupes',
                                    'drop_dupes','bucketSize', 'bucket_size', 'min', 'max']:
                         raise BadIndexError(
                           "%s is unknown key for indexes" % key)
                     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 structure" % value )
                         elif isinstance(value, tuple):
                             if len(value) != 2:
                                 raise BadIndexError(
                                   "Error in indexes: a tuple must contain "
                                   "only two value : the field name and the direction")
                             if not (isinstance(value[1], int) or isinstance(value[1], basestring)):
                                 raise BadIndexError(
                                   "Error in %s, the direction must be int or basestring (got %s instead)" % (value[0], type(value[1])))
                             if not isinstance(value[0], basestring):
                                 raise BadIndexError(
                                   "Error in %s, the field name must be string (got %s instead)" % (value[0], type(value[0])))
                             if value[0] not in attrs['_namespaces'] and value[0] not in STRUCTURE_KEYWORDS:
                                 raise ValueError(
                                   "Error in indexes: can't find %s in structure" % value[0] )
                             if not value[1] 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" % value[1])
                         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 structure" % 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:
                                     if val not in attrs['_namespaces'] and val not in STRUCTURE_KEYWORDS:
                                         raise ValueError(
                                           "Error in indexes: can't find %s in structure" % val )
                         else:
                             raise BadIndexError(
                               "fields must be a string, a tuple or a list of tuple (got %s instead)" % type(value))
                     elif key in ['ttl', 'bucketSize', 'bucket_size', 'min', 'max']:
                         assert isinstance(value, int)
                     else:
                         assert value in [False, True], value
Beispiel #2
0
 def _validate_descriptors(cls, attrs):
     SchemaProperties._validate_descriptors(attrs)
     # validate index descriptor
     if attrs.get('migration_handler') and attrs.get('use_schemaless'):
         raise OptionConflictError('You cannot set a migration_handler with use_schemaless set to True')
     if attrs.get('indexes'):
         for index in attrs['indexes']:
             if index.get('check', True):
                 if 'fields' not in index:
                     raise BadIndexError(
                       "'fields' key must be specify in indexes")
                 for key, value in index.iteritems():
                     if key not in ['fields', 'unique', 'ttl', 'check']:
                         raise BadIndexError(
                           "%s is unknown key for indexes" % key)
                     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 structure" % value )
                         elif isinstance(value, tuple):
                             if len(value) != 2:
                                 raise BadIndexError(
                                   "Error in indexes: a tuple must contain "
                                   "only two value : the field name and the direction")
                             if not (isinstance(value[1], int) or isinstance(value[1], basestring)):
                                 raise BadIndexError(
                                   "Error in %s, the direction must be int or basestring (got %s instead)" % (value[0], type(value[1])))
                             if not isinstance(value[0], basestring):
                                 raise BadIndexError(
                                   "Error in %s, the field name must be string (got %s instead)" % (value[0], type(value[0])))
                             if value[0] not in attrs['_namespaces'] and value[0] not in STRUCTURE_KEYWORDS:
                                 raise ValueError(
                                   "Error in indexes: can't find %s in structure" % value[0] )
                             if not value[1] 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" % value[1])
                         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 structure" % 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:
                                     if val not in attrs['_namespaces'] and val not in STRUCTURE_KEYWORDS:
                                         raise ValueError(
                                           "Error in indexes: can't find %s in structure" % val )
                         else:
                             raise BadIndexError(
                               "fields must be a string, a tuple or a list of tuple (got %s instead)" % type(value))
                     elif key == "ttl":
                         assert isinstance(value, int)
                     else:
                         assert value in [False, True], value
Beispiel #3
0
 def _validate_descriptors(cls, attrs):
     SchemaProperties._validate_descriptors(attrs)
     # validate index descriptor
     if attrs.get('migration_handler') and attrs.get('use_schemaless'):
         raise OptionConflictError('You cannot set a migration_handler with use_schemaless set to True')
     if attrs.get('indexes'):
         for index in attrs['indexes']:
             if index.get('check', True):
                 if 'fields' not in index:
                     raise BadIndexError(
                       "'fields' key must be specify in indexes")
                 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 structure" % value )
                         elif isinstance(value, tuple):
                             if len(value) != 2:
                                 raise BadIndexError(
                                   "Error in indexes: a tuple must contain "
                                   "only two value : the field name and the direction")
                             if not (isinstance(value[1], int) or isinstance(value[1], basestring)):
                                 raise BadIndexError(
                                   "Error in %s, the direction must be int or basestring (got %s instead)" % (value[0], type(value[1])))
                             if not isinstance(value[0], basestring):
                                 raise BadIndexError(
                                   "Error in %s, the field name must be string (got %s instead)" % (value[0], type(value[0])))
                             if value[0] not in attrs['_namespaces'] and value[0] not in STRUCTURE_KEYWORDS:
                                 raise ValueError(
                                   "Error in indexes: can't find %s in structure" % value[0] )
                             if not value[1] in [pymongo.DESCENDING, pymongo.ASCENDING, pymongo.OFF, pymongo.ALL, pymongo.GEO2D, pymongo.GEOHAYSTACK, pymongo.GEOSPHERE, "text"]:
                                 raise BadIndexError(
                                   "index direction must be INDEX_DESCENDING, INDEX_ASCENDING, INDEX_OFF, INDEX_ALL, INDEX_GEO2D, INDEX_GEOHAYSTACK, or INDEX_GEOSPHERE. Got %s" % value[1])  # Omit text because it's still beta
                         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 structure" % field )
                                     if not direction in [pymongo.DESCENDING, pymongo.ASCENDING, pymongo.OFF, pymongo.ALL, pymongo.GEO2D, pymongo.GEOHAYSTACK, pymongo.GEOSPHERE, "text"]:
                                         raise BadIndexError(
                                           "index direction must be INDEX_DESCENDING, INDEX_ASCENDING, INDEX_OFF, INDEX_ALL, INDEX_GEO2D, INDEX_GEOHAYSTACK, or INDEX_GEOSPHERE. Got %s" % direction)  # Omit text because it's still beta
                                 else:
                                     if val not in attrs['_namespaces'] and val not in STRUCTURE_KEYWORDS:
                                         raise ValueError(
                                           "Error in indexes: can't find %s in structure" % val )
                         else:
                             raise BadIndexError(
                               "fields must be a string, a tuple or a list of tuple (got %s instead)" % type(value))
                     elif key == "ttl":
                         assert isinstance(value, int)
Beispiel #4
0
 def __new__(cls, name, bases, attrs):
     for base in bases:
         parent = base.__mro__[0]
         if hasattr(parent, 'structure'):
             if parent.structure is not None:
                 #parent = parent()
                 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)        
Beispiel #5
0
 def __new__(cls, name, bases, attrs):
     for base in bases:
         parent = base.__mro__[0]
         if hasattr(parent, 'structure'):
             if parent.structure is not None:
                 #parent = parent()
                 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)        
Beispiel #6
0
 def __new__(cls, name, bases, attrs):
     for base in bases:
         parent = base.__mro__[0]
         if hasattr(parent, 'structure'):
             if parent.structure is not None:
                 #parent = parent()
                 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)
     if '__database__' in attrs and not '__collection__' in attrs:
         raise AttributeError("%s: __collection__ attribute not found. "
           "You cannot specify the `__database__` attribute without "
           "the `__collection__` attribute" % name)
     return SchemaProperties.__new__(cls, name, bases, attrs)        
Beispiel #7
0
 def _validate_descriptors(cls, attrs):
     SchemaProperties._validate_descriptors(attrs)
     # validate index descriptor
     if attrs.get("indexes"):
         for index in attrs["indexes"]:
             if index.get("check", True):
                 if "fields" not in index:
                     raise BadIndexError("'fields' key must be specify in indexes")
                 for key, value in index.iteritems():
                     if key not in ["fields", "unique", "ttl", "check"]:
                         raise BadIndexError("%s is unknown key for indexes" % key)
                     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 structure" % value)
                         elif isinstance(value, tuple):
                             if len(value) != 2:
                                 raise BadIndexError(
                                     "Error in indexes: a tuple must contain "
                                     "only two value : the field name and the direction"
                                 )
                             if not (isinstance(value[1], int) or isinstance(value[1], basestring)):
                                 raise BadIndexError(
                                     "Error in %s, the direction must be int or basestring (got %s instead)"
                                     % (value[0], type(value[1]))
                                 )
                             if not isinstance(value[0], basestring):
                                 raise BadIndexError(
                                     "Error in %s, the field name must be string (got %s instead)"
                                     % (value[0], type(value[0]))
                                 )
                             if value[0] not in attrs["_namespaces"] and value[0] not in STRUCTURE_KEYWORDS:
                                 raise ValueError("Error in indexes: can't find %s in structure" % value[0])
                             if not value[1] 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"
                                     % value[1]
                                 )
                         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 structure" % 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:
                                     if val not in attrs["_namespaces"] and val not in STRUCTURE_KEYWORDS:
                                         raise ValueError("Error in indexes: can't find %s in structure" % val)
                         else:
                             raise BadIndexError(
                                 "fields must be a string, a tuple or a list of tuple (got %s instead)" % type(value)
                             )
                     elif key == "ttl":
                         assert isinstance(value, int)
                     else:
                         assert value in [False, True], value