
    h:              
          d dl mZ d dlmZ d dlmZ 	 d Z	 dZ	 dZ	 dZ		 dZ
	  G d d	      Zej                  Z	 ej                  Z	 ej                  Z	 ej                  Z	 e	e
fZej"                  ej                  ej                  ej                  ej                  fZej"                  d
ej                  dej                  dej                  dej                  diZdZ	 dZ	  G d de      Z G d de      Zy)    )UUID)warn)PY3            c                   (    e Zd ZdZ	 eZ	 eZ	 dZ	 dZ	y)UuidRepresentationr         N)
__name__
__module____qualname__UNSPECIFIEDUUID_SUBTYPESTANDARDOLD_UUID_SUBTYPEPYTHON_LEGACYJAVA_LEGACYCSHARP_LEGACY     N/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/binary.pyr   r   <   s<    K  H	 %M	 K	 M	r   r   zUuidRepresentation.UNSPECIFIEDzUuidRepresentation.STANDARDz UuidRepresentation.PYTHON_LEGACYzUuidRepresentation.JAVA_LEGACYz UuidRepresentation.CSHARP_LEGACYr      c                        e Zd ZdZdZefdZeej                  fd       Z
ej                  fdZed        Z fdZd Z fd	Zd
 Zd Z xZS )Binarya  Representation of BSON binary data.

    This is necessary because we want to represent Python strings as
    the BSON string type. We need to wrap binary data so we can tell
    the difference between what should be considered binary data and
    what should be considered a string when we encode to BSON.

    Raises TypeError if `data` is not an instance of :class:`bytes`
    (:class:`str` in python 2) or `subtype` is not an instance of
    :class:`int`. Raises ValueError if `subtype` is not in [0, 256).

    .. note::
      In python 3 instances of Binary with subtype 0 will be decoded
      directly to :class:`bytes`.

    :Parameters:
      - `data`: the binary data to represent. Can be any bytes-like type
        that implements the buffer protocol.
      - `subtype` (optional): the `binary subtype
        <http://bsonspec.org/#/specification>`_
        to use

    .. versionchanged:: 3.9
      Support any bytes-like type that implements the buffer protocol.
    r   c                     t        |t              st        d      |dk\  s|dk  rt        d      t        j                  | t        |      j                               }||_        |S )Nz"subtype must be an instance of int   r   z%subtype must be contained in [0, 256))	
isinstanceint	TypeError
ValueErrorbytes__new__
memoryviewtobytes_Binary__subtype)clsdatasubtypeselfs       r   r%   zBinary.__new__   s[    '3'@AAc>Wq[DEE}}S*T"2":":"<= r   c                    t        |t              st        d      |t        vrt	        d      |t
        j                  k(  rt	        d      t        }|t
        j                  k(  r|j                  }ni|t
        j                  k(  r$|j                  }|dd ddd   |dd ddd   z   }n2|t
        j                  k(  r|j                  }nt        }|j                  } | ||      S )	a  Create a BSON Binary object from a Python UUID.

        Creates a :class:`~bson.binary.Binary` object from a
        :class:`uuid.UUID` instance. Assumes that the native
        :class:`uuid.UUID` instance uses the byte-order implied by the
        provided ``uuid_representation``.

        Raises :exc:`TypeError` if `uuid` is not an instance of
        :class:`~uuid.UUID`.

        :Parameters:
          - `uuid`: A :class:`uuid.UUID` instance.
          - `uuid_representation`: A member of
            :class:`~bson.binary.UuidRepresentation`. Default:
            :const:`~bson.binary.UuidRepresentation.STANDARD`.
            See :ref:`handling-uuid-data-example` for details.

        .. versionadded:: 3.11
        z%uuid must be an instance of uuid.UUIDGuuid_representation must be a value from bson.binary.UuidRepresentationa  cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED. UUIDs can be manually converted to bson.Binary instances using bson.Binary.from_uuid() or a different UuidRepresentation can be configured. See the documentation for UuidRepresentation for more information.r      N   )r    r   r"   ALL_UUID_REPRESENTATIONSr#   r   r   r   r   r$   r   r   bytes_ler   )r)   uuiduuid_representationr+   payload	from_uuids         r   r7   zBinary.from_uuid   s    * $%CDD&>> C D D "4"@"@@;< < #"4"B"BBjjG $6$B$BB

I!nTrT*Yq_TrT-BBG $6$D$DDmmG #GjjG7G$$r   c                    | j                   t        vrt        d| j                   d      |t        vrt        d      |t        j
                  k(  rt        d      |t        j                  k(  r| j                   t        k(  rt        |       S |t        j                  k(  r4| j                   t        k(  rrt        | dd ddd	   | dd
 ddd	   z         S |t        j                  k(  r| j                   t        k(  r+t        |       S | j                   t        k(  rt        |       S t        d| j                   dt        |         )aM  Create a Python UUID from this BSON Binary object.

        Decodes this binary object as a native :class:`uuid.UUID` instance
        with the provided ``uuid_representation``.

        Raises :exc:`ValueError` if this :class:`~bson.binary.Binary` instance
        does not contain a UUID.

        :Parameters:
          - `uuid_representation`: A member of
            :class:`~bson.binary.UuidRepresentation`. Default:
            :const:`~bson.binary.UuidRepresentation.STANDARD`.
            See :ref:`handling-uuid-data-example` for details.

        .. versionadded:: 3.11
        zcannot decode subtype z
 as a uuidr.   z)uuid_representation cannot be UNSPECIFIED)r$   r   r/   Nr0   r1   )r3   z to )r+   ALL_UUID_SUBTYPESr#   r2   r   r   r   r   r   r   r   r   UUID_REPRESENTATION_NAMES)r,   r5   s     r   as_uuidzBinary.as_uuid  s9   " <<00     &>> > ? ? "4"@"@@HII $6$D$DD||//$'' $6$B$BB||//$q)DbD/D2Jtt4D"DEE $6$D$DD||//T** |||+$''78KLN O 	Or   c                     | j                   S )z%Subtype of this binary data.
        )r(   r,   s    r   r+   zBinary.subtype8  s     ~~r   c                     t         t        |          d   }t        r!t	        |t
              s|j                  d      }|| j                  fS )Nr   zlatin-1)superr   __getnewargs__r   r    r$   encoder(   )r,   r*   	__class__s     r   r@   zBinary.__getnewargs__>  s@    VT13A6z$.;;y)DT^^##r   c                     t        |t              r/| j                  t        |       f|j                  t        |      fk(  S y)NF)r    r   r(   r$   r+   r,   others     r   __eq__zBinary.__eq__E  s;    eV$^^U4[1]]E%L12 3
 r   c                 T    t         t        |          t        | j                        z  S N)r?   r   __hash__hashr(   )r,   rB   s    r   rI   zBinary.__hash__N  s!    VT+-T^^0DDDr   c                     | |k(   S rH   r   rD   s     r   __ne__zBinary.__ne__Q  s    5=  r   c                 N    dt         j                  |       d| j                  dS )NzBinary(z, ))r$   __repr__r(   r=   s    r   rO   zBinary.__repr__T  s    #(>>$#7HHr   )r   r   r   __doc___type_markerBINARY_SUBTYPEr%   classmethodr   r   r7   r;   propertyr+   r@   rF   rI   rL   rO   __classcell__)rB   s   @r   r   r      sv    4 L#1  1C1L1L 1% 1%f +=*E*E *OX  
$E!Ir   r   c                   2    e Zd ZdZd Zd Zed        Zd Zy)
UUIDLegacya  **DEPRECATED** - UUID wrapper to support working with UUIDs stored as
    PYTHON_LEGACY.

    .. note:: This class has been deprecated and will be removed in
       PyMongo 4.0. Use :meth:`~bson.binary.Binary.from_uuid` and
       :meth:`~bson.binary.Binary.as_uuid` with the appropriate
       :class:`~bson.binary.UuidRepresentation` to handle legacy-formatted
       UUIDs instead.::

            from bson import Binary, UUIDLegacy, UuidRepresentation
            import uuid

            my_uuid = uuid.uuid4()
            legacy_uuid = UUIDLegacy(my_uuid)
            binary_uuid = Binary.from_uuid(
                my_uuid, UuidRepresentation.PYTHON_LEGACY)

            assert legacy_uuid == binary_uuid
            assert legacy_uuid.uuid == binary_uuid.as_uuid(
                UuidRepresentation.PYTHON_LEGACY)

    .. doctest::

      >>> import uuid
      >>> from bson.binary import Binary, UUIDLegacy, STANDARD
      >>> from bson.codec_options import CodecOptions
      >>> my_uuid = uuid.uuid4()
      >>> coll = db.get_collection('test',
      ...                          CodecOptions(uuid_representation=STANDARD))
      >>> coll.insert_one({'uuid': Binary(my_uuid.bytes, 3)}).inserted_id
      ObjectId('...')
      >>> coll.count_documents({'uuid': my_uuid})
      0
      >>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
      1
      >>> coll.find({'uuid': UUIDLegacy(my_uuid)})[0]['uuid']
      UUID('...')
      >>>
      >>> # Convert from subtype 3 to subtype 4
      >>> doc = coll.find_one({'uuid': UUIDLegacy(my_uuid)})
      >>> coll.replace_one({"_id": doc["_id"]}, doc).matched_count
      1
      >>> coll.count_documents({'uuid': UUIDLegacy(my_uuid)})
      0
      >>> coll.count_documents({'uuid': {'$in': [UUIDLegacy(my_uuid), my_uuid]}})
      1
      >>> coll.find_one({'uuid': my_uuid})['uuid']
      UUID('...')

    Raises :exc:`TypeError` if `obj` is not an instance of :class:`~uuid.UUID`.

    :Parameters:
      - `obj`: An instance of :class:`~uuid.UUID`.

    .. versionchanged:: 3.11
       Deprecated. The same functionality can be replicated using the
       :meth:`~Binary.from_uuid` and :meth:`~Binary.to_uuid` methods with
       :data:`~UuidRepresentation.PYTHON_LEGACY`.
    .. versionadded:: 2.1
    c                     t        dt        d       t        |t              st	        d      t
        j                  | |j                  t              }||_	        |S )NzThe UUIDLegacy class has been deprecated and will be removed in PyMongo 4.0. Use the Binary.from_uuid() and Binary.to_uuid() with the appropriate UuidRepresentation to handle legacy-formatted UUIDs instead.r   )
stacklevelz$obj must be an instance of uuid.UUID)
r   DeprecationWarningr    r   r"   r   r%   r$   r   _UUIDLegacy__uuid)r)   objr,   s      r   r%   zUUIDLegacy.__new__  sQ    . 1	. #t$BCC~~c399.>?r   c                     | j                   fS rH   r[   r=   s    r   r@   zUUIDLegacy.__getnewargs__  s    ~r   c                     | j                   S )z;UUID instance wrapped by this UUIDLegacy instance.
        r^   r=   s    r   r4   zUUIDLegacy.uuid  s     {{r   c                      d| j                   z  S )NzUUIDLegacy('%s')r^   r=   s    r   rO   zUUIDLegacy.__repr__  s    !DKK//r   N)	r   r   r   rP   r%   r@   rT   r4   rO   r   r   r   rW   rW   X  s+    ;z  
0r   rW   N)r4   r   warningsr   bson.py3compatr   rR   FUNCTION_SUBTYPEOLD_BINARY_SUBTYPEr   r   r   r   r   r   r   r9   r   r2   r:   MD5_SUBTYPEUSER_DEFINED_SUBTYPEr$   r   rW   r   r   r   <module>rg      sj      
       @ @F &&
 #00
 !,, #00 &|4 .::.77.<<.::.<<	>  ""$D!>$$&H""$D$$&HJ    dIU dINV0 V0r   