o
    ?8¾\}  ã                   @   s@   d Z ddlmZ ddlmZmZ ddlmZ G dd„ deƒZ	dS )z@Tools for manipulating DBRefs (references to MongoDB documents).é    )Údeepcopy)Ú	iteritemsÚstring_type)ÚSONc                   @   s†   e Zd ZdZdZdi f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dd„ ZdS )ÚDBRefz1A reference to a document stored in MongoDB.
    éd   Nc                 K   s^   t |tƒstdtj ƒ‚|durt |tƒstdtj ƒ‚|| _|| _|| _| |¡ || _dS )aû  Initialize a new :class:`DBRef`.

        Raises :class:`TypeError` if `collection` or `database` is not
        an instance of :class:`basestring` (:class:`str` in python 3).
        `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.

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

        .. mongodoc:: dbrefs
        z$collection must be an instance of %sNz"database must be an instance of %s)	Ú
isinstancer   Ú	TypeErrorÚ__name__Ú_DBRef__collectionÚ
_DBRef__idÚ_DBRef__databaseÚupdateÚ_DBRef__kwargs)ÚselfÚ
collectionÚidÚdatabaseÚ_extraÚkwargs© r   ú</var/www/html/env/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 as unicode.
        )r   ©r   r   r   r   r   =   ó   zDBRef.collectionc                 C   r   )zGet this DBRef's _id.
        )r   r   r   r   r   r   C   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   I   s   zDBRef.databasec                 C   s$   z| j | W S  ty   t|ƒ‚w ©N)r   ÚKeyErrorÚAttributeError)r   Úkeyr   r   r   Ú__getattr__Q   s
   ÿzDBRef.__getattr__c                 C   s   | j  |¡ d S r   )Ú__dict__r   )r   Ústater   r   r   Ú__setstate__Z   s   zDBRef.__setstate__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   sL   d  dd„ t| jƒD ƒ¡}| jd u rd| j| j|f S d| j| j| j|f S )NÚ c                 S   s   g | ]
\}}d ||f ‘qS )z, %s=%rr   )Ú.0ÚkÚvr   r   r   Ú
<listcomp>j   s    ÿz"DBRef.__repr__.<locals>.<listcomp>zDBRef(%r, %r%s)zDBRef(%r, %r, %r%s))Újoinr   r   r   r   r   )r   Úextrar   r   r   Ú__repr__i   s   
ÿ

ÿzDBRef.__repr__c                 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   ÚotherÚusÚthemr   r   r   Ú__eq__q   s   
ÿÿzDBRef.__eq__c                 C   s
   | |k S r   r   )r   r/   r   r   r   Ú__ne__z   s   
zDBRef.__ne__c                 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   Úitemsr   r   r   r   Ú__hash__}   s   ÿzDBRef.__hash__c                 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   Úmemor   r   r   Ú__deepcopy__‚   s
   


ýzDBRef.__deepcopy__)r
   Ú
__module__Ú__qualname__Ú__doc__Ú_type_markerr   Úpropertyr   r   r   r    r#   r%   r-   r2   r3   r8   r:   r   r   r   r   r      s$    


		r   N)
r=   Úcopyr   Úbson.py3compatr   r   Úbson.sonr   Úobjectr   r   r   r   r   Ú<module>   s
   