File: object_id.py

package info (click to toggle)
python-mongomock 4.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,024 kB
  • sloc: python: 16,412; makefile: 24
file content (25 lines) | stat: -rw-r--r-- 534 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import uuid


class ObjectId:
    def __init__(self, id=None):
        super().__init__()
        if id is None:
            self._id = uuid.uuid1()
        else:
            self._id = uuid.UUID(id)

    def __eq__(self, other):
        return isinstance(other, ObjectId) and other._id == self._id

    def __ne__(self, other):
        return not self == other

    def __hash__(self):
        return hash(self._id)

    def __repr__(self):
        return f'ObjectId({self._id})'

    def __str__(self):
        return str(self._id)