JSONEncoder.py 556 B

12345678910111213141516171819202122
  1. from typing import Any
  2. from flask.json import JSONEncoder as Base
  3. from pycs.database.util.JSONEncoder import JSONEncoder as Database
  4. from pycs.jobs.util.JSONEncoder import JSONEncoder as Jobs
  5. class JSONEncoder(Base):
  6. """
  7. prepares job objects to be json encoded
  8. """
  9. def default(self, o: Any) -> Any:
  10. module = o.__class__.__module__
  11. if module.startswith('pycs.database'):
  12. return Database().default(o)
  13. if module.startswith('pycs.jobs'):
  14. return Jobs().default(o)
  15. return o.__dict__