message.py 898 B

12345678910111213141516171819202122232425262728293031323334
  1. class Record:
  2. """Data record in data stream"""
  3. def __init__(self, value):
  4. self.value = value
  5. self.stream = None
  6. def __repr__(self):
  7. return "Record({})".format(self.value)
  8. def __eq__(self, other):
  9. if type(self) is type(other):
  10. return (self.stream, self.value) == (other.stream, other.value)
  11. return False
  12. def __hash__(self):
  13. return hash((self.stream, self.value))
  14. class KeyRecord(Record):
  15. """Data record in a keyed data stream"""
  16. def __init__(self, key, value):
  17. super().__init__(value)
  18. self.key = key
  19. def __eq__(self, other):
  20. if type(self) is type(other):
  21. return (self.stream, self.key, self.value) ==\
  22. (other.stream, other.key, other.value)
  23. return False
  24. def __hash__(self):
  25. return hash((self.stream, self.key, self.value))