gen_pickles.py 843 B

1234567891011121314151617181920212223242526272829303132
  1. import pickle
  2. from multidict._compat import USE_EXTENSIONS
  3. from multidict._multidict_py import CIMultiDict as PyCIMultiDict # noqa
  4. from multidict._multidict_py import MultiDict as PyMultiDict # noqa
  5. try:
  6. from multidict._multidict import ( # type: ignore # noqa
  7. CIMultiDict,
  8. MultiDict,
  9. )
  10. except ImportError:
  11. pass
  12. def write(name, proto):
  13. cls = globals()[name]
  14. d = cls([("a", 1), ("a", 2)])
  15. with open("{}.pickle.{}".format(name.lower(), proto), "wb") as f:
  16. pickle.dump(d, f, proto)
  17. def generate():
  18. if not USE_EXTENSIONS:
  19. raise RuntimeError("C Extension is required")
  20. for proto in range(pickle.HIGHEST_PROTOCOL + 1):
  21. for name in ("MultiDict", "CIMultiDict", "PyMultiDict", "PyCIMultiDict"):
  22. write(name, proto)
  23. if __name__ == "__main__":
  24. generate()