
    +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	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ZddZddZ G d d          ZdS )z)Tools for working with MongoDB ObjectIds.    )annotationsN)SystemRandom)AnyNoReturnOptionalTypeUnion	InvalidId)utci oidstrreturnr   c                &    t          d| z            )NzS%r is not a valid ObjectId, it must be a 12-byte input or a 24-character hex stringr
   )r   s    Q/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/bson/objectid.py_raise_invalid_idr   "   s!    
	(*-	.      bytesc                 *    t          j        d          S )z+Get the 5-byte random field of an ObjectId.   )osurandom r   r   _random_bytesr   )   s    :a==r   c                     e Zd ZdZ ej                    Z e                                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d0dZd1dZd1dZd2d Z d2d!Z!d2d"Z"d2d#Z#d2d$Z$d2d%Z%d3d'Z&dS )4ObjectIdzA MongoDB ObjectId.r   )__id   Nr   %Optional[Union[str, ObjectId, bytes]]r   Nonec                    ||                                   dS t          |t                    rt          |          dk    r	|| _        dS |                     |           dS )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
isinstancer   len_ObjectId__id_ObjectId__validateselfr   s     r   __init__zObjectId.__init__<   sc    J ;OOU## 	!CBDIIIOOC     r   clsType[ObjectId]generation_timedatetime.datetimec                    |                                 }|||z
  }t          j        |                                          }t	          j        dt          |                    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.
        N>Is           )	utcoffsetcalendartimegm	timetuplestructpackint)r+   r-   offset	timestampr   s        r   from_datetimezObjectId.from_datetimeh   sj    6 !**,,-6OOO$=$=$?$?@@	k$I//2UUs3xxr   r   boolc                ^    |sdS 	 t          |           dS # t          t          f$ r Y dS 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   sM      	5	SMMM49% 	 	 	55	s    ,,r   c                    t          j                    }|| j        k    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     ikk#(??CH(??CL|r   c                   t          j        dt          t          j                                        }|t                                          z  }t          j        5  |t          j        dt          j                  dd         z  }t          j        dz   t          dz   z  t          _        ddd           n# 1 swxY w Y   || _	        dS )z'Generate a new value for this ObjectId.r0         N)
r5   r6   r7   timer   rD   	_inc_lock_inc_MAX_COUNTER_VALUEr&   r(   s     r   
__generatezObjectId.__generate   s     k$DIKK 0 011 	x!!!  	K 	K6;tX]33AaC88C%]Q.3E3IJHM	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 			s   AB77B;>B;c                   t          |t                    r|j        | _        dS t          |t                    rmt          |          dk    rI	 t                              |          | _        dS # t          t          f$ r t          |           Y dS w xY wt          |           dS t          dt          |                     )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&   r   r%   r   fromhexr=   
ValueErrorr   typer(   s     r   
__validatezObjectId.__validate   s     c8$$ 	b
DIIIS!! 		b3xx2~~+ %c 2 2DIII!:. + + +%c******+ "#&&&&&`UYZ]U^U^``aaas   A. . BBc                    | j         S )z/12-byte binary representation of this ObjectId.r&   r)   s    r   rO   zObjectId.binary   s     yr   c                    t          j        d| j        dd                   d         }t          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.
        r0   r   rG   )r5   unpackr&   datetimefromtimestampr   )r)   r9   s     r   r-   zObjectId.generation_time   s=     M$	!A#77:	 ..y#>>>r   c                    | j         S )zdReturn value of object for pickling.
        needed explicitly because __slots__() defined.
        rU   rV   s    r   __getstate__zObjectId.__getstate__   s     yr   valuec                    t          |t                    r	|d         }n|}t          |t                    r|                    d          | _        dS || _        dS )z Explicit state set from picklingr&   zlatin-1N)r$   dictr   encoder&   )r)   r]   r   s      r   __setstate__zObjectId.__setstate__   s]     eT"" 	(CCC c3 	

9--DIIIDIIIr   r   c                X    t          j        | j                                                  S N)binasciihexlifyr&   decoderV   s    r   __str__zObjectId.__str__   s!    	**11333r   c                    d| dS )Nz
ObjectId('z')r   rV   s    r   __repr__zObjectId.__repr__   s    &D&&&&r   otherc                Z    t          |t                    r| j        |j        k    S t          S rc   r$   r   r&   rO   NotImplementedr)   rj   s     r   __eq__zObjectId.__eq__   )    eX&& 	-9,,r   c                Z    t          |t                    r| j        |j        k    S t          S rc   rl   rn   s     r   __ne__zObjectId.__ne__   rp   r   c                Z    t          |t                    r| j        |j        k     S t          S rc   rl   rn   s     r   __lt__zObjectId.__lt__   )    eX&& 	,9u|++r   c                Z    t          |t                    r| j        |j        k    S t          S rc   rl   rn   s     r   __le__zObjectId.__le__  rp   r   c                Z    t          |t                    r| j        |j        k    S t          S rc   rl   rn   s     r   __gt__zObjectId.__gt__
  ru   r   c                Z    t          |t                    r| j        |j        k    S t          S rc   rl   rn   s     r   __ge__zObjectId.__ge__  rp   r   r7   c                *    t          | j                  S )z,Get a hash value for this :class:`ObjectId`.)hashr&   rV   s    r   __hash__zObjectId.__hash__  s    DIr   rc   )r   r   r   r    )r+   r,   r-   r.   r   r   )r+   r,   r   r   r   r;   r   r   )r   r    )r   r   r   r    )r   r.   )r]   r   r   r    )r   r   )rj   r   r   r;   )r   r7   )'__name__
__module____qualname____doc__r   r@   rA   r   randintrK   rJ   	threadingLockrI   r   rB   	__slots___type_markerr*   classmethodr:   r>   rD   r#   r'   propertyrO   r-   r\   ra   rg   ri   ro   rr   rt   rw   ry   r{   r~   r   r   r   r   r   .   s*       29;;D<>>!!!%788D	  I}HIL*! *! *! *! *!X    [B    [     [   b b b b,    X 	? 	? 	? X	?       4 4 4 4' ' ' '   
   
   
   
   
   
     r   r   )r   r   r   r   r   )r   
__future__r   rd   r2   rY   r   r5   r   rH   randomr   typingr   r   r   r   r	   bson.errorsr   bson.tz_utilr   rK   r   r   r   r   r   r   <module>r      s+   0 / " " " " " "    				             7 7 7 7 7 7 7 7 7 7 7 7 7 7 ! ! ! ! ! !             
h h h h h h h h h hr   