object_id.py 567 B

12345678910111213141516171819202122232425
  1. import uuid
  2. class ObjectId(object):
  3. def __init__(self, id=None):
  4. super(ObjectId, self).__init__()
  5. if id is None:
  6. self._id = uuid.uuid1()
  7. else:
  8. self._id = uuid.UUID(id)
  9. def __eq__(self, other):
  10. return isinstance(other, ObjectId) and other._id == self._id
  11. def __ne__(self, other):
  12. return not (self == other)
  13. def __hash__(self):
  14. return hash(self._id)
  15. def __repr__(self):
  16. return 'ObjectId({0})'.format(self._id)
  17. def __str__(self):
  18. return str(self._id)