python类InvalidDocument()的实例源码

test_bulk.py 文件源码 项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_insert_check_keys(self, test_coll):
        bulk = test_coll.initialize_ordered_bulk_op()
        bulk.insert({'$dollar': 1})
        with pytest.raises(InvalidDocument):
            await bulk.execute()

        bulk = test_coll.initialize_ordered_bulk_op()
        bulk.insert({'a.b': 1})
        with pytest.raises(InvalidDocument):
            await bulk.execute()
summary_channel.py 文件源码 项目:SPHERE-HyperStream 作者: IRC-SPHERE 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_stream_writer(self, stream):
        """
        Gets the database channel writer
        The mongoengine model checks whether a stream_id/datetime pair already exists in the DB (unique pairs)
        Should be overridden by users' personal channels - allows for non-mongo outputs.
        :param stream: The stream
        :return: The stream writer function
        """

        def writer(document_collection):
            with switch_db(SummaryInstanceModel, 'hyperstream'):
                if isinstance(document_collection, StreamInstance):
                    document_collection = [document_collection]

                for t, doc in document_collection:
                    instance = SummaryInstanceModel(
                        stream_id=stream.stream_id.as_dict(),
                        datetime=t,
                        value=doc)
                    try:
                        instance.save()
                    except NotUniqueError as e:
                        # Implies that this has already been written to the database
                        # Raise an error if the value differs from that in the database
                        logging.warn("Found duplicate document: {}".format(e.message))
                        existing = SummaryInstanceModel.objects(stream_id=stream.stream_id.as_dict(), datetime=t)[0]
                        if existing.value != doc:
                            raise e
                    except (InvalidDocumentError, InvalidDocument) as e:
                        # Something wrong with the document - log the error
                        logging.error(e)
        return writer
database.py 文件源码 项目:Snakepit 作者: K4lium 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def insertRagpickerDB(self, report):
        # Store the report
        try:
            self.__mongodbCollectionRagpicker.insert(report)
        except InvalidDocument as e:
            log.exception("Error InvalidDocument: %s", report)
            raise Exception("Error InvalidDocument: {0}".format(e)) 
        except InvalidStringData:
            self.__mongodbCollectionRagpicker.insert(convertDirtyDict2ASCII(report))

    #Count Ragpicker-Reports by file (and url)
database_channel.py 文件源码 项目:HyperStream 作者: IRC-SPHERE 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_stream_writer(self, stream):
        """
        Gets the database channel writer
        The mongoengine model checks whether a stream_id/datetime pair already exists in the DB (unique pairs)
        Should be overridden by users' personal channels - allows for non-mongo outputs.

        :param stream: The stream
        :return: The stream writer function
        """

        def writer(document_collection):
            with switch_db(StreamInstanceModel, 'hyperstream'):
                if isinstance(document_collection, StreamInstance):
                    document_collection = [document_collection]

                for t, doc in document_collection:
                    instance = StreamInstanceModel(
                        stream_id=stream.stream_id.as_dict(),
                        datetime=t,
                        value=doc)
                    try:
                        instance.save()
                    except NotUniqueError as e:
                        # Implies that this has already been written to the database
                        # Raise an error if the value differs from that in the database
                        logging.warn("Found duplicate document: {}".format(e.message))
                        existing = StreamInstanceModel.objects(stream_id=stream.stream_id.as_dict(), datetime=t)[0]
                        if existing.value != doc:
                            raise e
                    except (InvalidDocumentError, InvalidDocument) as e:
                        # Something wrong with the document - log the error
                        logging.error(e)
        return writer


问题


面经


文章

微信
公众号

扫码关注公众号