|
12 | 12 |
|
13 | 13 | #include "datetime.h"
|
14 | 14 |
|
| 15 | +#include "clinic/_zoneinfo.c.h" |
| 16 | +/*[clinic input] |
| 17 | +module zoneinfo |
| 18 | +class zoneinfo.ZoneInfo "PyObject *" "PyTypeObject *" |
| 19 | +[clinic start generated code]*/ |
| 20 | +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d12c73c0eef36df8]*/ |
| 21 | + |
15 | 22 | // Imports
|
16 | 23 | static PyObject *io_open = NULL;
|
17 | 24 | static PyObject *_tzpath_find_tzfile = NULL;
|
@@ -338,20 +345,25 @@ zoneinfo_dealloc(PyObject *obj_self)
|
338 | 345 | Py_TYPE(self)->tp_free((PyObject *)self);
|
339 | 346 | }
|
340 | 347 |
|
| 348 | +/*[clinic input] |
| 349 | +@classmethod |
| 350 | +zoneinfo.ZoneInfo.from_file |
| 351 | +
|
| 352 | + file_obj: object |
| 353 | + / |
| 354 | + key: object = None |
| 355 | +
|
| 356 | +Create a ZoneInfo file from a file object. |
| 357 | +[clinic start generated code]*/ |
| 358 | + |
341 | 359 | static PyObject *
|
342 |
| -zoneinfo_from_file(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 360 | +zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyObject *file_obj, |
| 361 | + PyObject *key) |
| 362 | +/*[clinic end generated code: output=68ed2022404ae5be input=ccfe73708133d2e4]*/ |
343 | 363 | {
|
344 |
| - PyObject *file_obj = NULL; |
345 | 364 | PyObject *file_repr = NULL;
|
346 |
| - PyObject *key = Py_None; |
347 | 365 | PyZoneInfo_ZoneInfo *self = NULL;
|
348 | 366 |
|
349 |
| - static char *kwlist[] = {"", "key", NULL}; |
350 |
| - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &file_obj, |
351 |
| - &key)) { |
352 |
| - return NULL; |
353 |
| - } |
354 |
| - |
355 | 367 | PyObject *obj_self = (PyObject *)(type->tp_alloc(type, 0));
|
356 | 368 | self = (PyZoneInfo_ZoneInfo *)obj_self;
|
357 | 369 | if (self == NULL) {
|
@@ -379,35 +391,41 @@ zoneinfo_from_file(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
379 | 391 | return NULL;
|
380 | 392 | }
|
381 | 393 |
|
| 394 | +/*[clinic input] |
| 395 | +@classmethod |
| 396 | +zoneinfo.ZoneInfo.no_cache |
| 397 | +
|
| 398 | + key: object |
| 399 | +
|
| 400 | +Get a new instance of ZoneInfo, bypassing the cache. |
| 401 | +[clinic start generated code]*/ |
| 402 | + |
382 | 403 | static PyObject *
|
383 |
| -zoneinfo_no_cache(PyTypeObject *cls, PyObject *args, PyObject *kwargs) |
| 404 | +zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type, PyObject *key) |
| 405 | +/*[clinic end generated code: output=751c6894ad66f91b input=bb24afd84a80ba46]*/ |
384 | 406 | {
|
385 |
| - static char *kwlist[] = {"key", NULL};
|
386 |
| - PyObject *key = NULL; |
387 |
| - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &key)) { |
388 |
| - return NULL; |
389 |
| - } |
390 |
| - |
391 |
| - PyObject *out = zoneinfo_new_instance(cls, key); |
| 407 | + PyObject *out = zoneinfo_new_instance(type, key); |
392 | 408 | if (out != NULL) {
|
393 | 409 | ((PyZoneInfo_ZoneInfo *)out)->source = SOURCE_NOCACHE;
|
394 | 410 | }
|
395 | 411 |
|
396 | 412 | return out;
|
397 | 413 | }
|
398 | 414 |
|
399 |
| -static PyObject * |
400 |
| -zoneinfo_clear_cache(PyObject *cls, PyObject *args, PyObject *kwargs) |
401 |
| -{ |
402 |
| - PyObject *only_keys = NULL; |
403 |
| - static char *kwlist[] = {"only_keys", NULL}; |
| 415 | +/*[clinic input] |
| 416 | +@classmethod |
| 417 | +zoneinfo.ZoneInfo.clear_cache |
404 | 418 |
|
405 |
| - if (!(PyArg_ParseTupleAndKeywords(args, kwargs, "|$O", kwlist, |
406 |
| - &only_keys))) { |
407 |
| - return NULL; |
408 |
| - } |
| 419 | + * |
| 420 | + only_keys: object = None |
409 | 421 |
|
410 |
| - PyTypeObject *type = (PyTypeObject *)cls; |
| 422 | +Clear the ZoneInfo cache. |
| 423 | +[clinic start generated code]*/ |
| 424 | + |
| 425 | +static PyObject * |
| 426 | +zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type, PyObject *only_keys) |
| 427 | +/*[clinic end generated code: output=eec0a3276f07bd90 input=8cff0182a95f295b]*/ |
| 428 | +{ |
411 | 429 | PyObject *weak_cache = get_weak_cache(type);
|
412 | 430 |
|
413 | 431 | if (only_keys == NULL || only_keys == Py_None) {
|
@@ -2545,15 +2563,9 @@ zoneinfo_init_subclass(PyTypeObject *cls, PyObject *args, PyObject **kwargs)
|
2545 | 2563 | /////
|
2546 | 2564 | // Specify the ZoneInfo type
|
2547 | 2565 | static PyMethodDef zoneinfo_methods[] = {
|
2548 |
| - {"clear_cache", (PyCFunction)(void (*)(void))zoneinfo_clear_cache, |
2549 |
| - METH_VARARGS | METH_KEYWORDS | METH_CLASS, |
2550 |
| - PyDoc_STR("Clear the ZoneInfo cache.")}, |
2551 |
| - {"no_cache", (PyCFunction)(void (*)(void))zoneinfo_no_cache, |
2552 |
| - METH_VARARGS | METH_KEYWORDS | METH_CLASS, |
2553 |
| - PyDoc_STR("Get a new instance of ZoneInfo, bypassing the cache.")}, |
2554 |
| - {"from_file", (PyCFunction)(void (*)(void))zoneinfo_from_file, |
2555 |
| - METH_VARARGS | METH_KEYWORDS | METH_CLASS, |
2556 |
| - PyDoc_STR("Create a ZoneInfo file from a file object.")}, |
| 2566 | + ZONEINFO_ZONEINFO_CLEAR_CACHE_METHODDEF |
| 2567 | + ZONEINFO_ZONEINFO_NO_CACHE_METHODDEF |
| 2568 | + ZONEINFO_ZONEINFO_FROM_FILE_METHODDEF |
2557 | 2569 | {"utcoffset", (PyCFunction)zoneinfo_utcoffset, METH_O,
|
2558 | 2570 | PyDoc_STR("Retrieve a timedelta representing the UTC offset in a zone at "
|
2559 | 2571 | "the given datetime.")},
|
|
0 commit comments