@classmethod
    def _validate_structure(cls, structure, name, authorized_types):
        """
        validate if all fields in self.structure are in authorized types.
        """
        ##############
        def __validate_structure(struct, name, _authorized):
            if type(struct) is type:
                if struct not in authorized_types:
                    if struct not in authorized_types:
                        raise StructureError("%s: %s is not an authorized type" % (name, struct))
            elif isinstance(struct, dict):
                for key in struct:
                    if isinstance(key, basestring):
                        if "." in key:
                            raise BadKeyError("%s: %s must not contain '.'" % (name, key))
                        if key.startswith('$'):
                            raise BadKeyError("%s: %s must not start with '$'" % (name, key))
                    elif type(key) is type:
                        if not key in authorized_types:
                            raise AuthorizedTypeError("%s: %s is not an authorized type" % (name, key))
                    else:
                        raise StructureError("%s: %s must be a basestring or a type" % (name, key))
                    if struct[key] is None:
                        pass
                    elif isinstance(struct[key], dict):
                        __validate_structure(struct[key], name, authorized_types)
                    elif isinstance(struct[key], list):
                        __validate_structure(struct[key], name, authorized_types)
                    elif isinstance(struct[key], tuple):
                        __validate_structure(struct[key], name, authorized_types)
                    elif isinstance(struct[key], CustomType):
                        __validate_structure(struct[key].mongo_type, name, authorized_types)
                    elif isinstance(struct[key], SchemaProperties):
                        pass
                    elif isinstance(struct[key], SchemaOperator):
                        __validate_structure(struct[key], name, authorized_types)
                    elif hasattr(struct[key], 'structure'):
                        __validate_structure(struct[key], name, authorized_types)
                    elif struct[key] not in authorized_types:
                        ok = False
                        for auth_type in authorized_types:
                            if struct[key] is None:
                                ok = True
                            else:
                                try:
                                    if isinstance(struct[key], auth_type) or issubclass(struct[key], auth_type):
                                        ok = True
                                except __HOLE__:
                                    raise TypeError("%s: %s is not a type" % (name, struct[key]))
                        if not ok:
                            raise StructureError(
                                "%s: %s is not an authorized type" % (name, struct[key]))
            elif isinstance(struct, list) or isinstance(struct, tuple):
                for item in struct:
                    __validate_structure(item, name, authorized_types)
            elif isinstance(struct, SchemaOperator):
                if isinstance(struct, IS):
                    for operand in struct:
                        if type(operand) not in authorized_types:
                            raise StructureError("%s: %s in %s is not an authorized type (%s found)" % (
                                name, operand, struct, type(operand).__name__))
                else:
                    for operand in struct:
                        if operand not in authorized_types:
                            raise StructureError("%s: %s in %s is not an authorized type (%s found)" % (
                                name, operand, struct, type(operand).__name__))
            elif isinstance(struct, SchemaProperties):
                pass
            else:
                ok = False
                for auth_type in authorized_types:
                    if isinstance(struct, auth_type):
                        ok = True
                if not ok:
                    raise StructureError("%s: %s is not an authorized_types" % (name, struct))
        #################
        if structure is None:
            raise StructureError("%s.structure must not be None" % name)
        if not isinstance(structure, dict):
            raise StructureError("%s.structure must be a dict instance" % name)
        __validate_structure(structure, name, authorized_types)
dataset/ETHPy150Open namlook/mongokit/mongokit/schema_document.py/SchemaDocument._validate_structure