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.)__collection__id
__database__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#   F/var/www/html/olx_land/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(r2   ))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"   r=   usthemr#   r#   r$   __eq__n   s
   
zDBRef.__eq__c                 C  s
   | |k S r*   r#   )r"   r=   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!   r:   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"   rI   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.   )r=   r   r   r>   )r   rD   )rI   r   r   r
   )__name__
__module____qualname____doc__	__slots__r   __getstate__r   __setstate___type_markerr%   propertyr   r   r   r-   r0   r<   rB   rC   rH   rJ   r#   r#   r#   r$   r
      s,    #





r
   N)rN   
__future__r   copyr   typingr   r   r   bson._helpersr   r   bson.sonr	   r
   r#   r#   r#   r$   <module>   s   