@@ 56-93 (lines=38) @@ | ||
53 | return to_container(load_fn(content_or_strm, **opts)) |
|
54 | ||
55 | ||
56 | class Parser(anyconfig.backend.base.FromStreamLoader, |
|
57 | anyconfig.backend.base.ToStreamDumper): |
|
58 | """ |
|
59 | Parser for Pickle files. |
|
60 | """ |
|
61 | _type = "pickle" |
|
62 | _extensions = ["pkl", "pickle"] |
|
63 | _load_opts = LOAD_OPTS |
|
64 | _dump_opts = DUMP_OPTS |
|
65 | _open_flags = ('rb', 'wb') |
|
66 | ||
67 | dump_to_string = anyconfig.backend.base.to_method(pickle.dumps) |
|
68 | dump_to_stream = anyconfig.backend.base.to_method(pickle.dump) |
|
69 | _load = anyconfig.backend.base.to_method(load_with_fn) |
|
70 | ||
71 | def load_from_string(self, content, to_container, **opts): |
|
72 | """ |
|
73 | Load Pickle config from given string `content`. |
|
74 | ||
75 | :param content: Pickled config content |
|
76 | :param to_container: callble to make a container object |
|
77 | :param opts: keyword options passed to `pickle.loads` |
|
78 | ||
79 | :return: Dict-like object holding configuration |
|
80 | """ |
|
81 | return self._load(pickle.loads, content, to_container, **opts) |
|
82 | ||
83 | def load_from_stream(self, stream, to_container, **opts): |
|
84 | """ |
|
85 | Load Pickle config from given stream `stream`. |
|
86 | ||
87 | :param stream: Stream will provide Pickled config content string |
|
88 | :param to_container: callble to make a container object |
|
89 | :param opts: keyword options passed to `pickle.load` |
|
90 | ||
91 | :return: Dict-like object holding configuration |
|
92 | """ |
|
93 | return self._load(pickle.load, stream, to_container, **opts) |
|
94 | ||
95 | # vim:sw=4:ts=4:et: |
|
96 |
@@ 30-67 (lines=38) @@ | ||
27 | from anyconfig.backend.pickle import load_with_fn |
|
28 | ||
29 | ||
30 | class Parser(anyconfig.backend.base.FromStreamLoader, |
|
31 | anyconfig.backend.base.ToStreamDumper): |
|
32 | """ |
|
33 | Parser for CBOR files. |
|
34 | """ |
|
35 | _type = "cbor" |
|
36 | _extensions = ["cbor"] |
|
37 | _load_opts = [] |
|
38 | _dump_opts = ["sort_keys"] |
|
39 | _open_flags = ('rb', 'wb') |
|
40 | ||
41 | dump_to_string = anyconfig.backend.base.to_method(cbor.dumps) |
|
42 | dump_to_stream = anyconfig.backend.base.to_method(cbor.dump) |
|
43 | _load = anyconfig.backend.base.to_method(load_with_fn) |
|
44 | ||
45 | def load_from_string(self, content, to_container, **opts): |
|
46 | """ |
|
47 | Load CBOR config from given string `content`. |
|
48 | ||
49 | :param content: CBOR config content |
|
50 | :param to_container: callble to make a container object |
|
51 | :param opts: keyword options passed to `cbor.loads` |
|
52 | ||
53 | :return: Dict-like object holding configuration |
|
54 | """ |
|
55 | return self._load(cbor.loads, content, to_container, **opts) |
|
56 | ||
57 | def load_from_stream(self, stream, to_container, **opts): |
|
58 | """ |
|
59 | Load CBOR config from given stream `stream`. |
|
60 | ||
61 | :param stream: Stream will provide CBOR config content string |
|
62 | :param to_container: callble to make a container object |
|
63 | :param opts: keyword options passed to `cbor.load` |
|
64 | ||
65 | :return: Dict-like object holding configuration |
|
66 | """ |
|
67 | return self._load(cbor.load, stream, to_container, **opts) |
|
68 | ||
69 | # vim:sw=4:ts=4:et: |
|
70 |