
    FCf00              
         d dl mZ d dlmZmZmZmZmZ d dlm	Z	 	 d Z
	 dZ	 dZ	 dZ	 dZ	 erd dlmZ d d	lmZ  G d
 d      Zej(                  Z	 ej*                  Z	 ej,                  Z	 ej.                  Z	 eefZej2                  ej(                  ej*                  ej,                  ej.                  fZej2                  dej(                  dej*                  dej,                  dej.                  diZdZ	 dZ	 dZ	 dZ	  G d de       Z!y)    )annotations)TYPE_CHECKINGAnyTupleTypeUnion)UUID            )array)mmapc                  (    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     K/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/bson/binary.pyr   r   B   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U dZdZded<   ef	 	 	 	 	 	 	 ddZee	j                  f	 	 	 	 	 	 	 dd       Ze	j                  fddZedd       Zd fd	Zdd
Zd fdZddZd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`
    or `subtype` is not an instance of :class:`int`.
    Raises ValueError if `subtype` is not in [0, 256).

    .. note::
      Instances of Binary with subtype 0 will be decoded directly to :class:`bytes`.

    :param data: the binary data to represent. Can be any bytes-like type
        that implements the buffer protocol.
    :param subtype: the `binary subtype
        <https://bsonspec.org/spec.html>`_
        to use

    .. versionchanged:: 3.9
      Support any bytes-like type that implements the buffer protocol.
    r   int_Binary__subtypec                    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))	
isinstancer&   	TypeError
ValueErrorbytes__new__
memoryviewtobytesr'   )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`.

        :param uuid: A :class:`uuid.UUID` instance.
        :param 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   r"   N   )r*   r	   r+   ALL_UUID_REPRESENTATIONSr,   r   r   r   r   r-   r   r   bytes_ler   )r1   uuiduuid_representationr3   payload	from_uuids         r    r>   zBinary.from_uuid   s    , $%CDD&>>Y  "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        |          )a9  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.

        :param 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 uuidr6   z)uuid_representation cannot be UNSPECIFIED)r-   r   r"   Nr7   r8   )r:   z to )r3   ALL_UUID_SUBTYPESr,   r9   r   r   r   r   r	   r   r   r   UUID_REPRESENTATION_NAMES)r4   r<   s     r    as_uuidzBinary.as_uuid(  s9     <<005dll^:NOO&>>Y  "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** |||+$''$T\\N$7PQd7e6fg
 	
r   c                    | j                   S )zSubtype of this binary data.)r'   r4   s    r    r3   zBinary.subtypeT  s     ~~r   c                    t         |          d   }t        |t              s|j	                  d      }|| j
                  fS )Nr   zlatin-1)super__getnewargs__r*   r-   encoder'   )r4   r2   	__class__s     r    rG   zBinary.__getnewargs__Y  s<    w%'*$&;;y)DT^^##r   c                    t        |t              r/| j                  t        |       f|j                  t        |      fk(  S y)NF)r*   r%   r'   r-   r3   r4   others     r    __eq__zBinary.__eq__`  s6    eV$NNE$K0U]]E%L4QQQ r   c                L    t         |          t        | j                        z  S N)rF   __hash__hashr'   )r4   rI   s    r    rP   zBinary.__hash__h  s    w!D$888r   c                    | |k(   S rO   r   rK   s     r    __ne__zBinary.__ne__k  s    5=  r   c                N    dt         j                  |        d| j                   dS )NzBinary(z, ))r-   __repr__r'   rD   s    r    rV   zBinary.__repr__n  s&    -.b0@BBr   )r1   Type[Binary]r2   z,Union[memoryview, bytes, _mmap, _array[Any]]r3   r&   returnr%   )r1   rW   r;   r	   r<   r&   rX   r%   )r<   r&   rX   r	   )rX   r&   )rX   zTuple[bytes, int])rL   r   rX   bool)rX   str)r   r   r   __doc___type_marker__annotations__BINARY_SUBTYPEr.   classmethodr   r   r>   rB   propertyr3   rG   rM   rP   rS   rV   __classcell__)rI   s   @r    r%   r%      s    0 LN
 &:  
	 BTB]B]4%4%!%4%<?4%	4% 4%l 2D1L1L *
X  $9!Cr   r%   N)"
__future__r   typingr   r   r   r   r   r;   r	   r^   FUNCTION_SUBTYPEOLD_BINARY_SUBTYPEr   r   r   _arrayr   _mmapr   r   r   r   r   r@   r   r9   rA   MD5_SUBTYPECOLUMN_SUBTYPESENSITIVE_SUBTYPEUSER_DEFINED_SUBTYPEr-   r%   r   r   r    <module>rl      s   # 9 9  
      	  %"@ @F &&
 #00
 !,, #00 &|4 ""$$""$$  ""$D!>$$&H""$D$$&H   
    hCU hCr   