+\h{P lddlmZddlZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZddlmZ dZ dZ dZ dZ d Z er dd lmZdd lmZGd d Zej6Z ej8Z ej:Z ej<Z eefZej@ej6ej8ej:ej<fZ!ej@dej6dej8dej:dej<diZ"dZ# dZ$ dZ% dZ& dZ' GddeZ(GddZ)Gdde*Z+y)) annotationsN)Enum) TYPE_CHECKINGAnyOptionalSequenceTupleTypeUnionoverload)UUID)array)mmapc(eZdZdZ eZ eZ dZ dZ y)UuidRepresentationrN) __name__ __module__ __qualname__ UNSPECIFIED UUID_SUBTYPESTANDARDOLD_UUID_SUBTYPE PYTHON_LEGACY JAVA_LEGACY CSHARP_LEGACYN/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/bson/binary.pyrrEs<K H %M K M r#rzUuidRepresentation.UNSPECIFIEDzUuidRepresentation.STANDARDz UuidRepresentation.PYTHON_LEGACYzUuidRepresentation.JAVA_LEGACYz UuidRepresentation.CSHARP_LEGACYr ceZdZdZdZdZdZy)BinaryVectorDtypeaNDatatypes of vector subtype. :param FLOAT32: (0x27) Pack list of :class:`float` as float32 :param INT8: (0x03) Pack list of :class:`int` in [-128, 127] as signed int8 :param PACKED_BIT: (0x10) Pack list of :class:`int` in [0, 255] as unsigned uint8 The `PACKED_BIT` value represents a special case where vector values themselves can only be of two values (0 or 1) but these are packed together into groups of 8, a byte. In Python, these are displayed as ints in range [0, 255] Each value is of type bytes with a length of one. .. versionadded:: 4.10 'N)rrr__doc__INT8FLOAT32 PACKED_BITr"r#r$r*r*s  DGJr#r*c6eZdZdZdZdd dZd dZd dZd dZy) BinaryVectorzbVector of numbers along with metadata for binary interoperability. .. versionadded:: 4.10 datadtypepaddingc.||_||_||_y)a\ :param data: Sequence of numbers representing the mathematical vector. :param dtype: The data type stored in binary :param padding: The number of bits in the final byte that are to be ignored when a vector element's size is less than a byte and the length of the vector is not a multiple of 8. Nr4)selfr5r6r7s r$__init__zBinaryVector.__init__s   r#cVd|jd|jd|jdS)NzBinaryVector(dtype=z , padding=z, data=))r6r7r5r9s r$__repr__zBinaryVector.__repr__s-$TZZL 4<<.PTPYPY{Z[\\r#ct|tsy|j|jk(xr4|j|jk(xr|j|jk(SNF) isinstancer3r6r7r5r9others r$__eq__zBinaryVector.__eq__sK%. JJ%++ % c$,,%--*G cDIIY^YcYcLc r#c,t|jSN)lenr5r=s r$__len__zBinaryVector.__len__s499~r#Nr)r5zSequence[float | int]r6r*r7intreturnstrrCrrLboolrLrJ) rrrr. __slots__r:r>rDrHr"r#r$r3r3s#-I ] r#r3c\eZdZUdZdZded<ef ddZee jf ddZ e jfddZ ee ddZee d dd Ze d dd Zdd Zedd Zdfd ZddZdfd ZddZddZxZS)BinaryaRepresentation of BSON binary data. We want to represent Python strings as the BSON string type. We need to wrap binary data so that we can tell the difference between what should be considered binary data and what should be considered a string when we encode to BSON. Subtype 9 provides a space-efficient representation of 1-dimensional vector data. Its data is prepended with two bytes of metadata. The first (dtype) describes its data type, such as float32 or int8. The second (padding) prescribes the number of bits to ignore in the final byte. This is relevant when the element size of the dtype is not a multiple of 8. Raises TypeError if `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 `_ to use .. versionchanged:: 3.9 Support any bytes-like type that implements the buffer protocol. .. versionchanged:: 4.10 Addition of vector subtype. rrJ_Binary__subtypect|tstdt||dk\s|dkr t dt j |t|j}||_ |S)Nz(subtype must be an instance of int, not rz%subtype must be contained in [0, 256)) rArJ TypeErrortype ValueErrorbytes__new__ memoryviewtobytesrT)clsr5subtyper9s r$r[zBinary.__new__+sh '3'FtG}oVW W c>Wq[DE E}}S*T"2":":"<=  r#ct|tstdt||tvr t d|t jk(r t dt}|t jk(r |j}ni|t jk(r$|j}|ddddd|dddddz}n2|t jk(r |j}nt}|j}|||S) aCreate 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.UUID, not Guuid_representation must be a value from bson.binary.UuidRepresentationacannot 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.rr&N)rAr rWrXALL_UUID_REPRESENTATIONSrYrrrrrZr r!bytes_ler)r^uuiduuid_representationr_payload from_uuids r$rizBinary.from_uuid9s,$%I$t*VW W &> >Y  "4"@"@ @; # "4"B"B BjjG $6$B$B B I!nTrT*Yq_TrT-BBG $6$D$D DmmG#GjjG7G$$r#c|jtvrtd|jd|tvr td|tj k(r td|tj k(r|jtk(rt|S|tjk(r4|jtk(rrt|ddddd |dd ddd zS|tjk(r|jtk(r+t| S|jtk(r t|Std|jd t|) a9Create 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 zcannot decode subtype z as a uuidraz)uuid_representation cannot be UNSPECIFIED)rZrr&Nrbrc)rez to ) r_ALL_UUID_SUBTYPESrYrdrrrrr r r!rUUID_REPRESENTATION_NAMES)r9rgs r$as_uuidzBinary.as_uuidps9 <<0 05dll^:NO O &> >Y  "4"@"@ @HI I $6$D$D D||//$'' $6$B$B B||//$q)DbD/D2Jtt4D"DEE $6$D$D D||//T**|||+$''$T\\N$7PQd7e6f g  r#cyrFr")r^vectors r$ from_vectorzBinary.from_vectors r#cyrFr")r^ror6r7s r$rpzBinary.from_vectors r#ct|tr3|s|r td|j}|j}|j }|dn|}|t jk(rd}|rtd||t jk(r.d}d|cxkrdkDrnntd|d|r@|s>td |t jk(rd }|rtd|td |ztjd |j|}tjd t||g|}|r't|r|dd|zdz zdk(s td|||ztS)a#Create a BSON :class:`~bson.binary.Binary` of Vector subtype. To interpret the representation of the numbers, a data type must be included. See :class:`~bson.binary.BinaryVectorDtype` for available types and descriptions. The dtype and padding are prepended to the binary data's value. :param vector: Either a List of values, or a :class:`~bson.binary.BinaryVector` dataclass. :param dtype: Data type of the values :param padding: For fractional bytes, number of bits to ignore at end of vector. :return: Binary packed data identified by dtype and padding. .. versionchanged:: 4.14 When padding is non-zero, ignored bits should be zero. Raise exception on encoding, warn on decoding. .. versionadded:: 4.10 zkThe first argument, vector, has type BinaryVector. dtype or padding cannot be separately defined, but were.rbz padding does not apply to dtype=Br%zpadding=z. It must be in [0,1, ..7].z#Empty vector with non-zero padding.fz%s not yet supported=5.0, they must be zero.) stacklevelz(Binary Vector dtype %s not yet supported)r_r|rYry unpack_fromr*rGr1r/listr3r0warningswarnDeprecationWarningrxname) r9positionr6r7n_values dtype_format format_stringron_bytesunpacked_uint8ss r$ as_vectorzBinary.as_vectors9 <<> )5dll^<PQ Q++E4BwA !%(t9x' u 1 < <<)'2e_d^ffgh  %** *Lz,8M&,,]D(KLFw7 7 '// /$i(*G!|H{ YLz,8M&,,]D(KLFw7 7 '22 2x !UVV{gk #:7)C]!^__Lz,8M"6#5#5mT8#TUO8(;qG|q>P(PTU(U I&   @ @&&PSXS]S]&]^ ^r#c|jS)zSubtype of this binary data.)rTr=s r$r_zBinary.subtype#s~~r#ct|d}t|ts|j d}||j fS)Nrzlatin-1)super__getnewargs__rArZencoderT)r9r5 __class__s r$rzBinary.__getnewargs__(s<w%'*$&;;y)DT^^##r#ct|tr/|jt|f|jt|fk(Syr@)rArSrTrZr_rBs r$rDz Binary.__eq__/s6 eV $NNE$K0U]]E%L4QQ Qr#cLt|t|jz SrF)r__hash__hashrT)r9rs r$rzBinary.__hash__7sw!D$888r#c||k( SrFr"rBs r$__ne__z Binary.__ne__:s5=  r#c|jtk(rd|jdSdtj|d|jdS)NzzBinary(z, r<)rTSENSITIVE_SUBTYPErZr>r=s r$r>zBinary.__repr__=sG >>. .''7r: :U^^D12"T^^4DAF Fr#)r^ Type[Binary]r5z,Union[memoryview, bytes, _mmap, _array[Any]]r_rJrLrS)r^rrfr rgrJrLrS)rgrJrLr )r^rror3rLrSrI) r^rrozUnion[list[int], list[float]]r6r*r7rJrLrS)NN) r^rroz+Union[BinaryVector, list[int], list[float]]r6zOptional[BinaryVectorDtype]r7z Optional[int]rLrS)rLr3rP)rLzTuple[bytes, int]rNrK)rrrr. _type_marker__annotations__BINARY_SUBTYPEr[ classmethodrrrirmr rprpropertyr_rrDrrr> __classcell__)rs@r$rSrSs~@LN &   :    BTB]B]4% 4%!%4%rs# WWW    %"@@F  & & #00  !,, #00 &|4""$$""$$ ""$D!>$$&H""$D$$&H     *BzGUzGr#