o Sûb¤ã@sTdZddlmZddlmZmZmZddlmZm Z ddl m Z Gdd„de ƒZ dS) z@Tools for manipulating DBRefs (references to MongoDB documents).é)Údeepcopy)ÚAnyÚMappingÚOptional)Ú_getstate_slotsÚ_setstate_slots)ÚSONc @seZdZdZdZeZeZdZ  d$de de de e de e e e fd e d df d d „Zed e fd d„ƒZed e fdd„ƒZed e e fdd„ƒZde d e fdd„Zd ee e ffdd„Zdd„Zde d efdd„Zde d efdd„Zd efdd „Zd!e d dfd"d#„ZdS)%ÚDBRefz,A reference to a document stored in MongoDB.)Z __collectionZ__idZ __databaseZ__kwargsédNÚ collectionÚidÚdatabaseÚ_extraÚkwargsÚreturncKsVt|tƒs tdƒ‚|durt|tƒstdƒ‚||_||_||_| |p$i¡||_dS)aDInitialize 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 `_. z%collection must be an instance of strNz#database must be an instance of str)Ú isinstanceÚstrÚ TypeErrorÚ_DBRef__collectionÚ _DBRef__idÚ_DBRef__databaseÚupdateÚ_DBRef__kwargs)Úselfr r r rr©rú1/tmp/pip-target-onvjaxws/lib/python/bson/dbref.pyÚ__init__!s  zDBRef.__init__cCó|jS)z(Get the name of this DBRef's collection.)r©rrrrr EózDBRef.collectioncCr)zGet this DBRef's _id.)rrrrrr JrzDBRef.idcCr)zoGet the name of this DBRef's database. Returns None if this DBRef doesn't specify a database. )rrrrrr OszDBRef.databaseÚkeycCs$z|j|WStyt|ƒ‚w©N)rÚKeyErrorÚAttributeError)rr rrrÚ __getattr__Ws   ÿzDBRef.__getattr__cCs<td|jfd|jfgƒ}|jdur|j|d<| |j¡|S)zsGet the SON document representation of this DBRef. Generally not needed by application developers z$refz$idNz$db)rr r r rr)rÚdocrrrÚas_doc]s    z DBRef.as_doccCsLd dd„|j ¡Dƒ¡}|jdurd|j|j|fSd|j|j|j|fS)NÚcSsg|] \}}d||f‘qS)z, %s=%rr)Ú.0ÚkÚvrrrÚ isz"DBRef.__repr__..zDBRef(%r, %r%s)zDBRef(%r, %r, %r%s))ÚjoinrÚitemsr r r )rÚextrarrrÚ__repr__hs zDBRef.__repr__ÚothercCs>t|tƒr|j|j|j|jf}|j|j|j|jf}||kStSr!)rr rrrrÚNotImplemented)rr0ÚusZthemrrrÚ__eq__ns z DBRef.__eq__cCs ||k Sr!r)rr0rrrÚ__ne__us z DBRef.__ne__cCs$t|j|j|jtt|j ¡ƒƒfƒS)z)Get a hash value for this :class:`DBRef`.)ÚhashrrrÚtupleÚsortedrr-rrrrÚ__hash__xsÿzDBRef.__hash__ÚmemocCs.tt|j|ƒt|j|ƒt|j|ƒt|j|ƒƒS)z'Support function for `copy.deepcopy()`.)r rrrrr)rr9rrrÚ __deepcopy__~s     üzDBRef.__deepcopy__)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__rÚ __getstate__rÚ __setstate__Z _type_markerrrrrrÚpropertyr r r r$rr&r/Úboolr3r4Úintr8r:rrrrr sDûþýüûú ù$ r N)r>ÚcopyrÚtypingrrrZ bson._helpersrrZbson.sonrÚobjectr rrrrÚs