Debian Codegraph @

Modules/_zstd/clinic/zstddict.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(_zstd_ZstdDict_new__doc__,
12 "ZstdDict(dict_content, /, *, is_raw=False)\n"
13 "--\n"
14 "\n"
15 "Represents a Zstandard dictionary.\n"
16 "\n"
17 " dict_content\n"
18 " The content of a Zstandard dictionary as a bytes-like object.\n"
19 " is_raw\n"
20 " If true, perform no checks on *dict_content*, useful for some\n"
21 " advanced cases. Otherwise, check that the content represents\n"
22 " a Zstandard dictionary created by the zstd library or CLI.\n"
23 "\n"
24 "The dictionary can be used for compression or decompression, and can be shared\n"
25 "by multiple ZstdCompressor or ZstdDecompressor objects.");
26
27 static PyObject *
28 _zstd_ZstdDict_new_impl(PyTypeObject *type, Py_buffer *dict_content,
29 int is_raw);
30
31 static PyObject *
32 _zstd_ZstdDict_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
33 {
34 PyObject *return_value = NULL;
35 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
36
37 #define NUM_KEYWORDS 1
38 static struct {
39 PyGC_Head _this_is_not_used;
40 PyObject_VAR_HEAD
41 Py_hash_t ob_hash;
42 PyObject *ob_item[NUM_KEYWORDS];
43 } _kwtuple = {
44 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
45 .ob_hash = -1,
46 .ob_item = { &_Py_ID(is_raw), },
47 };
48 #undef NUM_KEYWORDS
49 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
50
51 #else // !Py_BUILD_CORE
52 # define KWTUPLE NULL
53 #endif // !Py_BUILD_CORE
54
55 static const char * const _keywords[] = {"", "is_raw", NULL};
56 static _PyArg_Parser _parser = {
57 .keywords = _keywords,
58 .fname = "ZstdDict",
59 .kwtuple = KWTUPLE,
60 };
61 #undef KWTUPLE
62 PyObject *argsbuf[2];
63 PyObject * const *fastargs;
64 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
65 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
66 Py_buffer dict_content = {NULL, NULL};
67 int is_raw = 0;
68
69 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
70 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
71 if (!fastargs) {
72 goto exit;
73 }
74 if (PyObject_GetBuffer(fastargs[0], &dict_content, PyBUF_SIMPLE) != 0) {
75 goto exit;
76 }
77 if (!noptargs) {
78 goto skip_optional_kwonly;
79 }
80 is_raw = PyObject_IsTrue(fastargs[1]);
81 if (is_raw < 0) {
82 goto exit;
83 }
84 skip_optional_kwonly:
85 return_value = _zstd_ZstdDict_new_impl(type, &dict_content, is_raw);
86
87 exit:
88 /* Cleanup for dict_content */
89 if (dict_content.obj) {
90 PyBuffer_Release(&dict_content);
91 }
92
93 return return_value;
94 }
95
96 PyDoc_STRVAR(_zstd_ZstdDict_dict_content__doc__,
97 "The content of a Zstandard dictionary, as a bytes object.");
98 #if defined(_zstd_ZstdDict_dict_content_DOCSTR)
99 # undef _zstd_ZstdDict_dict_content_DOCSTR
100 #endif
101 #define _zstd_ZstdDict_dict_content_DOCSTR _zstd_ZstdDict_dict_content__doc__
102
103 #if !defined(_zstd_ZstdDict_dict_content_DOCSTR)
104 # define _zstd_ZstdDict_dict_content_DOCSTR NULL
105 #endif
106 #if defined(_ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF)
107 # undef _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF
108 # define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, (setter)_zstd_ZstdDict_dict_content_set, _zstd_ZstdDict_dict_content_DOCSTR},
109 #else
110 # define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, NULL, _zstd_ZstdDict_dict_content_DOCSTR},
111 #endif
112
113 static PyObject *
114 _zstd_ZstdDict_dict_content_get_impl(ZstdDict *self);
115
116 static PyObject *
117 _zstd_ZstdDict_dict_content_get(PyObject *self, void *Py_UNUSED(context))
118 {
119 return _zstd_ZstdDict_dict_content_get_impl((ZstdDict *)self);
120 }
121
122 PyDoc_STRVAR(_zstd_ZstdDict_as_digested_dict__doc__,
123 "Load as a digested dictionary to compressor.\n"
124 "\n"
125 "Pass this attribute as zstd_dict argument:\n"
126 "compress(dat, zstd_dict=zd.as_digested_dict)\n"
127 "\n"
128 "1. Some advanced compression parameters of compressor may be overridden\n"
129 " by parameters of digested dictionary.\n"
130 "2. ZstdDict has a digested dictionaries cache for each compression level.\n"
131 " It\'s faster when loading again a digested dictionary with the same\n"
132 " compression level.\n"
133 "3. No need to use this for decompression.");
134 #if defined(_zstd_ZstdDict_as_digested_dict_DOCSTR)
135 # undef _zstd_ZstdDict_as_digested_dict_DOCSTR
136 #endif
137 #define _zstd_ZstdDict_as_digested_dict_DOCSTR _zstd_ZstdDict_as_digested_dict__doc__
138
139 #if !defined(_zstd_ZstdDict_as_digested_dict_DOCSTR)
140 # define _zstd_ZstdDict_as_digested_dict_DOCSTR NULL
141 #endif
142 #if defined(_ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF)
143 # undef _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF
144 # define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, (setter)_zstd_ZstdDict_as_digested_dict_set, _zstd_ZstdDict_as_digested_dict_DOCSTR},
145 #else
146 # define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, NULL, _zstd_ZstdDict_as_digested_dict_DOCSTR},
147 #endif
148
149 static PyObject *
150 _zstd_ZstdDict_as_digested_dict_get_impl(ZstdDict *self);
151
152 static PyObject *
153 _zstd_ZstdDict_as_digested_dict_get(PyObject *self, void *Py_UNUSED(context))
154 {
155 return _zstd_ZstdDict_as_digested_dict_get_impl((ZstdDict *)self);
156 }
157
158 PyDoc_STRVAR(_zstd_ZstdDict_as_undigested_dict__doc__,
159 "Load as an undigested dictionary to compressor.\n"
160 "\n"
161 "Pass this attribute as zstd_dict argument:\n"
162 "compress(dat, zstd_dict=zd.as_undigested_dict)\n"
163 "\n"
164 "1. The advanced compression parameters of compressor will not be overridden.\n"
165 "2. Loading an undigested dictionary is costly. If load an undigested dictionary\n"
166 " multiple times, consider reusing a compressor object.\n"
167 "3. No need to use this for decompression.");
168 #if defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
169 # undef _zstd_ZstdDict_as_undigested_dict_DOCSTR
170 #endif
171 #define _zstd_ZstdDict_as_undigested_dict_DOCSTR _zstd_ZstdDict_as_undigested_dict__doc__
172
173 #if !defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
174 # define _zstd_ZstdDict_as_undigested_dict_DOCSTR NULL
175 #endif
176 #if defined(_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF)
177 # undef _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF
178 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, (setter)_zstd_ZstdDict_as_undigested_dict_set, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
179 #else
180 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, NULL, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
181 #endif
182
183 static PyObject *
184 _zstd_ZstdDict_as_undigested_dict_get_impl(ZstdDict *self);
185
186 static PyObject *
187 _zstd_ZstdDict_as_undigested_dict_get(PyObject *self, void *Py_UNUSED(context))
188 {
189 return _zstd_ZstdDict_as_undigested_dict_get_impl((ZstdDict *)self);
190 }
191
192 PyDoc_STRVAR(_zstd_ZstdDict_as_prefix__doc__,
193 "Load as a prefix to compressor/decompressor.\n"
194 "\n"
195 "Pass this attribute as zstd_dict argument:\n"
196 "compress(dat, zstd_dict=zd.as_prefix)\n"
197 "\n"
198 "1. Prefix is compatible with long distance matching, while dictionary is not.\n"
199 "2. It only works for the first frame, then the compressor/decompressor will\n"
200 " return to no prefix state.\n"
201 "3. When decompressing, must use the same prefix as when compressing.");
202 #if defined(_zstd_ZstdDict_as_prefix_DOCSTR)
203 # undef _zstd_ZstdDict_as_prefix_DOCSTR
204 #endif
205 #define _zstd_ZstdDict_as_prefix_DOCSTR _zstd_ZstdDict_as_prefix__doc__
206
207 #if !defined(_zstd_ZstdDict_as_prefix_DOCSTR)
208 # define _zstd_ZstdDict_as_prefix_DOCSTR NULL
209 #endif
210 #if defined(_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF)
211 # undef _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF
212 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, (setter)_zstd_ZstdDict_as_prefix_set, _zstd_ZstdDict_as_prefix_DOCSTR},
213 #else
214 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, NULL, _zstd_ZstdDict_as_prefix_DOCSTR},
215 #endif
216
217 static PyObject *
218 _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self);
219
220 static PyObject *
221 _zstd_ZstdDict_as_prefix_get(PyObject *self, void *Py_UNUSED(context))
222 {
223 return _zstd_ZstdDict_as_prefix_get_impl((ZstdDict *)self);
224 }
225 /*[clinic end generated code: output=f41d9e2e2cc2928f input=a9049054013a1b77]*/