
    nh                    d    d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ ddlmZ  G d d      Zy	)
z@Tools for manipulating DBRefs (references to MongoDB documents).    )annotations)deepcopy)AnyMappingOptional)_getstate_slots_setstate_slots)SONc                      e Zd ZdZdZeZeZdZ		 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ
edd       Zedd       Zedd       Zdd	Zdd
ZddZddZddZddZddZy)DBRefz,A reference to a document stored in MongoDB.)__collection__id
__database__kwargsd   Nc                   t        |t              st        dt        |             |'t        |t              st        dt        |             || _        || _        || _        |j                  |xs i        || _        y)a  Initialize a new :class:`DBRef`.

        Raises :class:`TypeError` if `collection` or `database` is not
        an instance of :class:`str`. `database` is optional and allows
        references to documents to work across databases. Any additional
        keyword arguments will create additional fields in the resultant
        embedded document.

        :param collection: name of the collection the document is stored in
        :param id: the value of the document's ``"_id"`` field
        :param database: name of the database to reference
        :param kwargs: additional keyword arguments will
            create additional, custom fields

        .. seealso:: The MongoDB documentation on `dbrefs <https://dochub.mongodb.org/core/dbrefs>`_.
        z+collection must be an instance of str, not Nz)database must be an instance of str, not )	
isinstancestr	TypeErrortype_DBRef__collection
_DBRef__id_DBRef__databaseupdate_DBRef__kwargs)self
collectioniddatabase_extrakwargss         p/var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/bson/dbref.py__init__zDBRef.__init__"   s{    0 *c*I$zJZI[\]]
8S(AGXGWXYY&	"fl#    c                    | j                   S )z(Get the name of this DBRef's collection.)r   r   s    r"   r   zDBRef.collectionE   s        r$   c                    | j                   S )zGet this DBRef's _id.)r   r&   s    r"   r   zDBRef.idJ   s     yyr$   c                    | j                   S )zoGet the name of this DBRef's database.

        Returns None if this DBRef doesn't specify a database.
        )r   r&   s    r"   r   zDBRef.databaseO   s     r$   c                T    	 | j                   |   S # t        $ r t        |      d w xY wN)r   KeyErrorAttributeError)r   keys     r"   __getattr__zDBRef.__getattr__W   s2    	0==%% 	0 %4/	0s    'c                    t        d| j                  fd| j                  fg      }| j                  | j                  |d<   |j	                  | j
                         |S )zsGet the SON document representation of this DBRef.

        Generally not needed by application developers
        z$refz$idz$db)r
   r   r   r   r   r   )r   docs     r"   as_doczDBRef.as_doc]   sQ    
 FDOO,udgg.>?@==$CJ

4==!
r$   c           
     @   dj                  | j                  j                         D cg c]  \  }}d| d| c}}      }| j                  d| j                  d| j
                  | dS d| j                  d| j
                  d| j                  | dS c c}}w )N z, =zDBRef())joinr   itemsr   r   r   )r   kvextras       r"   __repr__zDBRef.__repr__h   s    DMM4G4G4IJDAq2aS!JK== DOO.bE7!DD*"TWWKr$--9J5'QRSS Ks   B
c                    t        |t              ra| j                  | j                  | j                  | j
                  f}|j                  |j                  |j                  |j
                  f}||k(  S t        S r*   )r   r   r   r   r   r   NotImplemented)r   otherusthems       r"   __eq__zDBRef.__eq__n   s^    eU#//4#4#4diiOB$$e&8&8%**ennUD:r$   c                    | |k(   S r*    )r   r>   s     r"   __ne__zDBRef.__ne__u   s    5=  r$   c                    t        | j                  | j                  | j                  t	        t        | j                  j                                     f      S )z)Get a hash value for this :class:`DBRef`.)hashr   r   r   tuplesortedr   r7   r&   s    r"   __hash__zDBRef.__hash__x   s@    		4??E&I\I\I^B_<`a
 	
r$   c           	         t        t        | j                  |      t        | j                  |      t        | j                  |      t        | j
                  |            S )z'Support function for `copy.deepcopy()`.)r   r   r   r   r   r   )r   memos     r"   __deepcopy__zDBRef.__deepcopy__~   sI    T&&-TYY%T__d+T]]D)	
 	
r$   )NN)r   r   r   r   r   Optional[str]r    zOptional[Mapping[str, Any]]r!   r   returnNone)rN   r   )rN   r   )rN   rM   )r-   r   rN   r   )rN   zSON[str, Any])r>   r   rN   bool)rN   int)rK   r   rN   r   )__name__
__module____qualname____doc__	__slots__r   __getstate__r	   __setstate___type_markerr#   propertyr   r   r   r.   r1   r;   rA   rD   rI   rL   rC   r$   r"   r   r      s    6@I"L"LL #'.2!! !  	!
 ,! ! 
!F ! !    0	T!

r$   r   N)rU   
__future__r   copyr   typingr   r   r   bson._helpersr   r	   bson.sonr
   r   rC   r$   r"   <module>r`      s)    G "  ) ) : l
 l
r$   