
    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)DBRefz,A 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)aD  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

        .. seealso:: The MongoDB documentation on `dbrefs <https://dochub.mongodb.org/core/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         H/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/bson/dbref.py__init__zDBRef.__init__   st    $ *k2EH\H\\]]
8[(ICkFZFZZ[[&	"f    c                     | j                   S )z3Get 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.id?   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.databaseD   s     r   c                 R    	 | j                   |   S # t        $ r t        |      w xY wN)r   KeyErrorAttributeError)r   keys     r   __getattr__zDBRef.__getattr__L   s0    	&==%% 	& %%	&s    &c                 :    | j                   j                  |       y r!   )__dict__r   )r   states     r   __setstate__zDBRef.__setstate__U   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_docX   sQ    
 FDOO,udgg.>?@==$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__c   ss    	$--8PQ1a+QR== (,%HH !(,$--QVWW R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__i   s^    eU#//4#4#4diiOB$$e&8&8%**ennUD:r   c                     | |k(   S r!    )r   r8   s     r   __ne__zDBRef.__ne__p   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__s   s@    		4??E&I\I\I^B_<`a
 	
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__y   sI    T&&-TYY%T__d+T]]D)	
 	
r   )r   
__module____qualname____doc___type_markerr   propertyr   r   r   r%   r)   r,   r5   r;   r>   rD   rG   r=   r   r   r   r      s{    6 L04R : ! !    &$	X!

r   r   N)
rJ   copyr   bson.py3compatr   r   bson.sonr   objectr   r=   r   r   <module>rQ      s"    G  1 i
F i
r   