_zoneinfo.c.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(zoneinfo_ZoneInfo_from_file__doc__,
  9. "from_file($type, file_obj, /, key=None)\n"
  10. "--\n"
  11. "\n"
  12. "Create a ZoneInfo file from a file object.");
  13. #define ZONEINFO_ZONEINFO_FROM_FILE_METHODDEF \
  14. {"from_file", _PyCFunction_CAST(zoneinfo_ZoneInfo_from_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_from_file__doc__},
  15. static PyObject *
  16. zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
  17. PyObject *file_obj, PyObject *key);
  18. static PyObject *
  19. zoneinfo_ZoneInfo_from_file(PyTypeObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  20. {
  21. PyObject *return_value = NULL;
  22. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  23. #define NUM_KEYWORDS 1
  24. static struct {
  25. PyGC_Head _this_is_not_used;
  26. PyObject_VAR_HEAD
  27. PyObject *ob_item[NUM_KEYWORDS];
  28. } _kwtuple = {
  29. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  30. .ob_item = { &_Py_ID(key), },
  31. };
  32. #undef NUM_KEYWORDS
  33. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  34. #else // !Py_BUILD_CORE
  35. # define KWTUPLE NULL
  36. #endif // !Py_BUILD_CORE
  37. static const char * const _keywords[] = {"", "key", NULL};
  38. static _PyArg_Parser _parser = {
  39. .keywords = _keywords,
  40. .fname = "from_file",
  41. .kwtuple = KWTUPLE,
  42. };
  43. #undef KWTUPLE
  44. PyObject *argsbuf[2];
  45. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  46. PyObject *file_obj;
  47. PyObject *key = Py_None;
  48. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  49. if (!args) {
  50. goto exit;
  51. }
  52. file_obj = args[0];
  53. if (!noptargs) {
  54. goto skip_optional_pos;
  55. }
  56. key = args[1];
  57. skip_optional_pos:
  58. return_value = zoneinfo_ZoneInfo_from_file_impl(type, cls, file_obj, key);
  59. exit:
  60. return return_value;
  61. }
  62. PyDoc_STRVAR(zoneinfo_ZoneInfo_no_cache__doc__,
  63. "no_cache($type, /, key)\n"
  64. "--\n"
  65. "\n"
  66. "Get a new instance of ZoneInfo, bypassing the cache.");
  67. #define ZONEINFO_ZONEINFO_NO_CACHE_METHODDEF \
  68. {"no_cache", _PyCFunction_CAST(zoneinfo_ZoneInfo_no_cache), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_no_cache__doc__},
  69. static PyObject *
  70. zoneinfo_ZoneInfo_no_cache_impl(PyTypeObject *type, PyTypeObject *cls,
  71. PyObject *key);
  72. static PyObject *
  73. zoneinfo_ZoneInfo_no_cache(PyTypeObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  74. {
  75. PyObject *return_value = NULL;
  76. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  77. #define NUM_KEYWORDS 1
  78. static struct {
  79. PyGC_Head _this_is_not_used;
  80. PyObject_VAR_HEAD
  81. PyObject *ob_item[NUM_KEYWORDS];
  82. } _kwtuple = {
  83. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  84. .ob_item = { &_Py_ID(key), },
  85. };
  86. #undef NUM_KEYWORDS
  87. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  88. #else // !Py_BUILD_CORE
  89. # define KWTUPLE NULL
  90. #endif // !Py_BUILD_CORE
  91. static const char * const _keywords[] = {"key", NULL};
  92. static _PyArg_Parser _parser = {
  93. .keywords = _keywords,
  94. .fname = "no_cache",
  95. .kwtuple = KWTUPLE,
  96. };
  97. #undef KWTUPLE
  98. PyObject *argsbuf[1];
  99. PyObject *key;
  100. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  101. if (!args) {
  102. goto exit;
  103. }
  104. key = args[0];
  105. return_value = zoneinfo_ZoneInfo_no_cache_impl(type, cls, key);
  106. exit:
  107. return return_value;
  108. }
  109. PyDoc_STRVAR(zoneinfo_ZoneInfo_clear_cache__doc__,
  110. "clear_cache($type, /, *, only_keys=None)\n"
  111. "--\n"
  112. "\n"
  113. "Clear the ZoneInfo cache.");
  114. #define ZONEINFO_ZONEINFO_CLEAR_CACHE_METHODDEF \
  115. {"clear_cache", _PyCFunction_CAST(zoneinfo_ZoneInfo_clear_cache), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo_clear_cache__doc__},
  116. static PyObject *
  117. zoneinfo_ZoneInfo_clear_cache_impl(PyTypeObject *type, PyTypeObject *cls,
  118. PyObject *only_keys);
  119. static PyObject *
  120. zoneinfo_ZoneInfo_clear_cache(PyTypeObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  121. {
  122. PyObject *return_value = NULL;
  123. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  124. #define NUM_KEYWORDS 1
  125. static struct {
  126. PyGC_Head _this_is_not_used;
  127. PyObject_VAR_HEAD
  128. PyObject *ob_item[NUM_KEYWORDS];
  129. } _kwtuple = {
  130. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  131. .ob_item = { &_Py_ID(only_keys), },
  132. };
  133. #undef NUM_KEYWORDS
  134. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  135. #else // !Py_BUILD_CORE
  136. # define KWTUPLE NULL
  137. #endif // !Py_BUILD_CORE
  138. static const char * const _keywords[] = {"only_keys", NULL};
  139. static _PyArg_Parser _parser = {
  140. .keywords = _keywords,
  141. .fname = "clear_cache",
  142. .kwtuple = KWTUPLE,
  143. };
  144. #undef KWTUPLE
  145. PyObject *argsbuf[1];
  146. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  147. PyObject *only_keys = Py_None;
  148. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  149. if (!args) {
  150. goto exit;
  151. }
  152. if (!noptargs) {
  153. goto skip_optional_kwonly;
  154. }
  155. only_keys = args[0];
  156. skip_optional_kwonly:
  157. return_value = zoneinfo_ZoneInfo_clear_cache_impl(type, cls, only_keys);
  158. exit:
  159. return return_value;
  160. }
  161. PyDoc_STRVAR(zoneinfo_ZoneInfo_utcoffset__doc__,
  162. "utcoffset($self, dt, /)\n"
  163. "--\n"
  164. "\n"
  165. "Retrieve a timedelta representing the UTC offset in a zone at the given datetime.");
  166. #define ZONEINFO_ZONEINFO_UTCOFFSET_METHODDEF \
  167. {"utcoffset", _PyCFunction_CAST(zoneinfo_ZoneInfo_utcoffset), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_utcoffset__doc__},
  168. static PyObject *
  169. zoneinfo_ZoneInfo_utcoffset_impl(PyObject *self, PyTypeObject *cls,
  170. PyObject *dt);
  171. static PyObject *
  172. zoneinfo_ZoneInfo_utcoffset(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  173. {
  174. PyObject *return_value = NULL;
  175. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  176. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  177. #else
  178. # define KWTUPLE NULL
  179. #endif
  180. static const char * const _keywords[] = {"", NULL};
  181. static _PyArg_Parser _parser = {
  182. .keywords = _keywords,
  183. .fname = "utcoffset",
  184. .kwtuple = KWTUPLE,
  185. };
  186. #undef KWTUPLE
  187. PyObject *argsbuf[1];
  188. PyObject *dt;
  189. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  190. if (!args) {
  191. goto exit;
  192. }
  193. dt = args[0];
  194. return_value = zoneinfo_ZoneInfo_utcoffset_impl(self, cls, dt);
  195. exit:
  196. return return_value;
  197. }
  198. PyDoc_STRVAR(zoneinfo_ZoneInfo_dst__doc__,
  199. "dst($self, dt, /)\n"
  200. "--\n"
  201. "\n"
  202. "Retrieve a timedelta representing the amount of DST applied in a zone at the given datetime.");
  203. #define ZONEINFO_ZONEINFO_DST_METHODDEF \
  204. {"dst", _PyCFunction_CAST(zoneinfo_ZoneInfo_dst), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_dst__doc__},
  205. static PyObject *
  206. zoneinfo_ZoneInfo_dst_impl(PyObject *self, PyTypeObject *cls, PyObject *dt);
  207. static PyObject *
  208. zoneinfo_ZoneInfo_dst(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  209. {
  210. PyObject *return_value = NULL;
  211. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  212. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  213. #else
  214. # define KWTUPLE NULL
  215. #endif
  216. static const char * const _keywords[] = {"", NULL};
  217. static _PyArg_Parser _parser = {
  218. .keywords = _keywords,
  219. .fname = "dst",
  220. .kwtuple = KWTUPLE,
  221. };
  222. #undef KWTUPLE
  223. PyObject *argsbuf[1];
  224. PyObject *dt;
  225. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  226. if (!args) {
  227. goto exit;
  228. }
  229. dt = args[0];
  230. return_value = zoneinfo_ZoneInfo_dst_impl(self, cls, dt);
  231. exit:
  232. return return_value;
  233. }
  234. PyDoc_STRVAR(zoneinfo_ZoneInfo_tzname__doc__,
  235. "tzname($self, dt, /)\n"
  236. "--\n"
  237. "\n"
  238. "Retrieve a string containing the abbreviation for the time zone that applies in a zone at a given datetime.");
  239. #define ZONEINFO_ZONEINFO_TZNAME_METHODDEF \
  240. {"tzname", _PyCFunction_CAST(zoneinfo_ZoneInfo_tzname), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, zoneinfo_ZoneInfo_tzname__doc__},
  241. static PyObject *
  242. zoneinfo_ZoneInfo_tzname_impl(PyObject *self, PyTypeObject *cls,
  243. PyObject *dt);
  244. static PyObject *
  245. zoneinfo_ZoneInfo_tzname(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  246. {
  247. PyObject *return_value = NULL;
  248. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  249. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  250. #else
  251. # define KWTUPLE NULL
  252. #endif
  253. static const char * const _keywords[] = {"", NULL};
  254. static _PyArg_Parser _parser = {
  255. .keywords = _keywords,
  256. .fname = "tzname",
  257. .kwtuple = KWTUPLE,
  258. };
  259. #undef KWTUPLE
  260. PyObject *argsbuf[1];
  261. PyObject *dt;
  262. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  263. if (!args) {
  264. goto exit;
  265. }
  266. dt = args[0];
  267. return_value = zoneinfo_ZoneInfo_tzname_impl(self, cls, dt);
  268. exit:
  269. return return_value;
  270. }
  271. PyDoc_STRVAR(zoneinfo_ZoneInfo__unpickle__doc__,
  272. "_unpickle($type, key, from_cache, /)\n"
  273. "--\n"
  274. "\n"
  275. "Private method used in unpickling.");
  276. #define ZONEINFO_ZONEINFO__UNPICKLE_METHODDEF \
  277. {"_unpickle", _PyCFunction_CAST(zoneinfo_ZoneInfo__unpickle), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, zoneinfo_ZoneInfo__unpickle__doc__},
  278. static PyObject *
  279. zoneinfo_ZoneInfo__unpickle_impl(PyTypeObject *type, PyTypeObject *cls,
  280. PyObject *key, unsigned char from_cache);
  281. static PyObject *
  282. zoneinfo_ZoneInfo__unpickle(PyTypeObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  283. {
  284. PyObject *return_value = NULL;
  285. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  286. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  287. #else
  288. # define KWTUPLE NULL
  289. #endif
  290. static const char * const _keywords[] = {"", "", NULL};
  291. static _PyArg_Parser _parser = {
  292. .keywords = _keywords,
  293. .fname = "_unpickle",
  294. .kwtuple = KWTUPLE,
  295. };
  296. #undef KWTUPLE
  297. PyObject *argsbuf[2];
  298. PyObject *key;
  299. unsigned char from_cache;
  300. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  301. if (!args) {
  302. goto exit;
  303. }
  304. key = args[0];
  305. {
  306. unsigned long ival = PyLong_AsUnsignedLongMask(args[1]);
  307. if (ival == (unsigned long)-1 && PyErr_Occurred()) {
  308. goto exit;
  309. }
  310. else {
  311. from_cache = (unsigned char) ival;
  312. }
  313. }
  314. return_value = zoneinfo_ZoneInfo__unpickle_impl(type, cls, key, from_cache);
  315. exit:
  316. return return_value;
  317. }
  318. /*[clinic end generated code: output=54051388dfc408af input=a9049054013a1b77]*/