o
    C©Ì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Ú__kwargséd   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#   úY/var/www/html/Moveonwheels/move_on_wheels/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   