+\h#`dZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZmZmZddlmZddlmZddlmZd Zej0d j2Zej0d j2Zej0d j8Zdd Zdd ZGddZ y)z)Tools for working with MongoDB ObjectIds.) annotationsN) SystemRandom)AnyNoReturnOptionalTypeUnion)_datetime_to_millis InvalidId)utciz>Iz>I5sctd|z)NzS%r is not a valid ObjectId, it must be a 12-byte input or a 24-character hex stringr )oids P/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/bson/objectid.py_raise_invalid_idr%s  (*- . c,tjdS)z+Get the 5-byte random field of an ObjectId.)osurandomrr _random_bytesr,s ::a=rcdeZdZdZej Zejde Z e jZ eZdZdZdddZeddZeddZedd Zdd Zdd Zedd Zed d ZddZd!dZd"dZd"dZd#dZ d#dZ!d#dZ"d#dZ#d#dZ$d#dZ%d$dZ&y)%ObjectIdzA MongoDB ObjectId.r)__idNc||jyt|trt|dk(r||_y|j |y)aZInitialize a new ObjectId. An ObjectId is a 12-byte unique identifier consisting of: - a 4-byte value representing the seconds since the Unix epoch, - a 5-byte random value, - a 3-byte counter, starting with a random value. By default, ``ObjectId()`` creates a new unique identifier. The optional parameter `oid` can be an :class:`ObjectId`, or any 12 :class:`bytes`. For example, the 12 bytes b'foo-bar-quux' do not follow the ObjectId specification but they are acceptable input:: >>> ObjectId(b'foo-bar-quux') ObjectId('666f6f2d6261722d71757578') `oid` can also be a :class:`str` of 24 hex digits:: >>> ObjectId('0123456789ab0123456789ab') ObjectId('0123456789ab0123456789ab') Raises :class:`~bson.errors.InvalidId` if `oid` is not 12 bytes nor 24 hex digits, or :class:`TypeError` if `oid` is not an accepted type. :param oid: a valid ObjectId. .. seealso:: The MongoDB documentation on `ObjectIds `_. .. versionchanged:: 3.8 :class:`~bson.objectid.ObjectId` now implements the `ObjectID specification version 0.2 `_. N )_ObjectId__generate isinstancebyteslen _ObjectId__id_ObjectId__validateselfrs r__init__zObjectId.__init__?s;J ; OO  U #CBDI OOC rcFtt|dzdz}||S)aJCreate a dummy ObjectId instance with a specific generation time. This method is useful for doing range queries on a field containing :class:`ObjectId` instances. .. warning:: It is not safe to insert a document containing an ObjectId generated using this method. This method deliberately eliminates the uniqueness guarantee that ObjectIds generally provide. ObjectIds generated with this method should be used exclusively in queries. `generation_time` will be converted to UTC. Naive datetime instances will be treated as though they already contain UTC. An example using this helper to get documents where ``"_id"`` was generated before January 1, 2010 would be: >>> gen_time = datetime.datetime(2010, 1, 1) >>> dummy_id = ObjectId.from_datetime(gen_time) >>> result = collection.find({"_id": {"$lt": dummy_id}}) :param generation_time: :class:`~datetime.datetime` to be used as the generation time for the resulting ObjectId. is) _PACK_INTr )clsgeneration_timers r from_datetimezObjectId.from_datetimeks/8 )/:dB C1 2 3xrcL|sy t|y#ttf$rYywxYw)zChecks if a `oid` string is valid or not. :param oid: the object id to validate .. versionadded:: 2.3 FT)rr TypeError)r*rs ris_validzObjectId.is_valids0  SM9%  s ##ctj}||jk7r||_t|_|jS)z1Generate a 5-byte random number once per process.)rgetpid_pidr_ObjectId__random)r*pids r_randomzObjectId._randoms4iik #((?CH(?CL||rc8tj5tj}|dztdzzt_dddt t t j tjtddz|_ y#1swYWxYw)z'Generate a new value for this ObjectId.N) r _inc_lock_inc_MAX_COUNTER_VALUE_PACK_INT_RANDOMinttimer5r)r#)r&incs r __generatezObjectId.__generatesz    A--C 1W);a)?@HM A %S%5x7G7G7IJYWZ^\]^_M``  A As )BBc@t|tr|j|_yt|tr6t |dk(r t j||_yt|ytdt|#ttf$rt|YywxYw)aValidate and use the given id for this ObjectId. Raises TypeError if id is not an instance of :class:`str`, :class:`bytes`, or ObjectId. Raises InvalidId if it is not a valid ObjectId. :param oid: a valid ObjectId z6id must be an instance of (bytes, str, ObjectId), not N) r rbinaryr#strr"r!fromhexr. ValueErrorrtyper%s r __validatezObjectId.__validates c8 $ DI S !3x2~+ % c 2DI"#&TUYZ]U^T_`a a ":.+%c*+sBBBc|jS)z/12-byte binary representation of this ObjectId.r#r&s rrCzObjectId.binarysyyrct|jddd}tjj|tS)a A :class:`datetime.datetime` instance representing the time of generation for this :class:`ObjectId`. The :class:`datetime.datetime` is timezone aware, and represents the generation time in UTC. It is precise to the second. rr8) _UNPACK_INTr#datetime fromtimestampr )r& timestamps rr+zObjectId.generation_times6  !A/2   ..y#>>rc|jS)zdReturn value of object for pickling. needed explicitly because __slots__() defined. rJrKs r __getstate__zObjectId.__getstate__syyrct|tr|d}n|}t|tr|jd|_y||_y)z Explicit state set from picklingr#zlatin-1N)r dictrDencoder#)r&valuers r __setstate__zObjectId.__setstate__s@ eT "(CC c3  9-DIDIrc\tj|jjSN)binasciihexlifyr#decoderKs r__str__zObjectId.__str__s  *1133rcd|dS)Nz ObjectId('z')rrKs r__repr__zObjectId.__repr__sD82&&rc`t|tr|j|jk(StSrYr rr#rCNotImplementedr&others r__eq__zObjectId.__eq__% eX &99 , ,rc`t|tr|j|jk7StSrYrarcs r__ne__zObjectId.__ne__rfrc`t|tr|j|jkStSrYrarcs r__lt__zObjectId.__lt__% eX &99u||+ +rc`t|tr|j|jkStSrYrarcs r__le__zObjectId.__le__rfrc`t|tr|j|jkDStSrYrarcs r__gt__zObjectId.__gt__rkrc`t|tr|j|jk\StSrYrarcs r__ge__zObjectId.__ge__ rfrc,t|jS)z,Get a hash value for this :class:`ObjectId`.)hashr#rKs r__hash__zObjectId.__hash__sDIIrrY)rz%Optional[Union[str, ObjectId, bytes]]returnNone)r*Type[ObjectId]r+datetime.datetimerur)r*rwrrruboolrur!)rurv)rrrurv)rurx)rVrrurv)rurD)rdrrury)rur=)'__name__ __module__ __qualname____doc__rr1r2rrandintr;r: threadingLockr9rr3 __slots__ _type_markerr' classmethodr,r/r5rr$propertyrCr+rRrWr]r_rerhrjrmrorqrtrrrrr1s 299;D > ! !!%7 8D  IHIL*!X@ ab, ? ?  4'      rr)rrDrurrz)!r~ __future__rrZrNrstructrr>randomrtypingrrrrr bson.datetime_msr bson.errorsr bson.tz_utilr r;Structpackr)r<unpackrMrrrrrrrs0"  770! FMM$  $ $  6==(--fmmD!((  aar