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