o
    h                     @  s^   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 dZd	S )
z@Tools for manipulating DBRefs (references to MongoDB documents).    )annotations)deepcopy)AnyMappingOptional)_getstate_slots_setstate_slots)SONc                   @  s   e Zd ZdZdZeZeZdZ			d,d-ddZ
ed.ddZed/ddZed0ddZd1ddZd2ddZd.ddZd3d"d#Zd3d$d%Zd4d'd(Zd5d*d+ZdS )6DBRefz,A reference to a document stored in MongoDB.)Z__collectionZ__idZ
__databaseZ__kwargsd   N
collectionstridr   databaseOptional[str]_extraOptional[Mapping[str, Any]]kwargsreturnNonec                 K  sj   t |tstdt| |dur t |ts tdt| || _|| _|| _||p.i  || _dS )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 )	
isinstancer   	TypeErrortype_DBRef__collection
_DBRef__id_DBRef__databaseupdate_DBRef__kwargs)selfr   r   r   r   r    r   =/var/www/html/venv/lib/python3.10/site-packages/bson/dbref.py__init__"   s   

zDBRef.__init__c                 C     | j S )z(Get the name of this DBRef's collection.)r   r   r   r   r    r   E      zDBRef.collectionc                 C  r"   )zGet this DBRef's _id.)r   r#   r   r   r    r   J   r$   zDBRef.idc                 C  r"   )zoGet the name of this DBRef's database.

        Returns None if this DBRef doesn't specify a database.
        )r   r#   r   r   r    r   O   s   zDBRef.databasekeyc                 C  s&   z| j | W S  ty   t|d w N)r   KeyErrorAttributeError)r   r%   r   r   r    __getattr__W   s
   
zDBRef.__getattr__SON[str, Any]c                 C  s<   t d| jfd| jfg}| jdur| j|d< || j |S )zsGet the SON document representation of this DBRef.

        Generally not needed by application developers
        z$refz$idNz$db)r	   r   r   r   r   r   )r   docr   r   r    as_doc]   s
   

zDBRef.as_docc                 C  s`   d dd | j D }| jd u rd| jd| j| dS d| jd| jd| j| dS )N c                 S  s    g | ]\}}d | d|qS ), =r   ).0kvr   r   r    
<listcomp>i   s     z"DBRef.__repr__.<locals>.<listcomp>zDBRef(r.   ))joinr   itemsr   r   r   )r   extrar   r   r    __repr__h   s   
"zDBRef.__repr__otherboolc                 C  s>   t |tr| j| j| j| jf}|j|j|j|jf}||kS tS r&   )r   r
   r   r   r   r   NotImplemented)r   r9   usZthemr   r   r    __eq__n   s
   
zDBRef.__eq__c                 C  s
   | |k S r&   r   )r   r9   r   r   r    __ne__u   s   
zDBRef.__ne__intc                 C  s$   t | j| j| jtt| j fS )z)Get a hash value for this :class:`DBRef`.)hashr   r   r   tuplesortedr   r6   r#   r   r   r    __hash__x   s   zDBRef.__hash__memoc                 C  s.   t t| j|t| j|t| j|t| j|S )z'Support function for `copy.deepcopy()`.)r
   r   r   r   r   r   )r   rD   r   r   r    __deepcopy__~   s   



zDBRef.__deepcopy__)NN)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   )r   r   )r%   r   r   r   )r   r*   )r9   r   r   r:   )r   r?   )rD   r   r   r
   )__name__
__module____qualname____doc__	__slots__r   __getstate__r   __setstate__Z_type_markerr!   propertyr   r   r   r)   r,   r8   r=   r>   rC   rE   r   r   r   r    r
      s,    #





r
   N)rI   
__future__r   copyr   typingr   r   r   Zbson._helpersr   r   Zbson.sonr	   r
   r   r   r   r    <module>   s   