當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。