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

Public Member Functions

def __new__ (cls, obj)
 
def __getnewargs__ (self)
 
def uuid (self)
 
def __repr__ (self)
 
- Public Member Functions inherited from Binary
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 __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 

Additional Inherited Members

- Data Fields inherited from Binary
 subtype
 

Detailed Description

**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

Member Function Documentation

◆ __getnewargs__()

def __getnewargs__ (   self)

Reimplemented from Binary.

◆ __new__()

def __new__ (   cls,
  obj 
)

◆ __repr__()

def __repr__ (   self)

Reimplemented from Binary.

◆ uuid()

def uuid (   self)
UUID instance wrapped by this UUIDLegacy instance.

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