
    nh#                    `   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZ d	Z ej0                  d
      j2                  Z ej0                  d      j2                  Z ej0                  d
      j8                  ZddZddZ G d d      Z y)z)Tools for working with MongoDB ObjectIds.    )annotationsN)SystemRandom)AnyNoReturnOptionalTypeUnion)_datetime_to_millis	InvalidId)utci z>Iz>I5sc                    t        d| z        )NzS%r is not a valid ObjectId, it must be a 12-byte input or a 24-character hex stringr   )oids    s/var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/bson/objectid.py_raise_invalid_idr   %   s    
	(*-	.     c                 ,    t        j                  d      S )z+Get the 5-byte random field of an ObjectId.   )osurandom r   r   _random_bytesr   ,   s    ::a=r   c                  d   e Zd ZdZ ej
                         Z e       j                  de	      Z
 ej                         Z e       ZdZdZdddZedd       Zedd       Zedd	       Zdd
Z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#dZ$d#dZ%d$dZ&y)%ObjectIdzA MongoDB ObjectId.r   )__id   Nc                    || j                          yt        |t              rt        |      dk(  r|| _        y| j                  |       y)aZ  Initialize 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 <http://dochub.mongodb.org/core/objectids>`_.

        .. versionchanged:: 3.8
           :class:`~bson.objectid.ObjectId` now implements the `ObjectID
           specification version 0.2
           <https://github.com/mongodb/specifications/blob/master/source/
           objectid.rst>`_.
        N   )_ObjectId__generate
isinstancebyteslen_ObjectId__id_ObjectId__validateselfr   s     r   __init__zObjectId.__init__?   s;    J ;OOU#CBDIOOC r   c                F    t        t        |      dz        dz   } | |      S )aJ  Create 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.
        i  s           )	_PACK_INTr
   )clsgeneration_timer   s      r   from_datetimezObjectId.from_datetimek   s/    8 )/:dBC12 	 3xr   c                L    |sy	 t        |       y# t        t        f$ r Y yw xY w)zChecks if a `oid` string is valid or not.

        :param oid: the object id to validate

        .. versionadded:: 2.3
        FT)r   r   	TypeError)r*   r   s     r   is_validzObjectId.is_valid   s0     	SM9% 		s    ##c                    t        j                         }|| j                  k7  r|| _        t               | _        | j                  S )z1Generate a 5-byte random number once per process.)r   getpid_pidr   _ObjectId__random)r*   pids     r   _randomzObjectId._random   s4     iik#((?CH(?CL||r   c                8   t         j                  5  t         j                  }|dz   t        dz   z  t         _        ddd       t	        t        t        j                               t         j                               t              dd z   | _	        y# 1 sw Y   WxY w)z'Generate a new value for this ObjectId.   N   )
r   	_inc_lock_inc_MAX_COUNTER_VALUE_PACK_INT_RANDOMinttimer5   r)   r#   )r&   incs     r   
__generatezObjectId.__generate   sz     	A--C 1W);a)?@HM	A
 %S%5x7G7G7IJYWZ^\]^_M``		A 	As   )BBc                @   t        |t              r|j                  | _        yt        |t              r6t        |      dk(  r	 t        j                  |      | _        yt        |       yt        dt        |             # t        t        f$ r t        |       Y yw xY w)a   Validate 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    r   binaryr#   strr"   r!   fromhexr.   
ValueErrorr   typer%   s     r   
__validatezObjectId.__validate   s     c8$

DIS!3x2~+ %c 2DI "#&TUYZ]U^T_`aa ":. +%c*+s   B   BBc                    | j                   S )z/12-byte binary representation of this ObjectId.r#   r&   s    r   rC   zObjectId.binary   s     yyr   c                    t        | j                  dd       d   }t        j                  j                  |t              S )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.
        r   r8   )_UNPACK_INTr#   datetimefromtimestampr   )r&   	timestamps     r   r+   zObjectId.generation_time   s6      		!A/2	  ..y#>>r   c                    | j                   S )zdReturn value of object for pickling.
        needed explicitly because __slots__() defined.
        rJ   rK   s    r   __getstate__zObjectId.__getstate__   s     yyr   c                    t        |t              r|d   }n|}t        |t              r|j                  d      | _        y|| _        y)z Explicit state set from picklingr#   zlatin-1N)r    dictrD   encoder#   )r&   valuer   s      r   __setstate__zObjectId.__setstate__   s@     eT"(CC c3

9-DIDIr   c                \    t        j                  | j                        j                         S N)binasciihexlifyr#   decoderK   s    r   __str__zObjectId.__str__   s     		*1133r   c                    d| dS )Nz
ObjectId('z')r   rK   s    r   __repr__zObjectId.__repr__   s    D82&&r   c                `    t        |t              r| j                  |j                  k(  S t        S rY   r    r   r#   rC   NotImplementedr&   others     r   __eq__zObjectId.__eq__   %    eX&99,,r   c                `    t        |t              r| j                  |j                  k7  S t        S rY   ra   rc   s     r   __ne__zObjectId.__ne__   rf   r   c                `    t        |t              r| j                  |j                  k  S t        S rY   ra   rc   s     r   __lt__zObjectId.__lt__   %    eX&99u||++r   c                `    t        |t              r| j                  |j                  k  S t        S rY   ra   rc   s     r   __le__zObjectId.__le__  rf   r   c                `    t        |t              r| j                  |j                  kD  S t        S rY   ra   rc   s     r   __gt__zObjectId.__gt__  rk   r   c                `    t        |t              r| j                  |j                  k\  S t        S rY   ra   rc   s     r   __ge__zObjectId.__ge__  rf   r   c                ,    t        | j                        S )z,Get a hash value for this :class:`ObjectId`.)hashr#   rK   s    r   __hash__zObjectId.__hash__  s    DIIr   rY   )r   z%Optional[Union[str, ObjectId, bytes]]returnNone)r*   Type[ObjectId]r+   datetime.datetimeru   r   )r*   rw   r   r   ru   boolru   r!   )ru   rv   )r   r   ru   rv   )ru   rx   )rV   r   ru   rv   )ru   rD   )rd   r   ru   ry   )ru   r=   )'__name__
__module____qualname____doc__r   r1   r2   r   randintr;   r:   	threadingLockr9   r   r3   	__slots___type_markerr'   classmethodr,   r/   r5   r   r$   propertyrC   r+   rR   rW   r]   r_   re   rh   rj   rm   ro   rq   rt   r   r   r   r   r   1   s    299;D>!!!%78D	 IHIL*!X  @     ab,   	? 	? 4'





r   r   )r   rD   ru   r   rz   )!r~   
__future__r   rZ   rN   r   structr   r>   randomr   typingr   r   r   r   r	   bson.datetime_msr
   bson.errorsr   bson.tz_utilr   r;   Structpackr)   r<   unpackrM   r   r   r   r   r   r   <module>r      s    0 "   	     7 7 0 !  FMM$$$	 6==(-- fmmD!((
a ar   