+\hUdZddlmZddlmZmZmZmZmZddl m Z m Z ddl m Z mZddl mZ d ddZGd d eeefZGd d eZej*e Zded<ej*e Zded<y)aTools for representing raw BSON documents. Inserting and Retrieving RawBSONDocuments ========================================= Example: Moving a document between different databases/collections .. doctest:: >>> import bson >>> from pymongo import MongoClient >>> from bson.raw_bson import RawBSONDocument >>> client = MongoClient(document_class=RawBSONDocument) >>> client.drop_database("db") >>> client.drop_database("replica_db") >>> db = client.db >>> result = db.test.insert_many( ... [{"_id": 1, "a": 1}, {"_id": 2, "b": 1}, {"_id": 3, "c": 1}, {"_id": 4, "d": 1}] ... ) >>> replica_db = client.replica_db >>> for doc in db.test.find(): ... print(f"raw document: {doc.raw}") ... print(f"decoded document: {bson.decode(doc.raw)}") ... result = replica_db.test.insert_one(doc) ... raw document: b'...' decoded document: {'_id': 1, 'a': 1} raw document: b'...' decoded document: {'_id': 2, 'b': 1} raw document: b'...' decoded document: {'_id': 3, 'c': 1} raw document: b'...' decoded document: {'_id': 4, 'd': 1} For use cases like moving documents across different databases or writing binary blobs to disk, using raw BSON documents provides better speed and avoids the overhead of decoding or encoding BSON. ) annotations)Any ItemsViewIteratorMappingOptional)_get_object_size _raw_to_dict)_RAW_BSON_DOCUMENT_MARKER CodecOptions)DEFAULT_CODEC_OPTIONSCodecOptions[RawBSONDocument]c<t|dt|dz |i|S)aInflates the top level fields of a BSON document. :param bson_bytes: the BSON bytes that compose this document :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions` whose ``document_class`` must be :class:`RawBSONDocument`.  raw_array)r len) bson_bytes codec_optionsrs P/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/bson/raw_bson.py _inflate_bsonr>s#  As:':M2Yb ccceZdZUdZdZeZded< d ddZe ddZ ddZ e dd Z e dd Zdd Zdd Zdd ZddZddZy)RawBSONDocumentzRepresentation for a MongoDB document that provides access to the raw BSON bytes that compose it. Only when a field is accessed or modified within the document does RawBSONDocument decode its bytes. )__raw__inflated_doc__codec_optionsr_RawBSONDocument__codec_optionsNc||_d|_|t}n2t|jt st d|j||_t|dt|y)aCreate a new :class:`RawBSONDocument` :class:`RawBSONDocument` is a representation of a BSON document that provides access to the underlying raw BSON bytes. Only when a field is accessed or modified within the document does RawBSONDocument decode its bytes. :class:`RawBSONDocument` implements the ``Mapping`` abstract base class from the standard library so it can be used like a read-only ``dict``:: >>> from bson import encode >>> raw_doc = RawBSONDocument(encode({'_id': 'my_doc'})) >>> raw_doc.raw b'...' >>> raw_doc['_id'] 'my_doc' :param bson_bytes: the BSON bytes that compose this document :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions` whose ``document_class`` must be :class:`RawBSONDocument`. The default is :attr:`DEFAULT_RAW_BSON_OPTIONS`. .. versionchanged:: 3.8 :class:`RawBSONDocument` now validates that the ``bson_bytes`` passed in represent a single bson document. .. versionchanged:: 3.5 If a :class:`~bson.codec_options.CodecOptions` is passed in, its `document_class` must be :class:`RawBSONDocument`. Nzrcs%L#>>/F?X] d d&C dPT d ddbgc3h'dbNHOH;O':N:N";7@Tw?S?S(@<r