You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 1021B

123456789101112131415161718192021222324252627282930
  1. import datetime
  2. from .utils import format_rfc3339
  3. try:
  4. _string_types = (str, unicode)
  5. _int_types = (int, long)
  6. except NameError:
  7. _string_types = str
  8. _int_types = int
  9. def translate_to_test(v):
  10. if isinstance(v, dict):
  11. return { k: translate_to_test(v) for k, v in v.items() }
  12. if isinstance(v, list):
  13. a = [translate_to_test(x) for x in v]
  14. if v and isinstance(v[0], dict):
  15. return a
  16. else:
  17. return {'type': 'array', 'value': a}
  18. if isinstance(v, datetime.datetime):
  19. return {'type': 'datetime', 'value': format_rfc3339(v)}
  20. if isinstance(v, bool):
  21. return {'type': 'bool', 'value': 'true' if v else 'false'}
  22. if isinstance(v, _int_types):
  23. return {'type': 'integer', 'value': str(v)}
  24. if isinstance(v, float):
  25. return {'type': 'float', 'value': '{:.17}'.format(v)}
  26. if isinstance(v, _string_types):
  27. return {'type': 'string', 'value': v}
  28. raise RuntimeError('unexpected value: {!r}'.format(v))