当前位置: 首页>>代码示例>>Python>>正文


Python errors.InvalidOperation方法代码示例

本文整理汇总了Python中pymongo.errors.InvalidOperation方法的典型用法代码示例。如果您正苦于以下问题:Python errors.InvalidOperation方法的具体用法?Python errors.InvalidOperation怎么用?Python errors.InvalidOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.errors的用法示例。


在下文中一共展示了errors.InvalidOperation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: acknowledged

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def acknowledged(self):
        """Is this the result of an acknowledged write operation?

        The :attr:`acknowledged` attribute will be ``False`` when using
        ``WriteConcern(w=0)``, otherwise ``True``.

        .. note::
          If the :attr:`acknowledged` attribute is ``False`` all other
          attibutes of this class will raise
          :class:`~pymongo.errors.InvalidOperation` when accessed. Values for
          other attributes cannot be determined if the write operation was
          unacknowledged.

        .. seealso::
          :class:`~pymongo.write_concern.WriteConcern`
        """
        return self.__acknowledged 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:results.py

示例2: insert

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size) 
开发者ID:leancloud,项目名称:satori,代码行数:23,代码来源:message.py

示例3: test_cursor_first

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def test_cursor_first(collection):
    collection.insert_many([{"bar": "baz"},
                            {"bar": "qux"}])

    cursor = Cursor(collection)

    result = cursor.first()
    assert isinstance(result, dict)
    assert result["bar"] == "baz"

    with pytest.raises(InvalidOperation):
        cursor.first()

    class Foo(Thingy):
        _collection = collection

    cursor = Cursor(collection, thingy_cls=Foo)

    result = cursor.first()
    assert isinstance(result, Foo)
    assert result.bar == "baz"

    with pytest.raises(InvalidOperation):
        cursor.first() 
开发者ID:numberly,项目名称:mongo-thingy,代码行数:26,代码来源:cursor.py

示例4: insert

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, uuid_subtype):
    """Get an **insert** message.

    .. note:: As of PyMongo 2.6, this function is no longer used. It
       is being kept (with tests) for backwards compatibility with 3rd
       party libraries that may currently be using it, but will likely
       be removed in a future release.

    """
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, uuid_subtype) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(list(map(len, encoded)))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:message.py

示例5: _raise_if_unacknowledged

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def _raise_if_unacknowledged(self, property_name):
        """Raise an exception on property access if unacknowledged."""
        if not self.__acknowledged:
            raise InvalidOperation("A value for %s is not available when "
                                   "the write is unacknowledged. Check the "
                                   "acknowledged attribute to avoid this "
                                   "error." % (property_name,)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:results.py

示例6: __init__

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import InvalidOperation [as 别名]
def __init__(self, bulk_api_result, acknowledged):
        """Create a BulkWriteResult instance.

        :Parameters:
          - `bulk_api_result`: A result dict from the bulk API
          - `acknowledged`: Was this write result acknowledged? If ``False``
            then all properties of this object will raise
            :exc:`~pymongo.errors.InvalidOperation`.
        """
        self.__bulk_api_result = bulk_api_result
        super(BulkWriteResult, self).__init__(acknowledged) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:results.py


注:本文中的pymongo.errors.InvalidOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。