aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/multidict/tests/gen_pickles.py
blob: 028a01f8cc0caf5a4948d74fa901e9d632420dec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pickle

from multidict._compat import USE_EXTENSIONS
from multidict._multidict_py import CIMultiDict as PyCIMultiDict  # noqa
from multidict._multidict_py import MultiDict as PyMultiDict  # noqa

try:
    from multidict._multidict import (  # type: ignore # noqa
        CIMultiDict,
        MultiDict,
    )
except ImportError:
    pass


def write(name, proto):
    cls = globals()[name]
    d = cls([("a", 1), ("a", 2)])
    with open("{}.pickle.{}".format(name.lower(), proto), "wb") as f:
        pickle.dump(d, f, proto)


def generate():
    if not USE_EXTENSIONS:
        raise RuntimeError("C Extension is required")
    for proto in range(pickle.HIGHEST_PROTOCOL + 1):
        for name in ("MultiDict", "CIMultiDict", "PyMultiDict", "PyCIMultiDict"):
            write(name, proto)


if __name__ == "__main__":
    generate()