OpenQuizz
Une application de gestion des contenus pédagogiques
Binary Class Reference
Inheritance diagram for Binary:
Collaboration diagram for Binary:

Public Member Functions

def __new__ (cls, data, subtype=BINARY_SUBTYPE)
 
def from_uuid (cls, uuid, uuid_representation=UuidRepresentation.STANDARD)
 
def as_uuid (self, uuid_representation=UuidRepresentation.STANDARD)
 
def subtype (self)
 
def __getnewargs__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def __repr__ (self)
 

Data Fields

 subtype
 

Detailed Description

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.

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)

◆ __getnewargs__()

def __getnewargs__ (   self)

Reimplemented in UUIDLegacy.

◆ __hash__()

def __hash__ (   self)

◆ __ne__()

def __ne__ (   self,
  other 
)

◆ __new__()

def __new__ (   cls,
  data,
  subtype = BINARY_SUBTYPE 
)

◆ __repr__()

def __repr__ (   self)

Reimplemented in UUIDLegacy.

◆ as_uuid()

def as_uuid (   self,
  uuid_representation = UuidRepresentation.STANDARD 
)
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

◆ from_uuid()

def from_uuid (   cls,
  uuid,
  uuid_representation = UuidRepresentation.STANDARD 
)
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

◆ subtype()

def subtype (   self)
Subtype of this binary data.

Field Documentation

◆ subtype

subtype

The documentation for this class was generated from the following file: