o SbR0 @sddlmZmZmZmZmZddlmZ dZ dZ dZ dZ dZ er2ddl m ZddlmZGd d d ZejZ ejZ ejZ ejZ e e fZejejejejejfZejd ejd ejd ejdejdiZdZ dZ dZ GdddeZdS)) TYPE_CHECKINGAnyTupleTypeUnion)UUID)array)mmapc@s(eZdZdZ eZ eZ dZ dZ dS)UuidRepresentationrN) __name__ __module__ __qualname__ UNSPECIFIED UUID_SUBTYPESTANDARDOLD_UUID_SUBTYPE PYTHON_LEGACY JAVA_LEGACY CSHARP_LEGACYrr2/tmp/pip-target-onvjaxws/lib/python/bson/binary.pyrAs   rzUuidRepresentation.UNSPECIFIEDzUuidRepresentation.STANDARDz UuidRepresentation.PYTHON_LEGACYzUuidRepresentation.JAVA_LEGACYz UuidRepresentation.CSHARP_LEGACYrc seZdZUdZdZeed<efdedde e e ddfded dfd d Z e ejfdedd ed ed dfddZejfd ed efddZed efddZd ee efffdd Zded efddZd effdd Zded efddZddZZS)BinaryaRepresentation 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 `_ to use .. versionchanged:: 3.9 Support any bytes-like type that implements the buffer protocol. r_Binary__subtypeclsdata_mmap_arraysubtypereturncCsHt|ts td|dks|dkrtdt|t|}||_|S)Nz"subtype must be an instance of intrz%subtype must be contained in [0, 256)) isinstanceint TypeError ValueErrorbytes__new__ memoryviewtobytesr )r!r"r%selfrrrr-s zBinary.__new__uuiduuid_representationcCst|ts td|tvrtd|tjkrtdt}|tjkr%|j }n-|tj krD|j }|ddddd|ddddd}n|tj krM|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`. :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.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.rN)r(rr*ALL_UUID_REPRESENTATIONSr+rrrrr,rrbytes_ler)r!r1r2r%payload from_uuidrrrr:s*    .  zBinary.from_uuidcCs|jtvr td|jf|tvrtd|tjkrtd|tjkr.|jtkr-t|dSn>|tj krR|jtkrQt|ddddd|dd ddddSn|tj krb|jtkrat|d Sn |jt krlt|dStd |jt |f) aMCreate 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 %s as a uuidr3z)uuid_representation cannot be UNSPECIFIED)r,rr4Nr5r6)r8zcannot decode subtype %s to %s) r%ALL_UUID_SUBTYPESr+r7rrrrrrrrUUID_REPRESENTATION_NAMES)r0r2rrras_uuid#s6       2      zBinary.as_uuidcCs|jS)zSubtype of this binary data.)r r0rrrr%QszBinary.subtypecs0tt|d}t|ts|d}||jfS)Nrzlatin-1)superr__getnewargs__r(r,encoder )r0r" __class__rrr@Vs   zBinary.__getnewargs__othercCs*t|tr|jt|f|jt|fkSdS)NF)r(rr r,r%r0rDrrr__eq__]s z Binary.__eq__cstt|t|jASN)r?r__hash__hashr r>rBrrrHeszBinary.__hash__cCs ||k SrGrrErrr__ne__hs z Binary.__ne__cCsdt||jfS)NzBinary(%s, %s))r,__repr__r r>rrrrKkszBinary.__repr__)rrr__doc__Z _type_markerr)__annotations__BINARY_SUBTYPErrr.r,r- classmethodrrrr:r=propertyr%rr@rboolrFrHrJrK __classcell__rrrBrrsB   7.rN)typingrrrrrr1rrNZFUNCTION_SUBTYPEZOLD_BINARY_SUBTYPErrr r$r r#rrrrrr;rr7r<Z MD5_SUBTYPEZCOLUMN_SUBTYPEZUSER_DEFINED_SUBTYPEr,rrrrrsZ    C