
    h}                     F    d Z ddlmZ ddlmZmZ ddlmZ  G d de      Z	y)z@Tools for manipulating DBRefs (references to MongoDB documents).    )deepcopy)	iteritemsstring_type)SONc                       e Zd ZdZdZdi fdZed        Zed        Zed        Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)DBRefz1A reference to a document stored in MongoDB.
    d   Nc                    t        |t              st        dt        j                  z        |,t        |t              st        dt        j                  z        || _        || _        || _        |j                  |       || _        y)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kwargss         M/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/dbref.py__init__zDBRef.__init__   s    $ *k2 -/:/C/CD E E
8[(I -/:/C/CD E E '	"f    c                     | j                   S )z<Get the name of this DBRef's collection as unicode.
        )r   r   s    r   r   zDBRef.collection=   s        r   c                     | j                   S )zGet this DBRef's _id.
        )r   r   s    r   r   zDBRef.idC   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.databaseI   s     r   c                 R    	 | j                   |   S # t        $ r t        |      w xY wN)r   KeyErrorAttributeError)r   keys     r   __getattr__zDBRef.__getattr__Q   s0    	&==%% 	& %%	&s    &c                 :    | j                   j                  |       y r!   )__dict__r   )r   states     r   __setstate__zDBRef.__setstate__Z   s    U#r   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]   sV    
 FDOO,477#% &==$CJ

4==!
r   c           
      6   dj                  t        | 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   r   r   r   r   )r   kvextras       r   __repr__zDBRef.__repr__i   s    %.t}}%=?!Q '(+ ? @== (,%HH !(,(,u> 	>	?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__q   sd    eU#//4#4#4))T]],B$$e&8&8JJ0D:r   c                     | |k(   S r!    )r   r8   s     r   __ne__zDBRef.__ne__z   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   itemsr   s    r   __hash__zDBRef.__hash__}   sB    T&&		4??6$--"5"5"789; < 	<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__   sH    Xd//6dii.doot4dmmT24 	4r   )r   
__module____qualname____doc___type_markerr   propertyr   r   r   r%   r)   r,   r5   r;   r>   rD   rG   r=   r   r   r   r      s|     L04R > ! !
  
  &$
>!<
4r   r   N)
rJ   copyr   bson.py3compatr   r   bson.sonr   objectr   r=   r   r   <module>rQ      s"    G  1 p4F p4r   