
    h                         d Z ddlmZmZ ddlmZmZ ddlmZ	m
Z
 ddlmZ  G d dej                        Zd Z e	j                   e	      Zy
)z+Tools for representing raw BSON documents.
    )_raw_to_dict_get_object_size)abc	iteritems)DEFAULT_CODEC_OPTIONS_RAW_BSON_DOCUMENT_MARKER)SONc                   d    e Zd ZdZdZeZddZed        Z	d Z
ed        Zd Zd	 Zd
 Zd Zd Zy)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_optionsNc                     || _         d| _        |t        }n*|j                  t        urt        d|j                        || _        t        |dt        |             y)a9  Create 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'

        :Parameters:
          - `bson_bytes`: the BSON bytes that compose this document
          - `codec_options` (optional): 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`.
        Nz<RawBSONDocument cannot use CodecOptions with document class r   )	_RawBSONDocument__raw_RawBSONDocument__inflated_docDEFAULT_RAW_BSON_OPTIONSdocument_classr   	TypeError_RawBSONDocument__codec_optionsr   len)self
bson_bytescodec_optionss      P/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/raw_bson.py__init__zRawBSONDocument.__init__$   sd    D  
"  4M))@+::>? ?  -QJ8    c                     | j                   S )z+The raw BSON bytes composing this document.)r   r   s    r   rawzRawBSONDocument.rawT   s     zzr   c                 ,    t        | j                        S )z4Lazily decode and iterate elements in this document.)r   _RawBSONDocument__inflatedr   s    r   itemszRawBSONDocument.itemsY   s    ))r   c                 |    | j                   %t        | j                  | j                        | _         | j                   S N)r   _inflate_bsonr   r   r   s    r   
__inflatedzRawBSONDocument.__inflated]   s8    & #0

D00#2D"""r   c                      | j                   |   S r$   )r!   )r   items     r   __getitem__zRawBSONDocument.__getitem__g   s    t$$r   c                 ,    t        | j                        S r$   )iterr!   r   s    r   __iter__zRawBSONDocument.__iter__j   s    DOO$$r   c                 ,    t        | j                        S r$   )r   r!   r   s    r   __len__zRawBSONDocument.__len__m   s    4??##r   c                 `    t        |t              r| j                  |j                  k(  S t        S r$   )
isinstancer   r   r   NotImplemented)r   others     r   __eq__zRawBSONDocument.__eq__p   s%    e_-::**r   c                 <    d| j                   d| j                  dS )NzRawBSONDocument(z, codec_options=))r   r   r   s    r   __repr__zRawBSONDocument.__repr__u   s    88T113 	4r   r$   )__name__
__module____qualname____doc__	__slots__r   _type_markerr   propertyr   r"   r!   r)   r,   r.   r3   r6    r   r   r   r      s_     ?I,L.9`  * # #%%$
4r   r   c                 H    t        | dt        |       dz
  |t                     S )a%  Inflates the top level fields of a BSON document.

    :Parameters:
      - `bson_bytes`: the BSON bytes that compose this document
      - `codec_options`: An instance of
        :class:`~bson.codec_options.CodecOptions` whose ``document_class``
        must be :class:`RawBSONDocument`.
          )r   r   r	   )r   r   s     r   r%   r%   z   s)     As:q(-@ @r   )r   N)r:   bsonr   r   bson.py3compatr   r   bson.codec_optionsr   DEFAULTr   bson.sonr	   Mappingr   r%   with_optionsr   r>   r   r   <module>rI      sN    0 )A ^4ckk ^4B@ 07//O r   