Debian Codegraph @

Modules/clinic/_zoneinfo.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_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(zoneinfo_ZoneInfo__doc__,
13 "ZoneInfo(key)\n"
14 "--\n"
15 "\n"
16 "Create a new ZoneInfo instance.");
17
18 static PyObject *
19 zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key);
20
21 static PyObject *
22 zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24 PyObject *return_value = NULL;
25 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
26
27 #define NUM_KEYWORDS 1
28 static struct {
29 PyGC_Head _this_is_not_used;
30 PyObject_VAR_HEAD
31 Py_hash_t ob_hash;
32 PyObject *ob_item[NUM_KEYWORDS];
33 } _kwtuple = {
34 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
35 .ob_hash = -1,
36 .ob_item = { &_Py_ID(key), },
37 };
38 #undef NUM_KEYWORDS
39 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
40
41 #else // !Py_BUILD_CORE
42 # define KWTUPLE NULL
43 #endif // !Py_BUILD_CORE
44
45 static const char * const _keywords[] = {"key", NULL};
46 static _PyArg_Parser _parser = {
47 .keywords = _keywords,
48 .fname = "ZoneInfo",
49 .kwtuple = KWTUPLE,
50 };
51 #undef KWTUPLE
52 PyObject *argsbuf[1];
53 PyObject * const *fastargs;
54 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
55 PyObject *key;
56
57 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
58 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
59 if (!fastargs) {
60 goto exit;
61 }
62 key = fastargs[0];
63 Py_BEGIN_CRITICAL_SECTION(type);
64 return_value = zoneinfo_ZoneInfo_impl(type, key);
65 Py_END_CRITICAL_SECTION();
66
67 exit:
68 return return_value;
69 }
70
71 PyDoc_STRVAR(zoneinfo_ZoneInfo_from_file__doc__,
72 "from_file($type, file_obj, /, key=None)\n"
73 "--\n"
74 "\n"
75 "Create a ZoneInfo file from a file object.");
76
77 #define ZONEINFO_ZONEINFO_FROM_FILE_METHODDEF \
78 {"from_file", _PyCFunction_CAST(zoneinfo_ZoneInfo_from_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_from_file__doc__},
79
80 static PyObject *
81 zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
82 PyObject *file_obj, PyObject *key);
83
84 static PyObject *
85 zoneinfo_ZoneInfo_from_file(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
86 {
87 PyObject *return_value = NULL;
88 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
89
90 #define NUM_KEYWORDS 1
91 static struct {
92 PyGC_Head _this_is_not_used;
93 PyObject_VAR_HEAD
94 Py_hash_t ob_hash;
95 PyObject *ob_item[NUM_KEYWORDS];
96 } _kwtuple = {
97 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
98 .ob_hash = -1,
99 .ob_item = { &_Py_ID(key), },
100 };
101 #undef NUM_KEYWORDS
102 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
103
104 #else // !Py_BUILD_CORE
105 # define KWTUPLE NULL
106 #endif // !Py_BUILD_CORE
107
108 static const char * const _keywords[] = {"", "key", NULL};
109 static _PyArg_Parser _parser = {
110 .keywords = _keywords,
111 .fname = "from_file",
112 .kwtuple = KWTUPLE,
113 };
114 #undef KWTUPLE
115 PyObject *argsbuf[2];
116 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
117 PyObject *file_obj;
118 PyObject *key = Py_None;
119
120 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
121 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
122 if (!args) {
123 goto exit;
124 }
125 file_obj = args[0];
126 if (!noptargs) {
127 goto skip_optional_pos;
128 }
129 key = args[1];
130 skip_optional_pos:
131 return_value = zoneinfo_ZoneInfo_from_file_impl((PyTypeObject *)type, cls, file_obj, key);
132
133 exit:
134 return return_value;
135 }
136
137 PyDoc_STRVAR(zoneinfo_ZoneInfo_no_cache__doc__,
138 "no_cache($type, /, key)\n"
139 "--\n"
140 "\n"
141 "Get a new instance of ZoneInfo, bypassing the cache.");
142
143 #define ZONEINFO_ZONEINFO_NO_CACHE_METHODDEF \
144 {"no_cache", _PyCFunction_CAST(zoneinfo_ZoneInfo_no_cache), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_no_cache__doc__},
145
146 static PyObject *
147 zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type, PyTypeObject *cls,
148 PyObject *key);
149
150 static PyObject *
151 zoneinfo_ZoneInfo_no_cache(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
152 {
153 PyObject *return_value = NULL;
154 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
155
156 #define NUM_KEYWORDS 1
157 static struct {
158 PyGC_Head _this_is_not_used;
159 PyObject_VAR_HEAD
160 Py_hash_t ob_hash;
161 PyObject *ob_item[NUM_KEYWORDS];
162 } _kwtuple = {
163 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
164 .ob_hash = -1,
165 .ob_item = { &_Py_ID(key), },
166 };
167 #undef NUM_KEYWORDS
168 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
169
170 #else // !Py_BUILD_CORE
171 # define KWTUPLE NULL
172 #endif // !Py_BUILD_CORE
173
174 static const char * const _keywords[] = {"key", NULL};
175 static _PyArg_Parser _parser = {
176 .keywords = _keywords,
177 .fname = "no_cache",
178 .kwtuple = KWTUPLE,
179 };
180 #undef KWTUPLE
181 PyObject *argsbuf[1];
182 PyObject *key;
183
184 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
185 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
186 if (!args) {
187 goto exit;
188 }
189 key = args[0];
190 return_value = zoneinfo_ZoneInfo_no_cache_impl((PyTypeObject *)type, cls, key);
191
192 exit:
193 return return_value;
194 }
195
196 PyDoc_STRVAR(zoneinfo_ZoneInfo_clear_cache__doc__,
197 "clear_cache($type, /, *, only_keys=None)\n"
198 "--\n"
199 "\n"
200 "Clear the ZoneInfo cache.");
201
202 #define ZONEINFO_ZONEINFO_CLEAR_CACHE_METHODDEF \
203 {"clear_cache", _PyCFunction_CAST(zoneinfo_ZoneInfo_clear_cache), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_clear_cache__doc__},
204
205 static PyObject *
206 zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type, PyTypeObject *cls,
207 PyObject *only_keys);
208
209 static PyObject *
210 zoneinfo_ZoneInfo_clear_cache(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
211 {
212 PyObject *return_value = NULL;
213 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
214
215 #define NUM_KEYWORDS 1
216 static struct {
217 PyGC_Head _this_is_not_used;
218 PyObject_VAR_HEAD
219 Py_hash_t ob_hash;
220 PyObject *ob_item[NUM_KEYWORDS];
221 } _kwtuple = {
222 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
223 .ob_hash = -1,
224 .ob_item = { &_Py_ID(only_keys), },
225 };
226 #undef NUM_KEYWORDS
227 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
228
229 #else // !Py_BUILD_CORE
230 # define KWTUPLE NULL
231 #endif // !Py_BUILD_CORE
232
233 static const char * const _keywords[] = {"only_keys", NULL};
234 static _PyArg_Parser _parser = {
235 .keywords = _keywords,
236 .fname = "clear_cache",
237 .kwtuple = KWTUPLE,
238 };
239 #undef KWTUPLE
240 PyObject *argsbuf[1];
241 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
242 PyObject *only_keys = Py_None;
243
244 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
245 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
246 if (!args) {
247 goto exit;
248 }
249 if (!noptargs) {
250 goto skip_optional_kwonly;
251 }
252 only_keys = args[0];
253 skip_optional_kwonly:
254 Py_BEGIN_CRITICAL_SECTION(type);
255 return_value = zoneinfo_ZoneInfo_clear_cache_impl((PyTypeObject *)type, cls, only_keys);
256 Py_END_CRITICAL_SECTION();
257
258 exit:
259 return return_value;
260 }
261
262 PyDoc_STRVAR(zoneinfo_ZoneInfo_utcoffset__doc__,
263 "utcoffset($self, dt, /)\n"
264 "--\n"
265 "\n"
266 "Retrieve a timedelta representing the UTC offset in a zone at the given datetime.");
267
268 #define ZONEINFO_ZONEINFO_UTCOFFSET_METHODDEF \
269 {"utcoffset", _PyCFunction_CAST(zoneinfo_ZoneInfo_utcoffset), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_utcoffset__doc__},
270
271 static PyObject *
272 zoneinfo_ZoneInfo_utcoffset_impl(PyObject *self, PyTypeObject *cls,
273 PyObject *dt);
274
275 static PyObject *
276 zoneinfo_ZoneInfo_utcoffset(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
277 {
278 PyObject *return_value = NULL;
279 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
280 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
281 #else
282 # define KWTUPLE NULL
283 #endif
284
285 static const char * const _keywords[] = {"", NULL};
286 static _PyArg_Parser _parser = {
287 .keywords = _keywords,
288 .fname = "utcoffset",
289 .kwtuple = KWTUPLE,
290 };
291 #undef KWTUPLE
292 PyObject *argsbuf[1];
293 PyObject *dt;
294
295 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
296 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
297 if (!args) {
298 goto exit;
299 }
300 dt = args[0];
301 return_value = zoneinfo_ZoneInfo_utcoffset_impl(self, cls, dt);
302
303 exit:
304 return return_value;
305 }
306
307 PyDoc_STRVAR(zoneinfo_ZoneInfo_dst__doc__,
308 "dst($self, dt, /)\n"
309 "--\n"
310 "\n"
311 "Retrieve a timedelta representing the amount of DST applied in a zone at the given datetime.");
312
313 #define ZONEINFO_ZONEINFO_DST_METHODDEF \
314 {"dst", _PyCFunction_CAST(zoneinfo_ZoneInfo_dst), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_dst__doc__},
315
316 static PyObject *
317 zoneinfo_ZoneInfo_dst_impl(PyObject *self, PyTypeObject *cls, PyObject *dt);
318
319 static PyObject *
320 zoneinfo_ZoneInfo_dst(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
321 {
322 PyObject *return_value = NULL;
323 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
324 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
325 #else
326 # define KWTUPLE NULL
327 #endif
328
329 static const char * const _keywords[] = {"", NULL};
330 static _PyArg_Parser _parser = {
331 .keywords = _keywords,
332 .fname = "dst",
333 .kwtuple = KWTUPLE,
334 };
335 #undef KWTUPLE
336 PyObject *argsbuf[1];
337 PyObject *dt;
338
339 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
340 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
341 if (!args) {
342 goto exit;
343 }
344 dt = args[0];
345 return_value = zoneinfo_ZoneInfo_dst_impl(self, cls, dt);
346
347 exit:
348 return return_value;
349 }
350
351 PyDoc_STRVAR(zoneinfo_ZoneInfo_tzname__doc__,
352 "tzname($self, dt, /)\n"
353 "--\n"
354 "\n"
355 "Retrieve a string containing the abbreviation for the time zone that applies in a zone at a given datetime.");
356
357 #define ZONEINFO_ZONEINFO_TZNAME_METHODDEF \
358 {"tzname", _PyCFunction_CAST(zoneinfo_ZoneInfo_tzname), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_tzname__doc__},
359
360 static PyObject *
361 zoneinfo_ZoneInfo_tzname_impl(PyObject *self, PyTypeObject *cls,
362 PyObject *dt);
363
364 static PyObject *
365 zoneinfo_ZoneInfo_tzname(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
366 {
367 PyObject *return_value = NULL;
368 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
369 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
370 #else
371 # define KWTUPLE NULL
372 #endif
373
374 static const char * const _keywords[] = {"", NULL};
375 static _PyArg_Parser _parser = {
376 .keywords = _keywords,
377 .fname = "tzname",
378 .kwtuple = KWTUPLE,
379 };
380 #undef KWTUPLE
381 PyObject *argsbuf[1];
382 PyObject *dt;
383
384 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
385 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
386 if (!args) {
387 goto exit;
388 }
389 dt = args[0];
390 return_value = zoneinfo_ZoneInfo_tzname_impl(self, cls, dt);
391
392 exit:
393 return return_value;
394 }
395
396 PyDoc_STRVAR(zoneinfo_ZoneInfo__unpickle__doc__,
397 "_unpickle($type, key, from_cache, /)\n"
398 "--\n"
399 "\n"
400 "Private method used in unpickling.");
401
402 #define ZONEINFO_ZONEINFO__UNPICKLE_METHODDEF \
403 {"_unpickle", _PyCFunction_CAST(zoneinfo_ZoneInfo__unpickle), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo__unpickle__doc__},
404
405 static PyObject *
406 zoneinfo_ZoneInfo__unpickle_impl(PyTypeObject *type, PyTypeObject *cls,
407 PyObject *key, unsigned char from_cache);
408
409 static PyObject *
410 zoneinfo_ZoneInfo__unpickle(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
411 {
412 PyObject *return_value = NULL;
413 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
414 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
415 #else
416 # define KWTUPLE NULL
417 #endif
418
419 static const char * const _keywords[] = {"", "", NULL};
420 static _PyArg_Parser _parser = {
421 .keywords = _keywords,
422 .fname = "_unpickle",
423 .kwtuple = KWTUPLE,
424 };
425 #undef KWTUPLE
426 PyObject *argsbuf[2];
427 PyObject *key;
428 unsigned char from_cache;
429
430 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
431 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
432 if (!args) {
433 goto exit;
434 }
435 key = args[0];
436 {
437 unsigned long ival = PyLong_AsUnsignedLongMask(args[1]);
438 if (ival == (unsigned long)-1 && PyErr_Occurred()) {
439 goto exit;
440 }
441 else {
442 from_cache = (unsigned char) ival;
443 }
444 }
445 return_value = zoneinfo_ZoneInfo__unpickle_impl((PyTypeObject *)type, cls, key, from_cache);
446
447 exit:
448 return return_value;
449 }
450 /*[clinic end generated code: output=8e9e204f390261b9 input=a9049054013a1b77]*/