o
    h                     @   s>   d Z ddlT ddlmZ ddgZdddZdd Zd	d
 ZdS )a  
BSON serialization and deserialization logic.
Specifications taken from: http://bsonspec.org/#/specification
The following types are unsupported, because for data exchange purposes, they're
over-engineered:
    0x06 (Undefined)
    0x0b (Regex - Exactly which flavor do you want? Better let higher level
        programmers make that decision.)
    0x0c (DBPointer)
    0x0d (JavaScript code)
    0x0e (Symbol)
    0x0f (JS w/ scope)
    0x11 (MongoDB-specific timestamp)

For binaries, only the default 0x0 type is supported.
   )*)ObjectIdloadsdumpsNc                 C   s*   t | trt| g ||dS t| g ||dS )z
    Given a dict, outputs a BSON string.

    generator is an optional function which accepts the dictionary/array being
    encoded, the current DFS traversal stack, and outputs an iterator indicating
    the correct encoding order for keys.
    )Zgenerator_func
on_unknown)
isinstanceZ
BSONCodingZencode_objectZencode_document)obj	generatorr    r
   @/var/www/html/venv/lib/python3.10/site-packages/bson/__init__.pyr      s   
c                 C   s   t | dd S )z2
        Given a BSON string, outputs a dict.
        r   )Zdecode_document)datar
   r
   r   r   +   s   c                  C   s6   ddl m }  ddlm}m}m} || _|| _|| _dS )a	  
        Patches the Python socket class such that sockets can send and receive BSON
        objects atomically.

        This adds the following functions to socket:

        recvbytes(bytes_needed, sock_buf = None) - reads bytes_needed bytes
        atomically. Returns None if socket closed.

        recvobj() - reads a BSON document from the socket atomically and returns
        the deserialized dictionary. Returns None if socket closed.

        sendobj(obj) - sends a BSON document to the socket atomically.
    r   )socketr   )	recvbytesrecvobjsendobjN)r   networkr   r   r   )r   r   r   r   r
   r
   r   patch_socket2   s
   
r   )NN)__doc__codecZobjectidr   __all__r   r   r   r
   r
   r
   r   <module>   s   
