bases.py 777 B

12345678910111213141516171819202122232425262728
  1. # bases.py/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
  2. # This copyright was auto-generated on Mon Jul 31 17:04:07 UTC 2023
  3. """Base classes shared throughout models"""
  4. import json
  5. from pydantic import BaseModel
  6. from open_gopro.util import pretty_print, scrub
  7. class CustomBaseModel(BaseModel):
  8. """Additional functionality added to Pydantic BaseModel"""
  9. def __hash__(self) -> int:
  10. h = hash((type(self),))
  11. for v in self.__dict__.values():
  12. if isinstance(v, (dict, list)):
  13. h += hash(json.dumps(v))
  14. else:
  15. h += hash(v)
  16. return h
  17. def __str__(self) -> str:
  18. d = dict(self)
  19. scrub(d, bad_values=[None])
  20. return pretty_print(d)