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\n"
25 "shared 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\n"
129 " overridden by parameters of digested dictionary.\n"
130 "2. ZstdDict has a digested dictionaries cache for each compression\n"
131 " level. It\'s faster when loading again a digested dictionary with\n"
132 " the same 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\n"
165 " overridden.\n"
166 "2. Loading an undigested dictionary is costly. If load an undigested\n"
167 " dictionary multiple times, consider reusing a compressor object.\n"
168 "3. No need to use this for decompression.");
169 #if defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
170 # undef _zstd_ZstdDict_as_undigested_dict_DOCSTR
171 #endif
172 #define _zstd_ZstdDict_as_undigested_dict_DOCSTR _zstd_ZstdDict_as_undigested_dict__doc__
173
174 #if !defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
175 # define _zstd_ZstdDict_as_undigested_dict_DOCSTR NULL
176 #endif
177 #if defined(_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF)
178 # undef _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF
179 # 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},
180 #else
181 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, NULL, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
182 #endif
183
184 static PyObject *
185 _zstd_ZstdDict_as_undigested_dict_get_impl(ZstdDict *self);
186
187 static PyObject *
188 _zstd_ZstdDict_as_undigested_dict_get(PyObject *self, void *Py_UNUSED(context))
189 {
190 return _zstd_ZstdDict_as_undigested_dict_get_impl((ZstdDict *)self);
191 }
192
193 PyDoc_STRVAR(_zstd_ZstdDict_as_prefix__doc__,
194 "Load as a prefix to compressor/decompressor.\n"
195 "\n"
196 "Pass this attribute as zstd_dict argument:\n"
197 "compress(dat, zstd_dict=zd.as_prefix)\n"
198 "\n"
199 "1. Prefix is compatible with long distance matching, while\n"
200 " dictionary is not.\n"
201 "2. It only works for the first frame, then the\n"
202 " compressor/decompressor will return to no prefix state.\n"
203 "3. When decompressing, must use the same prefix as when compressing.");
204 #if defined(_zstd_ZstdDict_as_prefix_DOCSTR)
205 # undef _zstd_ZstdDict_as_prefix_DOCSTR
206 #endif
207 #define _zstd_ZstdDict_as_prefix_DOCSTR _zstd_ZstdDict_as_prefix__doc__
208
209 #if !defined(_zstd_ZstdDict_as_prefix_DOCSTR)
210 # define _zstd_ZstdDict_as_prefix_DOCSTR NULL
211 #endif
212 #if defined(_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF)
213 # undef _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF
214 # 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},
215 #else
216 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, NULL, _zstd_ZstdDict_as_prefix_DOCSTR},
217 #endif
218
219 static PyObject *
220 _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self);
221
222 static PyObject *
223 _zstd_ZstdDict_as_prefix_get(PyObject *self, void *Py_UNUSED(context))
224 {
225 return _zstd_ZstdDict_as_prefix_get_impl((ZstdDict *)self);
226 }
227 /*[clinic end generated code: output=49b66061b4fcdb5f input=a9049054013a1b77]*/