/src/cpython/Modules/clinic/_datetimemodule.c.h
Line | Count | Source |
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 | | #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() |
11 | | |
12 | | PyDoc_STRVAR(delta_new__doc__, |
13 | | "timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0,\n" |
14 | | " hours=0, weeks=0)\n" |
15 | | "--\n" |
16 | | "\n" |
17 | | "Difference between two datetime values.\n" |
18 | | "\n" |
19 | | "All arguments are optional and default to 0.\n" |
20 | | "Arguments may be integers or floats, and may be positive or negative."); |
21 | | |
22 | | static PyObject * |
23 | | delta_new_impl(PyTypeObject *type, PyObject *days, PyObject *seconds, |
24 | | PyObject *microseconds, PyObject *milliseconds, |
25 | | PyObject *minutes, PyObject *hours, PyObject *weeks); |
26 | | |
27 | | static PyObject * |
28 | | delta_new_helper(PyTypeObject *type, PyObject *const *args, |
29 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
30 | 827 | { |
31 | 827 | PyObject *return_value = NULL; |
32 | 827 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
33 | | |
34 | 827 | #define NUM_KEYWORDS 7 |
35 | 827 | static struct { |
36 | 827 | PyGC_Head _this_is_not_used; |
37 | 827 | PyObject_VAR_HEAD |
38 | 827 | Py_hash_t ob_hash; |
39 | 827 | PyObject *ob_item[NUM_KEYWORDS]; |
40 | 827 | } _kwtuple = { |
41 | 827 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
42 | 827 | .ob_hash = -1, |
43 | 827 | .ob_item = { &_Py_ID(days), &_Py_ID(seconds), &_Py_ID(microseconds), &_Py_ID(milliseconds), &_Py_ID(minutes), &_Py_ID(hours), &_Py_ID(weeks), }, |
44 | 827 | }; |
45 | 827 | #undef NUM_KEYWORDS |
46 | 827 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
47 | | |
48 | | #else // !Py_BUILD_CORE |
49 | | # define KWTUPLE NULL |
50 | | #endif // !Py_BUILD_CORE |
51 | | |
52 | 827 | static const char * const _keywords[] = {"days", "seconds", "microseconds", "milliseconds", "minutes", "hours", "weeks", NULL}; |
53 | 827 | static _PyArg_Parser _parser = { |
54 | 827 | .keywords = _keywords, |
55 | 827 | .fname = "timedelta", |
56 | 827 | .kwtuple = KWTUPLE, |
57 | 827 | }; |
58 | 827 | #undef KWTUPLE |
59 | 827 | PyObject *argsbuf[7]; |
60 | 827 | PyObject * const *fastargs; |
61 | 827 | Py_ssize_t noptargs = nargs + nkw - 0; |
62 | 827 | PyObject *days = NULL; |
63 | 827 | PyObject *seconds = NULL; |
64 | 827 | PyObject *microseconds = NULL; |
65 | 827 | PyObject *milliseconds = NULL; |
66 | 827 | PyObject *minutes = NULL; |
67 | 827 | PyObject *hours = NULL; |
68 | 827 | PyObject *weeks = NULL; |
69 | | |
70 | 827 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
71 | 827 | /*minpos*/ 0, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
72 | 827 | if (!fastargs) { |
73 | 0 | goto exit; |
74 | 0 | } |
75 | 827 | if (!noptargs) { |
76 | 0 | goto skip_optional_pos; |
77 | 0 | } |
78 | 827 | if (fastargs[0]) { |
79 | 16 | days = fastargs[0]; |
80 | 16 | if (!--noptargs) { |
81 | 16 | goto skip_optional_pos; |
82 | 16 | } |
83 | 16 | } |
84 | 811 | if (fastargs[1]) { |
85 | 674 | seconds = fastargs[1]; |
86 | 674 | if (!--noptargs) { |
87 | 670 | goto skip_optional_pos; |
88 | 670 | } |
89 | 674 | } |
90 | 141 | if (fastargs[2]) { |
91 | 12 | microseconds = fastargs[2]; |
92 | 12 | if (!--noptargs) { |
93 | 8 | goto skip_optional_pos; |
94 | 8 | } |
95 | 12 | } |
96 | 133 | if (fastargs[3]) { |
97 | 4 | milliseconds = fastargs[3]; |
98 | 4 | if (!--noptargs) { |
99 | 4 | goto skip_optional_pos; |
100 | 4 | } |
101 | 4 | } |
102 | 129 | if (fastargs[4]) { |
103 | 125 | minutes = fastargs[4]; |
104 | 125 | if (!--noptargs) { |
105 | 0 | goto skip_optional_pos; |
106 | 0 | } |
107 | 125 | } |
108 | 129 | if (fastargs[5]) { |
109 | 129 | hours = fastargs[5]; |
110 | 129 | if (!--noptargs) { |
111 | 129 | goto skip_optional_pos; |
112 | 129 | } |
113 | 129 | } |
114 | 0 | weeks = fastargs[6]; |
115 | 827 | skip_optional_pos: |
116 | 827 | return_value = delta_new_impl(type, days, seconds, microseconds, milliseconds, minutes, hours, weeks); |
117 | | |
118 | 827 | exit: |
119 | 827 | return return_value; |
120 | 827 | } |
121 | | |
122 | | static PyObject * |
123 | | delta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
124 | 8 | { |
125 | 8 | return delta_new_helper(type, _PyTuple_CAST(args)->ob_item, |
126 | 8 | PyTuple_GET_SIZE(args), |
127 | 8 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
128 | 8 | kwargs, NULL); |
129 | 8 | } |
130 | | |
131 | | static PyObject * |
132 | | delta_vectorcall(PyObject *type, PyObject *const *args, |
133 | | size_t nargsf, PyObject *kwnames) |
134 | 823 | { |
135 | 823 | PyObject *return_value = NULL; |
136 | 823 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
137 | 823 | PyObject *days = NULL; |
138 | 823 | PyObject *seconds = NULL; |
139 | 823 | PyObject *microseconds = NULL; |
140 | 823 | PyObject *milliseconds = NULL; |
141 | 823 | PyObject *minutes = NULL; |
142 | 823 | PyObject *hours = NULL; |
143 | 823 | PyObject *weeks = NULL; |
144 | | |
145 | 823 | assert(_PyType_CAST(type)->tp_new == delta_new); |
146 | | /* Make sure the type object is immutable: the generated |
147 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
148 | 823 | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
149 | 823 | if (kwnames != NULL || nargs > 7) { |
150 | 819 | return delta_new_helper(_PyType_CAST(type), args, nargs, |
151 | 819 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
152 | 819 | NULL, kwnames); |
153 | 819 | } |
154 | 4 | if (nargs < 1) { |
155 | 0 | goto skip_optional; |
156 | 0 | } |
157 | 4 | days = args[0]; |
158 | 4 | if (nargs < 2) { |
159 | 4 | goto skip_optional; |
160 | 4 | } |
161 | 0 | seconds = args[1]; |
162 | 0 | if (nargs < 3) { |
163 | 0 | goto skip_optional; |
164 | 0 | } |
165 | 0 | microseconds = args[2]; |
166 | 0 | if (nargs < 4) { |
167 | 0 | goto skip_optional; |
168 | 0 | } |
169 | 0 | milliseconds = args[3]; |
170 | 0 | if (nargs < 5) { |
171 | 0 | goto skip_optional; |
172 | 0 | } |
173 | 0 | minutes = args[4]; |
174 | 0 | if (nargs < 6) { |
175 | 0 | goto skip_optional; |
176 | 0 | } |
177 | 0 | hours = args[5]; |
178 | 0 | if (nargs < 7) { |
179 | 0 | goto skip_optional; |
180 | 0 | } |
181 | 0 | weeks = args[6]; |
182 | 4 | skip_optional: |
183 | 4 | return_value = delta_new_impl(_PyType_CAST(type), days, seconds, microseconds, milliseconds, minutes, hours, weeks); |
184 | | |
185 | 4 | return return_value; |
186 | 0 | } |
187 | | |
188 | | PyDoc_STRVAR(datetime_date__doc__, |
189 | | "date(year, month, day)\n" |
190 | | "--\n" |
191 | | "\n" |
192 | | "Concrete date type."); |
193 | | |
194 | | static PyObject * |
195 | | datetime_date_impl(PyTypeObject *type, int year, int month, int day); |
196 | | |
197 | | static PyObject * |
198 | | datetime_date(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
199 | 21.7k | { |
200 | 21.7k | PyObject *return_value = NULL; |
201 | 21.7k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
202 | | |
203 | 21.7k | #define NUM_KEYWORDS 3 |
204 | 21.7k | static struct { |
205 | 21.7k | PyGC_Head _this_is_not_used; |
206 | 21.7k | PyObject_VAR_HEAD |
207 | 21.7k | Py_hash_t ob_hash; |
208 | 21.7k | PyObject *ob_item[NUM_KEYWORDS]; |
209 | 21.7k | } _kwtuple = { |
210 | 21.7k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
211 | 21.7k | .ob_hash = -1, |
212 | 21.7k | .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), }, |
213 | 21.7k | }; |
214 | 21.7k | #undef NUM_KEYWORDS |
215 | 21.7k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
216 | | |
217 | | #else // !Py_BUILD_CORE |
218 | | # define KWTUPLE NULL |
219 | | #endif // !Py_BUILD_CORE |
220 | | |
221 | 21.7k | static const char * const _keywords[] = {"year", "month", "day", NULL}; |
222 | 21.7k | static _PyArg_Parser _parser = { |
223 | 21.7k | .keywords = _keywords, |
224 | 21.7k | .fname = "date", |
225 | 21.7k | .kwtuple = KWTUPLE, |
226 | 21.7k | }; |
227 | 21.7k | #undef KWTUPLE |
228 | 21.7k | PyObject *argsbuf[3]; |
229 | 21.7k | PyObject * const *fastargs; |
230 | 21.7k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
231 | 21.7k | int year; |
232 | 21.7k | int month; |
233 | 21.7k | int day; |
234 | | |
235 | 21.7k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
236 | 21.7k | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
237 | 21.7k | if (!fastargs) { |
238 | 0 | goto exit; |
239 | 0 | } |
240 | 21.7k | year = PyLong_AsInt(fastargs[0]); |
241 | 21.7k | if (year == -1 && PyErr_Occurred()) { |
242 | 0 | goto exit; |
243 | 0 | } |
244 | 21.7k | month = PyLong_AsInt(fastargs[1]); |
245 | 21.7k | if (month == -1 && PyErr_Occurred()) { |
246 | 0 | goto exit; |
247 | 0 | } |
248 | 21.7k | day = PyLong_AsInt(fastargs[2]); |
249 | 21.7k | if (day == -1 && PyErr_Occurred()) { |
250 | 0 | goto exit; |
251 | 0 | } |
252 | 21.7k | return_value = datetime_date_impl(type, year, month, day); |
253 | | |
254 | 21.7k | exit: |
255 | 21.7k | return return_value; |
256 | 21.7k | } |
257 | | |
258 | | PyDoc_STRVAR(datetime_date_today__doc__, |
259 | | "today($type, /)\n" |
260 | | "--\n" |
261 | | "\n" |
262 | | "Current date or datetime.\n" |
263 | | "\n" |
264 | | "Equivalent to fromtimestamp(time.time())."); |
265 | | |
266 | | #define DATETIME_DATE_TODAY_METHODDEF \ |
267 | | {"today", (PyCFunction)datetime_date_today, METH_NOARGS|METH_CLASS, datetime_date_today__doc__}, |
268 | | |
269 | | static PyObject * |
270 | | datetime_date_today_impl(PyTypeObject *type); |
271 | | |
272 | | static PyObject * |
273 | | datetime_date_today(PyObject *type, PyObject *Py_UNUSED(ignored)) |
274 | 0 | { |
275 | 0 | return datetime_date_today_impl((PyTypeObject *)type); |
276 | 0 | } |
277 | | |
278 | | PyDoc_STRVAR(datetime_date_fromtimestamp__doc__, |
279 | | "fromtimestamp($type, timestamp, /)\n" |
280 | | "--\n" |
281 | | "\n" |
282 | | "Create a date from a POSIX timestamp.\n" |
283 | | "\n" |
284 | | "The timestamp is a number, e.g. created via time.time(), that is\n" |
285 | | "interpreted as local time."); |
286 | | |
287 | | #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \ |
288 | | {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__}, |
289 | | |
290 | | static PyObject * |
291 | | datetime_date_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp); |
292 | | |
293 | | static PyObject * |
294 | | datetime_date_fromtimestamp(PyObject *type, PyObject *timestamp) |
295 | 0 | { |
296 | 0 | PyObject *return_value = NULL; |
297 | |
|
298 | 0 | return_value = datetime_date_fromtimestamp_impl((PyTypeObject *)type, timestamp); |
299 | |
|
300 | 0 | return return_value; |
301 | 0 | } |
302 | | |
303 | | PyDoc_STRVAR(datetime_date_fromordinal__doc__, |
304 | | "fromordinal($type, ordinal, /)\n" |
305 | | "--\n" |
306 | | "\n" |
307 | | "Construct a date from a proleptic Gregorian ordinal.\n" |
308 | | "\n" |
309 | | "January 1 of year 1 is day 1. Only the year, month and day are\n" |
310 | | "non-zero in the result."); |
311 | | |
312 | | #define DATETIME_DATE_FROMORDINAL_METHODDEF \ |
313 | | {"fromordinal", (PyCFunction)datetime_date_fromordinal, METH_O|METH_CLASS, datetime_date_fromordinal__doc__}, |
314 | | |
315 | | static PyObject * |
316 | | datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal); |
317 | | |
318 | | static PyObject * |
319 | | datetime_date_fromordinal(PyObject *type, PyObject *arg) |
320 | 0 | { |
321 | 0 | PyObject *return_value = NULL; |
322 | 0 | int ordinal; |
323 | |
|
324 | 0 | ordinal = PyLong_AsInt(arg); |
325 | 0 | if (ordinal == -1 && PyErr_Occurred()) { |
326 | 0 | goto exit; |
327 | 0 | } |
328 | 0 | return_value = datetime_date_fromordinal_impl((PyTypeObject *)type, ordinal); |
329 | |
|
330 | 0 | exit: |
331 | 0 | return return_value; |
332 | 0 | } |
333 | | |
334 | | PyDoc_STRVAR(datetime_date_fromisoformat__doc__, |
335 | | "fromisoformat($type, string, /)\n" |
336 | | "--\n" |
337 | | "\n" |
338 | | "Construct a date from a string in ISO 8601 format."); |
339 | | |
340 | | #define DATETIME_DATE_FROMISOFORMAT_METHODDEF \ |
341 | | {"fromisoformat", (PyCFunction)datetime_date_fromisoformat, METH_O|METH_CLASS, datetime_date_fromisoformat__doc__}, |
342 | | |
343 | | static PyObject * |
344 | | datetime_date_fromisoformat_impl(PyTypeObject *type, PyObject *string); |
345 | | |
346 | | static PyObject * |
347 | | datetime_date_fromisoformat(PyObject *type, PyObject *arg) |
348 | 0 | { |
349 | 0 | PyObject *return_value = NULL; |
350 | 0 | PyObject *string; |
351 | |
|
352 | 0 | if (!PyUnicode_Check(arg)) { |
353 | 0 | _PyArg_BadArgument("fromisoformat", "argument", "str", arg); |
354 | 0 | goto exit; |
355 | 0 | } |
356 | 0 | string = arg; |
357 | 0 | return_value = datetime_date_fromisoformat_impl((PyTypeObject *)type, string); |
358 | |
|
359 | 0 | exit: |
360 | 0 | return return_value; |
361 | 0 | } |
362 | | |
363 | | PyDoc_STRVAR(datetime_date_fromisocalendar__doc__, |
364 | | "fromisocalendar($type, /, year, week, day)\n" |
365 | | "--\n" |
366 | | "\n" |
367 | | "Construct a date from the ISO year, week number and weekday.\n" |
368 | | "\n" |
369 | | "This is the inverse of the date.isocalendar() function."); |
370 | | |
371 | | #define DATETIME_DATE_FROMISOCALENDAR_METHODDEF \ |
372 | | {"fromisocalendar", _PyCFunction_CAST(datetime_date_fromisocalendar), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_date_fromisocalendar__doc__}, |
373 | | |
374 | | static PyObject * |
375 | | datetime_date_fromisocalendar_impl(PyTypeObject *type, int year, int week, |
376 | | int day); |
377 | | |
378 | | static PyObject * |
379 | | datetime_date_fromisocalendar(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
380 | 0 | { |
381 | 0 | PyObject *return_value = NULL; |
382 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
383 | |
|
384 | 0 | #define NUM_KEYWORDS 3 |
385 | 0 | static struct { |
386 | 0 | PyGC_Head _this_is_not_used; |
387 | 0 | PyObject_VAR_HEAD |
388 | 0 | Py_hash_t ob_hash; |
389 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
390 | 0 | } _kwtuple = { |
391 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
392 | 0 | .ob_hash = -1, |
393 | 0 | .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(day), }, |
394 | 0 | }; |
395 | 0 | #undef NUM_KEYWORDS |
396 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
397 | |
|
398 | | #else // !Py_BUILD_CORE |
399 | | # define KWTUPLE NULL |
400 | | #endif // !Py_BUILD_CORE |
401 | |
|
402 | 0 | static const char * const _keywords[] = {"year", "week", "day", NULL}; |
403 | 0 | static _PyArg_Parser _parser = { |
404 | 0 | .keywords = _keywords, |
405 | 0 | .fname = "fromisocalendar", |
406 | 0 | .kwtuple = KWTUPLE, |
407 | 0 | }; |
408 | 0 | #undef KWTUPLE |
409 | 0 | PyObject *argsbuf[3]; |
410 | 0 | int year; |
411 | 0 | int week; |
412 | 0 | int day; |
413 | |
|
414 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
415 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
416 | 0 | if (!args) { |
417 | 0 | goto exit; |
418 | 0 | } |
419 | 0 | year = PyLong_AsInt(args[0]); |
420 | 0 | if (year == -1 && PyErr_Occurred()) { |
421 | 0 | goto exit; |
422 | 0 | } |
423 | 0 | week = PyLong_AsInt(args[1]); |
424 | 0 | if (week == -1 && PyErr_Occurred()) { |
425 | 0 | goto exit; |
426 | 0 | } |
427 | 0 | day = PyLong_AsInt(args[2]); |
428 | 0 | if (day == -1 && PyErr_Occurred()) { |
429 | 0 | goto exit; |
430 | 0 | } |
431 | 0 | return_value = datetime_date_fromisocalendar_impl((PyTypeObject *)type, year, week, day); |
432 | |
|
433 | 0 | exit: |
434 | 0 | return return_value; |
435 | 0 | } |
436 | | |
437 | | PyDoc_STRVAR(datetime_date_strptime__doc__, |
438 | | "strptime($type, string, format, /)\n" |
439 | | "--\n" |
440 | | "\n" |
441 | | "Parse string according to the given date format (like time.strptime()).\n" |
442 | | "\n" |
443 | | "For a list of supported format codes, see the documentation:\n" |
444 | | " https://docs.python.org/3/library/datetime.html#format-codes"); |
445 | | |
446 | | #define DATETIME_DATE_STRPTIME_METHODDEF \ |
447 | | {"strptime", _PyCFunction_CAST(datetime_date_strptime), METH_FASTCALL|METH_CLASS, datetime_date_strptime__doc__}, |
448 | | |
449 | | static PyObject * |
450 | | datetime_date_strptime_impl(PyTypeObject *type, PyObject *string, |
451 | | PyObject *format); |
452 | | |
453 | | static PyObject * |
454 | | datetime_date_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs) |
455 | 0 | { |
456 | 0 | PyObject *return_value = NULL; |
457 | 0 | PyObject *string; |
458 | 0 | PyObject *format; |
459 | |
|
460 | 0 | if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) { |
461 | 0 | goto exit; |
462 | 0 | } |
463 | 0 | if (!PyUnicode_Check(args[0])) { |
464 | 0 | _PyArg_BadArgument("strptime", "argument 1", "str", args[0]); |
465 | 0 | goto exit; |
466 | 0 | } |
467 | 0 | string = args[0]; |
468 | 0 | if (!PyUnicode_Check(args[1])) { |
469 | 0 | _PyArg_BadArgument("strptime", "argument 2", "str", args[1]); |
470 | 0 | goto exit; |
471 | 0 | } |
472 | 0 | format = args[1]; |
473 | 0 | return_value = datetime_date_strptime_impl((PyTypeObject *)type, string, format); |
474 | |
|
475 | 0 | exit: |
476 | 0 | return return_value; |
477 | 0 | } |
478 | | |
479 | | PyDoc_STRVAR(datetime_date_strftime__doc__, |
480 | | "strftime($self, /, format)\n" |
481 | | "--\n" |
482 | | "\n" |
483 | | "Format using strftime().\n" |
484 | | "\n" |
485 | | "Example: \"%d/%m/%Y, %H:%M:%S\".\n" |
486 | | "\n" |
487 | | "For a list of supported format codes, see the documentation:\n" |
488 | | " https://docs.python.org/3/library/datetime.html#format-codes"); |
489 | | |
490 | | #define DATETIME_DATE_STRFTIME_METHODDEF \ |
491 | | {"strftime", _PyCFunction_CAST(datetime_date_strftime), METH_FASTCALL|METH_KEYWORDS, datetime_date_strftime__doc__}, |
492 | | |
493 | | static PyObject * |
494 | | datetime_date_strftime_impl(PyObject *self, PyObject *format); |
495 | | |
496 | | static PyObject * |
497 | | datetime_date_strftime(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
498 | 0 | { |
499 | 0 | PyObject *return_value = NULL; |
500 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
501 | |
|
502 | 0 | #define NUM_KEYWORDS 1 |
503 | 0 | static struct { |
504 | 0 | PyGC_Head _this_is_not_used; |
505 | 0 | PyObject_VAR_HEAD |
506 | 0 | Py_hash_t ob_hash; |
507 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
508 | 0 | } _kwtuple = { |
509 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
510 | 0 | .ob_hash = -1, |
511 | 0 | .ob_item = { &_Py_ID(format), }, |
512 | 0 | }; |
513 | 0 | #undef NUM_KEYWORDS |
514 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
515 | |
|
516 | | #else // !Py_BUILD_CORE |
517 | | # define KWTUPLE NULL |
518 | | #endif // !Py_BUILD_CORE |
519 | |
|
520 | 0 | static const char * const _keywords[] = {"format", NULL}; |
521 | 0 | static _PyArg_Parser _parser = { |
522 | 0 | .keywords = _keywords, |
523 | 0 | .fname = "strftime", |
524 | 0 | .kwtuple = KWTUPLE, |
525 | 0 | }; |
526 | 0 | #undef KWTUPLE |
527 | 0 | PyObject *argsbuf[1]; |
528 | 0 | PyObject *format; |
529 | |
|
530 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
531 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
532 | 0 | if (!args) { |
533 | 0 | goto exit; |
534 | 0 | } |
535 | 0 | if (!PyUnicode_Check(args[0])) { |
536 | 0 | _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]); |
537 | 0 | goto exit; |
538 | 0 | } |
539 | 0 | format = args[0]; |
540 | 0 | return_value = datetime_date_strftime_impl(self, format); |
541 | |
|
542 | 0 | exit: |
543 | 0 | return return_value; |
544 | 0 | } |
545 | | |
546 | | PyDoc_STRVAR(datetime_date___format____doc__, |
547 | | "__format__($self, format, /)\n" |
548 | | "--\n" |
549 | | "\n" |
550 | | "Formats self with strftime."); |
551 | | |
552 | | #define DATETIME_DATE___FORMAT___METHODDEF \ |
553 | | {"__format__", (PyCFunction)datetime_date___format__, METH_O, datetime_date___format____doc__}, |
554 | | |
555 | | static PyObject * |
556 | | datetime_date___format___impl(PyObject *self, PyObject *format); |
557 | | |
558 | | static PyObject * |
559 | | datetime_date___format__(PyObject *self, PyObject *arg) |
560 | 0 | { |
561 | 0 | PyObject *return_value = NULL; |
562 | 0 | PyObject *format; |
563 | |
|
564 | 0 | if (!PyUnicode_Check(arg)) { |
565 | 0 | _PyArg_BadArgument("__format__", "argument", "str", arg); |
566 | 0 | goto exit; |
567 | 0 | } |
568 | 0 | format = arg; |
569 | 0 | return_value = datetime_date___format___impl(self, format); |
570 | |
|
571 | 0 | exit: |
572 | 0 | return return_value; |
573 | 0 | } |
574 | | |
575 | | static PyObject * |
576 | | iso_calendar_date_new_impl(PyTypeObject *type, int year, int week, |
577 | | int weekday); |
578 | | |
579 | | static PyObject * |
580 | | iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
581 | 0 | { |
582 | 0 | PyObject *return_value = NULL; |
583 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
584 | |
|
585 | 0 | #define NUM_KEYWORDS 3 |
586 | 0 | static struct { |
587 | 0 | PyGC_Head _this_is_not_used; |
588 | 0 | PyObject_VAR_HEAD |
589 | 0 | Py_hash_t ob_hash; |
590 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
591 | 0 | } _kwtuple = { |
592 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
593 | 0 | .ob_hash = -1, |
594 | 0 | .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(weekday), }, |
595 | 0 | }; |
596 | 0 | #undef NUM_KEYWORDS |
597 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
598 | |
|
599 | | #else // !Py_BUILD_CORE |
600 | | # define KWTUPLE NULL |
601 | | #endif // !Py_BUILD_CORE |
602 | |
|
603 | 0 | static const char * const _keywords[] = {"year", "week", "weekday", NULL}; |
604 | 0 | static _PyArg_Parser _parser = { |
605 | 0 | .keywords = _keywords, |
606 | 0 | .fname = "IsoCalendarDate", |
607 | 0 | .kwtuple = KWTUPLE, |
608 | 0 | }; |
609 | 0 | #undef KWTUPLE |
610 | 0 | PyObject *argsbuf[3]; |
611 | 0 | PyObject * const *fastargs; |
612 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
613 | 0 | int year; |
614 | 0 | int week; |
615 | 0 | int weekday; |
616 | |
|
617 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
618 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
619 | 0 | if (!fastargs) { |
620 | 0 | goto exit; |
621 | 0 | } |
622 | 0 | year = PyLong_AsInt(fastargs[0]); |
623 | 0 | if (year == -1 && PyErr_Occurred()) { |
624 | 0 | goto exit; |
625 | 0 | } |
626 | 0 | week = PyLong_AsInt(fastargs[1]); |
627 | 0 | if (week == -1 && PyErr_Occurred()) { |
628 | 0 | goto exit; |
629 | 0 | } |
630 | 0 | weekday = PyLong_AsInt(fastargs[2]); |
631 | 0 | if (weekday == -1 && PyErr_Occurred()) { |
632 | 0 | goto exit; |
633 | 0 | } |
634 | 0 | return_value = iso_calendar_date_new_impl(type, year, week, weekday); |
635 | |
|
636 | 0 | exit: |
637 | 0 | return return_value; |
638 | 0 | } |
639 | | |
640 | | PyDoc_STRVAR(datetime_date_replace__doc__, |
641 | | "replace($self, /, year=unchanged, month=unchanged, day=unchanged)\n" |
642 | | "--\n" |
643 | | "\n" |
644 | | "Return date with new specified fields."); |
645 | | |
646 | | #define DATETIME_DATE_REPLACE_METHODDEF \ |
647 | | {"replace", _PyCFunction_CAST(datetime_date_replace), METH_FASTCALL|METH_KEYWORDS, datetime_date_replace__doc__}, |
648 | | |
649 | | static PyObject * |
650 | | datetime_date_replace_impl(PyDateTime_Date *self, int year, int month, |
651 | | int day); |
652 | | |
653 | | static PyObject * |
654 | | datetime_date_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
655 | 0 | { |
656 | 0 | PyObject *return_value = NULL; |
657 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
658 | |
|
659 | 0 | #define NUM_KEYWORDS 3 |
660 | 0 | static struct { |
661 | 0 | PyGC_Head _this_is_not_used; |
662 | 0 | PyObject_VAR_HEAD |
663 | 0 | Py_hash_t ob_hash; |
664 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
665 | 0 | } _kwtuple = { |
666 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
667 | 0 | .ob_hash = -1, |
668 | 0 | .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), }, |
669 | 0 | }; |
670 | 0 | #undef NUM_KEYWORDS |
671 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
672 | |
|
673 | | #else // !Py_BUILD_CORE |
674 | | # define KWTUPLE NULL |
675 | | #endif // !Py_BUILD_CORE |
676 | |
|
677 | 0 | static const char * const _keywords[] = {"year", "month", "day", NULL}; |
678 | 0 | static _PyArg_Parser _parser = { |
679 | 0 | .keywords = _keywords, |
680 | 0 | .fname = "replace", |
681 | 0 | .kwtuple = KWTUPLE, |
682 | 0 | }; |
683 | 0 | #undef KWTUPLE |
684 | 0 | PyObject *argsbuf[3]; |
685 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
686 | 0 | int year = GET_YEAR(self); |
687 | 0 | int month = GET_MONTH(self); |
688 | 0 | int day = GET_DAY(self); |
689 | |
|
690 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
691 | 0 | /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
692 | 0 | if (!args) { |
693 | 0 | goto exit; |
694 | 0 | } |
695 | 0 | if (!noptargs) { |
696 | 0 | goto skip_optional_pos; |
697 | 0 | } |
698 | 0 | if (args[0]) { |
699 | 0 | year = PyLong_AsInt(args[0]); |
700 | 0 | if (year == -1 && PyErr_Occurred()) { |
701 | 0 | goto exit; |
702 | 0 | } |
703 | 0 | if (!--noptargs) { |
704 | 0 | goto skip_optional_pos; |
705 | 0 | } |
706 | 0 | } |
707 | 0 | if (args[1]) { |
708 | 0 | month = PyLong_AsInt(args[1]); |
709 | 0 | if (month == -1 && PyErr_Occurred()) { |
710 | 0 | goto exit; |
711 | 0 | } |
712 | 0 | if (!--noptargs) { |
713 | 0 | goto skip_optional_pos; |
714 | 0 | } |
715 | 0 | } |
716 | 0 | day = PyLong_AsInt(args[2]); |
717 | 0 | if (day == -1 && PyErr_Occurred()) { |
718 | 0 | goto exit; |
719 | 0 | } |
720 | 0 | skip_optional_pos: |
721 | 0 | return_value = datetime_date_replace_impl((PyDateTime_Date *)self, year, month, day); |
722 | |
|
723 | 0 | exit: |
724 | 0 | return return_value; |
725 | 0 | } |
726 | | |
727 | | PyDoc_STRVAR(timezone_new__doc__, |
728 | | "timezone(offset, name=<unrepresentable>)\n" |
729 | | "--\n" |
730 | | "\n" |
731 | | "Fixed offset from UTC implementation of tzinfo."); |
732 | | |
733 | | static PyObject * |
734 | | timezone_new_impl(PyTypeObject *type, PyObject *offset, PyObject *name); |
735 | | |
736 | | static PyObject * |
737 | | timezone_new_helper(PyTypeObject *type, PyObject *const *args, |
738 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
739 | 0 | { |
740 | 0 | PyObject *return_value = NULL; |
741 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
742 | |
|
743 | 0 | #define NUM_KEYWORDS 2 |
744 | 0 | static struct { |
745 | 0 | PyGC_Head _this_is_not_used; |
746 | 0 | PyObject_VAR_HEAD |
747 | 0 | Py_hash_t ob_hash; |
748 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
749 | 0 | } _kwtuple = { |
750 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
751 | 0 | .ob_hash = -1, |
752 | 0 | .ob_item = { &_Py_ID(offset), &_Py_ID(name), }, |
753 | 0 | }; |
754 | 0 | #undef NUM_KEYWORDS |
755 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
756 | |
|
757 | | #else // !Py_BUILD_CORE |
758 | | # define KWTUPLE NULL |
759 | | #endif // !Py_BUILD_CORE |
760 | |
|
761 | 0 | static const char * const _keywords[] = {"offset", "name", NULL}; |
762 | 0 | static _PyArg_Parser _parser = { |
763 | 0 | .keywords = _keywords, |
764 | 0 | .fname = "timezone", |
765 | 0 | .kwtuple = KWTUPLE, |
766 | 0 | }; |
767 | 0 | #undef KWTUPLE |
768 | 0 | PyObject *argsbuf[2]; |
769 | 0 | PyObject * const *fastargs; |
770 | 0 | Py_ssize_t noptargs = nargs + nkw - 1; |
771 | 0 | PyObject *offset; |
772 | 0 | PyObject *name = NULL; |
773 | |
|
774 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
775 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
776 | 0 | if (!fastargs) { |
777 | 0 | goto exit; |
778 | 0 | } |
779 | 0 | if (!PyObject_TypeCheck(fastargs[0], DELTA_TYPE(NO_STATE))) { |
780 | 0 | _PyArg_BadArgument("timezone", "argument 'offset'", (DELTA_TYPE(NO_STATE))->tp_name, fastargs[0]); |
781 | 0 | goto exit; |
782 | 0 | } |
783 | 0 | offset = fastargs[0]; |
784 | 0 | if (!noptargs) { |
785 | 0 | goto skip_optional_pos; |
786 | 0 | } |
787 | 0 | if (!PyUnicode_Check(fastargs[1])) { |
788 | 0 | _PyArg_BadArgument("timezone", "argument 'name'", "str", fastargs[1]); |
789 | 0 | goto exit; |
790 | 0 | } |
791 | 0 | name = fastargs[1]; |
792 | 0 | skip_optional_pos: |
793 | 0 | return_value = timezone_new_impl(type, offset, name); |
794 | |
|
795 | 0 | exit: |
796 | 0 | return return_value; |
797 | 0 | } |
798 | | |
799 | | static PyObject * |
800 | | timezone_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
801 | 0 | { |
802 | 0 | return timezone_new_helper(type, _PyTuple_CAST(args)->ob_item, |
803 | 0 | PyTuple_GET_SIZE(args), |
804 | 0 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
805 | 0 | kwargs, NULL); |
806 | 0 | } |
807 | | |
808 | | static PyObject * |
809 | | timezone_vectorcall(PyObject *type, PyObject *const *args, |
810 | | size_t nargsf, PyObject *kwnames) |
811 | 125 | { |
812 | 125 | PyObject *return_value = NULL; |
813 | 125 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
814 | 125 | PyObject *offset; |
815 | 125 | PyObject *name = NULL; |
816 | | |
817 | 125 | assert(_PyType_CAST(type)->tp_new == timezone_new); |
818 | | /* Make sure the type object is immutable: the generated |
819 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
820 | 125 | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
821 | 125 | if (kwnames != NULL || nargs < 1 || nargs > 2) { |
822 | 0 | return timezone_new_helper(_PyType_CAST(type), args, nargs, |
823 | 0 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
824 | 0 | NULL, kwnames); |
825 | 0 | } |
826 | 125 | if (!PyObject_TypeCheck(args[0], DELTA_TYPE(NO_STATE))) { |
827 | 0 | _PyArg_BadArgument("timezone", "argument 'offset'", (DELTA_TYPE(NO_STATE))->tp_name, args[0]); |
828 | 0 | goto exit; |
829 | 0 | } |
830 | 125 | offset = args[0]; |
831 | 125 | if (nargs < 2) { |
832 | 125 | goto skip_optional; |
833 | 125 | } |
834 | 0 | if (!PyUnicode_Check(args[1])) { |
835 | 0 | _PyArg_BadArgument("timezone", "argument 'name'", "str", args[1]); |
836 | 0 | goto exit; |
837 | 0 | } |
838 | 0 | name = args[1]; |
839 | 125 | skip_optional: |
840 | 125 | return_value = timezone_new_impl(_PyType_CAST(type), offset, name); |
841 | | |
842 | 125 | exit: |
843 | 125 | return return_value; |
844 | 125 | } |
845 | | |
846 | | PyDoc_STRVAR(datetime_time__doc__, |
847 | | "time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)\n" |
848 | | "--\n" |
849 | | "\n" |
850 | | "Time with time zone.\n" |
851 | | "\n" |
852 | | "All arguments are optional. tzinfo may be None, or an instance of\n" |
853 | | "a tzinfo subclass. The remaining arguments may be ints."); |
854 | | |
855 | | static PyObject * |
856 | | datetime_time_impl(PyTypeObject *type, int hour, int minute, int second, |
857 | | int microsecond, PyObject *tzinfo, int fold); |
858 | | |
859 | | static PyObject * |
860 | | datetime_time(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
861 | 21.5k | { |
862 | 21.5k | PyObject *return_value = NULL; |
863 | 21.5k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
864 | | |
865 | 21.5k | #define NUM_KEYWORDS 6 |
866 | 21.5k | static struct { |
867 | 21.5k | PyGC_Head _this_is_not_used; |
868 | 21.5k | PyObject_VAR_HEAD |
869 | 21.5k | Py_hash_t ob_hash; |
870 | 21.5k | PyObject *ob_item[NUM_KEYWORDS]; |
871 | 21.5k | } _kwtuple = { |
872 | 21.5k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
873 | 21.5k | .ob_hash = -1, |
874 | 21.5k | .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), }, |
875 | 21.5k | }; |
876 | 21.5k | #undef NUM_KEYWORDS |
877 | 21.5k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
878 | | |
879 | | #else // !Py_BUILD_CORE |
880 | | # define KWTUPLE NULL |
881 | | #endif // !Py_BUILD_CORE |
882 | | |
883 | 21.5k | static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL}; |
884 | 21.5k | static _PyArg_Parser _parser = { |
885 | 21.5k | .keywords = _keywords, |
886 | 21.5k | .fname = "time", |
887 | 21.5k | .kwtuple = KWTUPLE, |
888 | 21.5k | }; |
889 | 21.5k | #undef KWTUPLE |
890 | 21.5k | PyObject *argsbuf[6]; |
891 | 21.5k | PyObject * const *fastargs; |
892 | 21.5k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
893 | 21.5k | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
894 | 21.5k | int hour = 0; |
895 | 21.5k | int minute = 0; |
896 | 21.5k | int second = 0; |
897 | 21.5k | int microsecond = 0; |
898 | 21.5k | PyObject *tzinfo = Py_None; |
899 | 21.5k | int fold = 0; |
900 | | |
901 | 21.5k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
902 | 21.5k | /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
903 | 21.5k | if (!fastargs) { |
904 | 0 | goto exit; |
905 | 0 | } |
906 | 21.5k | if (!noptargs) { |
907 | 0 | goto skip_optional_pos; |
908 | 0 | } |
909 | 21.5k | if (fastargs[0]) { |
910 | 21.5k | hour = PyLong_AsInt(fastargs[0]); |
911 | 21.5k | if (hour == -1 && PyErr_Occurred()) { |
912 | 0 | goto exit; |
913 | 0 | } |
914 | 21.5k | if (!--noptargs) { |
915 | 0 | goto skip_optional_pos; |
916 | 0 | } |
917 | 21.5k | } |
918 | 21.5k | if (fastargs[1]) { |
919 | 21.5k | minute = PyLong_AsInt(fastargs[1]); |
920 | 21.5k | if (minute == -1 && PyErr_Occurred()) { |
921 | 0 | goto exit; |
922 | 0 | } |
923 | 21.5k | if (!--noptargs) { |
924 | 0 | goto skip_optional_pos; |
925 | 0 | } |
926 | 21.5k | } |
927 | 21.5k | if (fastargs[2]) { |
928 | 21.5k | second = PyLong_AsInt(fastargs[2]); |
929 | 21.5k | if (second == -1 && PyErr_Occurred()) { |
930 | 0 | goto exit; |
931 | 0 | } |
932 | 21.5k | if (!--noptargs) { |
933 | 0 | goto skip_optional_pos; |
934 | 0 | } |
935 | 21.5k | } |
936 | 21.5k | if (fastargs[3]) { |
937 | 21.5k | microsecond = PyLong_AsInt(fastargs[3]); |
938 | 21.5k | if (microsecond == -1 && PyErr_Occurred()) { |
939 | 0 | goto exit; |
940 | 0 | } |
941 | 21.5k | if (!--noptargs) { |
942 | 21.5k | goto skip_optional_pos; |
943 | 21.5k | } |
944 | 21.5k | } |
945 | 0 | if (fastargs[4]) { |
946 | 0 | tzinfo = fastargs[4]; |
947 | 0 | if (!--noptargs) { |
948 | 0 | goto skip_optional_pos; |
949 | 0 | } |
950 | 0 | } |
951 | 21.5k | skip_optional_pos: |
952 | 21.5k | if (!noptargs) { |
953 | 21.5k | goto skip_optional_kwonly; |
954 | 21.5k | } |
955 | 0 | fold = PyLong_AsInt(fastargs[5]); |
956 | 0 | if (fold == -1 && PyErr_Occurred()) { |
957 | 0 | goto exit; |
958 | 0 | } |
959 | 21.5k | skip_optional_kwonly: |
960 | 21.5k | return_value = datetime_time_impl(type, hour, minute, second, microsecond, tzinfo, fold); |
961 | | |
962 | 21.5k | exit: |
963 | 21.5k | return return_value; |
964 | 21.5k | } |
965 | | |
966 | | PyDoc_STRVAR(datetime_time_strptime__doc__, |
967 | | "strptime($type, string, format, /)\n" |
968 | | "--\n" |
969 | | "\n" |
970 | | "Parse string according to the given time format (like time.strptime()).\n" |
971 | | "\n" |
972 | | "For a list of supported format codes, see the documentation:\n" |
973 | | " https://docs.python.org/3/library/datetime.html#format-codes"); |
974 | | |
975 | | #define DATETIME_TIME_STRPTIME_METHODDEF \ |
976 | | {"strptime", _PyCFunction_CAST(datetime_time_strptime), METH_FASTCALL|METH_CLASS, datetime_time_strptime__doc__}, |
977 | | |
978 | | static PyObject * |
979 | | datetime_time_strptime_impl(PyTypeObject *type, PyObject *string, |
980 | | PyObject *format); |
981 | | |
982 | | static PyObject * |
983 | | datetime_time_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs) |
984 | 0 | { |
985 | 0 | PyObject *return_value = NULL; |
986 | 0 | PyObject *string; |
987 | 0 | PyObject *format; |
988 | |
|
989 | 0 | if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) { |
990 | 0 | goto exit; |
991 | 0 | } |
992 | 0 | if (!PyUnicode_Check(args[0])) { |
993 | 0 | _PyArg_BadArgument("strptime", "argument 1", "str", args[0]); |
994 | 0 | goto exit; |
995 | 0 | } |
996 | 0 | string = args[0]; |
997 | 0 | if (!PyUnicode_Check(args[1])) { |
998 | 0 | _PyArg_BadArgument("strptime", "argument 2", "str", args[1]); |
999 | 0 | goto exit; |
1000 | 0 | } |
1001 | 0 | format = args[1]; |
1002 | 0 | return_value = datetime_time_strptime_impl((PyTypeObject *)type, string, format); |
1003 | |
|
1004 | 0 | exit: |
1005 | 0 | return return_value; |
1006 | 0 | } |
1007 | | |
1008 | | PyDoc_STRVAR(datetime_time_isoformat__doc__, |
1009 | | "isoformat($self, /, timespec=\'auto\')\n" |
1010 | | "--\n" |
1011 | | "\n" |
1012 | | "Return the time formatted according to ISO.\n" |
1013 | | "\n" |
1014 | | "The full format is \'HH:MM:SS.mmmmmm+zz:zz\'. By default, the\n" |
1015 | | "fractional part is omitted if self.microsecond == 0.\n" |
1016 | | "\n" |
1017 | | "The optional argument timespec specifies the number of additional\n" |
1018 | | "terms of the time to include. Valid options are \'auto\', \'hours\',\n" |
1019 | | "\'minutes\', \'seconds\', \'milliseconds\' and \'microseconds\'."); |
1020 | | |
1021 | | #define DATETIME_TIME_ISOFORMAT_METHODDEF \ |
1022 | | {"isoformat", _PyCFunction_CAST(datetime_time_isoformat), METH_FASTCALL|METH_KEYWORDS, datetime_time_isoformat__doc__}, |
1023 | | |
1024 | | static PyObject * |
1025 | | datetime_time_isoformat_impl(PyDateTime_Time *self, const char *timespec); |
1026 | | |
1027 | | static PyObject * |
1028 | | datetime_time_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1029 | 0 | { |
1030 | 0 | PyObject *return_value = NULL; |
1031 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1032 | |
|
1033 | 0 | #define NUM_KEYWORDS 1 |
1034 | 0 | static struct { |
1035 | 0 | PyGC_Head _this_is_not_used; |
1036 | 0 | PyObject_VAR_HEAD |
1037 | 0 | Py_hash_t ob_hash; |
1038 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1039 | 0 | } _kwtuple = { |
1040 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1041 | 0 | .ob_hash = -1, |
1042 | 0 | .ob_item = { &_Py_ID(timespec), }, |
1043 | 0 | }; |
1044 | 0 | #undef NUM_KEYWORDS |
1045 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1046 | |
|
1047 | | #else // !Py_BUILD_CORE |
1048 | | # define KWTUPLE NULL |
1049 | | #endif // !Py_BUILD_CORE |
1050 | |
|
1051 | 0 | static const char * const _keywords[] = {"timespec", NULL}; |
1052 | 0 | static _PyArg_Parser _parser = { |
1053 | 0 | .keywords = _keywords, |
1054 | 0 | .fname = "isoformat", |
1055 | 0 | .kwtuple = KWTUPLE, |
1056 | 0 | }; |
1057 | 0 | #undef KWTUPLE |
1058 | 0 | PyObject *argsbuf[1]; |
1059 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1060 | 0 | const char *timespec = NULL; |
1061 | |
|
1062 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1063 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1064 | 0 | if (!args) { |
1065 | 0 | goto exit; |
1066 | 0 | } |
1067 | 0 | if (!noptargs) { |
1068 | 0 | goto skip_optional_pos; |
1069 | 0 | } |
1070 | 0 | if (!PyUnicode_Check(args[0])) { |
1071 | 0 | _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[0]); |
1072 | 0 | goto exit; |
1073 | 0 | } |
1074 | 0 | timespec = _PyUnicode_AsUTF8NoNUL(args[0]); |
1075 | 0 | if (timespec == NULL) { |
1076 | 0 | goto exit; |
1077 | 0 | } |
1078 | 0 | skip_optional_pos: |
1079 | 0 | return_value = datetime_time_isoformat_impl((PyDateTime_Time *)self, timespec); |
1080 | |
|
1081 | 0 | exit: |
1082 | 0 | return return_value; |
1083 | 0 | } |
1084 | | |
1085 | | PyDoc_STRVAR(datetime_time_strftime__doc__, |
1086 | | "strftime($self, /, format)\n" |
1087 | | "--\n" |
1088 | | "\n" |
1089 | | "Format using strftime().\n" |
1090 | | "\n" |
1091 | | "The date part of the timestamp passed to underlying strftime should\n" |
1092 | | "not be used.\n" |
1093 | | "\n" |
1094 | | "For a list of supported format codes, see the documentation:\n" |
1095 | | " https://docs.python.org/3/library/datetime.html#format-codes"); |
1096 | | |
1097 | | #define DATETIME_TIME_STRFTIME_METHODDEF \ |
1098 | | {"strftime", _PyCFunction_CAST(datetime_time_strftime), METH_FASTCALL|METH_KEYWORDS, datetime_time_strftime__doc__}, |
1099 | | |
1100 | | static PyObject * |
1101 | | datetime_time_strftime_impl(PyDateTime_Time *self, PyObject *format); |
1102 | | |
1103 | | static PyObject * |
1104 | | datetime_time_strftime(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1105 | 0 | { |
1106 | 0 | PyObject *return_value = NULL; |
1107 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1108 | |
|
1109 | 0 | #define NUM_KEYWORDS 1 |
1110 | 0 | static struct { |
1111 | 0 | PyGC_Head _this_is_not_used; |
1112 | 0 | PyObject_VAR_HEAD |
1113 | 0 | Py_hash_t ob_hash; |
1114 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1115 | 0 | } _kwtuple = { |
1116 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1117 | 0 | .ob_hash = -1, |
1118 | 0 | .ob_item = { &_Py_ID(format), }, |
1119 | 0 | }; |
1120 | 0 | #undef NUM_KEYWORDS |
1121 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1122 | |
|
1123 | | #else // !Py_BUILD_CORE |
1124 | | # define KWTUPLE NULL |
1125 | | #endif // !Py_BUILD_CORE |
1126 | |
|
1127 | 0 | static const char * const _keywords[] = {"format", NULL}; |
1128 | 0 | static _PyArg_Parser _parser = { |
1129 | 0 | .keywords = _keywords, |
1130 | 0 | .fname = "strftime", |
1131 | 0 | .kwtuple = KWTUPLE, |
1132 | 0 | }; |
1133 | 0 | #undef KWTUPLE |
1134 | 0 | PyObject *argsbuf[1]; |
1135 | 0 | PyObject *format; |
1136 | |
|
1137 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1138 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1139 | 0 | if (!args) { |
1140 | 0 | goto exit; |
1141 | 0 | } |
1142 | 0 | if (!PyUnicode_Check(args[0])) { |
1143 | 0 | _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]); |
1144 | 0 | goto exit; |
1145 | 0 | } |
1146 | 0 | format = args[0]; |
1147 | 0 | return_value = datetime_time_strftime_impl((PyDateTime_Time *)self, format); |
1148 | |
|
1149 | 0 | exit: |
1150 | 0 | return return_value; |
1151 | 0 | } |
1152 | | |
1153 | | PyDoc_STRVAR(datetime_time___format____doc__, |
1154 | | "__format__($self, format, /)\n" |
1155 | | "--\n" |
1156 | | "\n" |
1157 | | "Formats self with strftime."); |
1158 | | |
1159 | | #define DATETIME_TIME___FORMAT___METHODDEF \ |
1160 | | {"__format__", (PyCFunction)datetime_time___format__, METH_O, datetime_time___format____doc__}, |
1161 | | |
1162 | | static PyObject * |
1163 | | datetime_time___format___impl(PyObject *self, PyObject *format); |
1164 | | |
1165 | | static PyObject * |
1166 | | datetime_time___format__(PyObject *self, PyObject *arg) |
1167 | 0 | { |
1168 | 0 | PyObject *return_value = NULL; |
1169 | 0 | PyObject *format; |
1170 | |
|
1171 | 0 | if (!PyUnicode_Check(arg)) { |
1172 | 0 | _PyArg_BadArgument("__format__", "argument", "str", arg); |
1173 | 0 | goto exit; |
1174 | 0 | } |
1175 | 0 | format = arg; |
1176 | 0 | return_value = datetime_time___format___impl(self, format); |
1177 | |
|
1178 | 0 | exit: |
1179 | 0 | return return_value; |
1180 | 0 | } |
1181 | | |
1182 | | PyDoc_STRVAR(datetime_time_replace__doc__, |
1183 | | "replace($self, /, hour=unchanged, minute=unchanged, second=unchanged,\n" |
1184 | | " microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n" |
1185 | | "--\n" |
1186 | | "\n" |
1187 | | "Return time with new specified fields."); |
1188 | | |
1189 | | #define DATETIME_TIME_REPLACE_METHODDEF \ |
1190 | | {"replace", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL|METH_KEYWORDS, datetime_time_replace__doc__}, |
1191 | | |
1192 | | static PyObject * |
1193 | | datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute, |
1194 | | int second, int microsecond, PyObject *tzinfo, |
1195 | | int fold); |
1196 | | |
1197 | | static PyObject * |
1198 | | datetime_time_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1199 | 0 | { |
1200 | 0 | PyObject *return_value = NULL; |
1201 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1202 | |
|
1203 | 0 | #define NUM_KEYWORDS 6 |
1204 | 0 | static struct { |
1205 | 0 | PyGC_Head _this_is_not_used; |
1206 | 0 | PyObject_VAR_HEAD |
1207 | 0 | Py_hash_t ob_hash; |
1208 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1209 | 0 | } _kwtuple = { |
1210 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1211 | 0 | .ob_hash = -1, |
1212 | 0 | .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), }, |
1213 | 0 | }; |
1214 | 0 | #undef NUM_KEYWORDS |
1215 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1216 | |
|
1217 | | #else // !Py_BUILD_CORE |
1218 | | # define KWTUPLE NULL |
1219 | | #endif // !Py_BUILD_CORE |
1220 | |
|
1221 | 0 | static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL}; |
1222 | 0 | static _PyArg_Parser _parser = { |
1223 | 0 | .keywords = _keywords, |
1224 | 0 | .fname = "replace", |
1225 | 0 | .kwtuple = KWTUPLE, |
1226 | 0 | }; |
1227 | 0 | #undef KWTUPLE |
1228 | 0 | PyObject *argsbuf[6]; |
1229 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1230 | 0 | int hour = TIME_GET_HOUR(self); |
1231 | 0 | int minute = TIME_GET_MINUTE(self); |
1232 | 0 | int second = TIME_GET_SECOND(self); |
1233 | 0 | int microsecond = TIME_GET_MICROSECOND(self); |
1234 | 0 | PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None; |
1235 | 0 | int fold = TIME_GET_FOLD(self); |
1236 | |
|
1237 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1238 | 0 | /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1239 | 0 | if (!args) { |
1240 | 0 | goto exit; |
1241 | 0 | } |
1242 | 0 | if (!noptargs) { |
1243 | 0 | goto skip_optional_pos; |
1244 | 0 | } |
1245 | 0 | if (args[0]) { |
1246 | 0 | hour = PyLong_AsInt(args[0]); |
1247 | 0 | if (hour == -1 && PyErr_Occurred()) { |
1248 | 0 | goto exit; |
1249 | 0 | } |
1250 | 0 | if (!--noptargs) { |
1251 | 0 | goto skip_optional_pos; |
1252 | 0 | } |
1253 | 0 | } |
1254 | 0 | if (args[1]) { |
1255 | 0 | minute = PyLong_AsInt(args[1]); |
1256 | 0 | if (minute == -1 && PyErr_Occurred()) { |
1257 | 0 | goto exit; |
1258 | 0 | } |
1259 | 0 | if (!--noptargs) { |
1260 | 0 | goto skip_optional_pos; |
1261 | 0 | } |
1262 | 0 | } |
1263 | 0 | if (args[2]) { |
1264 | 0 | second = PyLong_AsInt(args[2]); |
1265 | 0 | if (second == -1 && PyErr_Occurred()) { |
1266 | 0 | goto exit; |
1267 | 0 | } |
1268 | 0 | if (!--noptargs) { |
1269 | 0 | goto skip_optional_pos; |
1270 | 0 | } |
1271 | 0 | } |
1272 | 0 | if (args[3]) { |
1273 | 0 | microsecond = PyLong_AsInt(args[3]); |
1274 | 0 | if (microsecond == -1 && PyErr_Occurred()) { |
1275 | 0 | goto exit; |
1276 | 0 | } |
1277 | 0 | if (!--noptargs) { |
1278 | 0 | goto skip_optional_pos; |
1279 | 0 | } |
1280 | 0 | } |
1281 | 0 | if (args[4]) { |
1282 | 0 | tzinfo = args[4]; |
1283 | 0 | if (!--noptargs) { |
1284 | 0 | goto skip_optional_pos; |
1285 | 0 | } |
1286 | 0 | } |
1287 | 0 | skip_optional_pos: |
1288 | 0 | if (!noptargs) { |
1289 | 0 | goto skip_optional_kwonly; |
1290 | 0 | } |
1291 | 0 | fold = PyLong_AsInt(args[5]); |
1292 | 0 | if (fold == -1 && PyErr_Occurred()) { |
1293 | 0 | goto exit; |
1294 | 0 | } |
1295 | 0 | skip_optional_kwonly: |
1296 | 0 | return_value = datetime_time_replace_impl((PyDateTime_Time *)self, hour, minute, second, microsecond, tzinfo, fold); |
1297 | |
|
1298 | 0 | exit: |
1299 | 0 | return return_value; |
1300 | 0 | } |
1301 | | |
1302 | | PyDoc_STRVAR(datetime_time_fromisoformat__doc__, |
1303 | | "fromisoformat($type, string, /)\n" |
1304 | | "--\n" |
1305 | | "\n" |
1306 | | "Construct a time from a string in ISO 8601 format."); |
1307 | | |
1308 | | #define DATETIME_TIME_FROMISOFORMAT_METHODDEF \ |
1309 | | {"fromisoformat", (PyCFunction)datetime_time_fromisoformat, METH_O|METH_CLASS, datetime_time_fromisoformat__doc__}, |
1310 | | |
1311 | | static PyObject * |
1312 | | datetime_time_fromisoformat_impl(PyTypeObject *type, PyObject *string); |
1313 | | |
1314 | | static PyObject * |
1315 | | datetime_time_fromisoformat(PyObject *type, PyObject *arg) |
1316 | 0 | { |
1317 | 0 | PyObject *return_value = NULL; |
1318 | 0 | PyObject *string; |
1319 | |
|
1320 | 0 | if (!PyUnicode_Check(arg)) { |
1321 | 0 | _PyArg_BadArgument("fromisoformat", "argument", "str", arg); |
1322 | 0 | goto exit; |
1323 | 0 | } |
1324 | 0 | string = arg; |
1325 | 0 | return_value = datetime_time_fromisoformat_impl((PyTypeObject *)type, string); |
1326 | |
|
1327 | 0 | exit: |
1328 | 0 | return return_value; |
1329 | 0 | } |
1330 | | |
1331 | | PyDoc_STRVAR(datetime_time___reduce_ex____doc__, |
1332 | | "__reduce_ex__($self, proto, /)\n" |
1333 | | "--\n" |
1334 | | "\n"); |
1335 | | |
1336 | | #define DATETIME_TIME___REDUCE_EX___METHODDEF \ |
1337 | | {"__reduce_ex__", (PyCFunction)datetime_time___reduce_ex__, METH_O, datetime_time___reduce_ex____doc__}, |
1338 | | |
1339 | | static PyObject * |
1340 | | datetime_time___reduce_ex___impl(PyDateTime_Time *self, int proto); |
1341 | | |
1342 | | static PyObject * |
1343 | | datetime_time___reduce_ex__(PyObject *self, PyObject *arg) |
1344 | 0 | { |
1345 | 0 | PyObject *return_value = NULL; |
1346 | 0 | int proto; |
1347 | |
|
1348 | 0 | proto = PyLong_AsInt(arg); |
1349 | 0 | if (proto == -1 && PyErr_Occurred()) { |
1350 | 0 | goto exit; |
1351 | 0 | } |
1352 | 0 | return_value = datetime_time___reduce_ex___impl((PyDateTime_Time *)self, proto); |
1353 | |
|
1354 | 0 | exit: |
1355 | 0 | return return_value; |
1356 | 0 | } |
1357 | | |
1358 | | PyDoc_STRVAR(datetime_time___reduce____doc__, |
1359 | | "__reduce__($self, /)\n" |
1360 | | "--\n" |
1361 | | "\n"); |
1362 | | |
1363 | | #define DATETIME_TIME___REDUCE___METHODDEF \ |
1364 | | {"__reduce__", (PyCFunction)datetime_time___reduce__, METH_NOARGS, datetime_time___reduce____doc__}, |
1365 | | |
1366 | | static PyObject * |
1367 | | datetime_time___reduce___impl(PyDateTime_Time *self); |
1368 | | |
1369 | | static PyObject * |
1370 | | datetime_time___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1371 | 0 | { |
1372 | 0 | return datetime_time___reduce___impl((PyDateTime_Time *)self); |
1373 | 0 | } |
1374 | | |
1375 | | PyDoc_STRVAR(datetime_datetime__doc__, |
1376 | | "datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0,\n" |
1377 | | " tzinfo=None, *, fold=0)\n" |
1378 | | "--\n" |
1379 | | "\n" |
1380 | | "A combination of a date and a time.\n" |
1381 | | "\n" |
1382 | | "The year, month and day arguments are required. tzinfo may be None, or\n" |
1383 | | "an instance of a tzinfo subclass. The remaining arguments may be ints."); |
1384 | | |
1385 | | static PyObject * |
1386 | | datetime_datetime_impl(PyTypeObject *type, int year, int month, int day, |
1387 | | int hour, int minute, int second, int microsecond, |
1388 | | PyObject *tzinfo, int fold); |
1389 | | |
1390 | | static PyObject * |
1391 | | datetime_datetime(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
1392 | 19.8k | { |
1393 | 19.8k | PyObject *return_value = NULL; |
1394 | 19.8k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1395 | | |
1396 | 19.8k | #define NUM_KEYWORDS 9 |
1397 | 19.8k | static struct { |
1398 | 19.8k | PyGC_Head _this_is_not_used; |
1399 | 19.8k | PyObject_VAR_HEAD |
1400 | 19.8k | Py_hash_t ob_hash; |
1401 | 19.8k | PyObject *ob_item[NUM_KEYWORDS]; |
1402 | 19.8k | } _kwtuple = { |
1403 | 19.8k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1404 | 19.8k | .ob_hash = -1, |
1405 | 19.8k | .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), }, |
1406 | 19.8k | }; |
1407 | 19.8k | #undef NUM_KEYWORDS |
1408 | 19.8k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1409 | | |
1410 | | #else // !Py_BUILD_CORE |
1411 | | # define KWTUPLE NULL |
1412 | | #endif // !Py_BUILD_CORE |
1413 | | |
1414 | 19.8k | static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL}; |
1415 | 19.8k | static _PyArg_Parser _parser = { |
1416 | 19.8k | .keywords = _keywords, |
1417 | 19.8k | .fname = "datetime", |
1418 | 19.8k | .kwtuple = KWTUPLE, |
1419 | 19.8k | }; |
1420 | 19.8k | #undef KWTUPLE |
1421 | 19.8k | PyObject *argsbuf[9]; |
1422 | 19.8k | PyObject * const *fastargs; |
1423 | 19.8k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
1424 | 19.8k | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 3; |
1425 | 19.8k | int year; |
1426 | 19.8k | int month; |
1427 | 19.8k | int day; |
1428 | 19.8k | int hour = 0; |
1429 | 19.8k | int minute = 0; |
1430 | 19.8k | int second = 0; |
1431 | 19.8k | int microsecond = 0; |
1432 | 19.8k | PyObject *tzinfo = Py_None; |
1433 | 19.8k | int fold = 0; |
1434 | | |
1435 | 19.8k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
1436 | 19.8k | /*minpos*/ 3, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1437 | 19.8k | if (!fastargs) { |
1438 | 0 | goto exit; |
1439 | 0 | } |
1440 | 19.8k | year = PyLong_AsInt(fastargs[0]); |
1441 | 19.8k | if (year == -1 && PyErr_Occurred()) { |
1442 | 0 | goto exit; |
1443 | 0 | } |
1444 | 19.8k | month = PyLong_AsInt(fastargs[1]); |
1445 | 19.8k | if (month == -1 && PyErr_Occurred()) { |
1446 | 0 | goto exit; |
1447 | 0 | } |
1448 | 19.8k | day = PyLong_AsInt(fastargs[2]); |
1449 | 19.8k | if (day == -1 && PyErr_Occurred()) { |
1450 | 0 | goto exit; |
1451 | 0 | } |
1452 | 19.8k | if (!noptargs) { |
1453 | 156 | goto skip_optional_pos; |
1454 | 156 | } |
1455 | 19.6k | if (fastargs[3]) { |
1456 | 19.6k | hour = PyLong_AsInt(fastargs[3]); |
1457 | 19.6k | if (hour == -1 && PyErr_Occurred()) { |
1458 | 0 | goto exit; |
1459 | 0 | } |
1460 | 19.6k | if (!--noptargs) { |
1461 | 0 | goto skip_optional_pos; |
1462 | 0 | } |
1463 | 19.6k | } |
1464 | 19.6k | if (fastargs[4]) { |
1465 | 19.6k | minute = PyLong_AsInt(fastargs[4]); |
1466 | 19.6k | if (minute == -1 && PyErr_Occurred()) { |
1467 | 0 | goto exit; |
1468 | 0 | } |
1469 | 19.6k | if (!--noptargs) { |
1470 | 0 | goto skip_optional_pos; |
1471 | 0 | } |
1472 | 19.6k | } |
1473 | 19.6k | if (fastargs[5]) { |
1474 | 19.6k | second = PyLong_AsInt(fastargs[5]); |
1475 | 19.6k | if (second == -1 && PyErr_Occurred()) { |
1476 | 0 | goto exit; |
1477 | 0 | } |
1478 | 19.6k | if (!--noptargs) { |
1479 | 136 | goto skip_optional_pos; |
1480 | 136 | } |
1481 | 19.6k | } |
1482 | 19.5k | if (fastargs[6]) { |
1483 | 19.5k | microsecond = PyLong_AsInt(fastargs[6]); |
1484 | 19.5k | if (microsecond == -1 && PyErr_Occurred()) { |
1485 | 0 | goto exit; |
1486 | 0 | } |
1487 | 19.5k | if (!--noptargs) { |
1488 | 0 | goto skip_optional_pos; |
1489 | 0 | } |
1490 | 19.5k | } |
1491 | 19.5k | if (fastargs[7]) { |
1492 | 19.5k | tzinfo = fastargs[7]; |
1493 | 19.5k | if (!--noptargs) { |
1494 | 19.5k | goto skip_optional_pos; |
1495 | 19.5k | } |
1496 | 19.5k | } |
1497 | 19.8k | skip_optional_pos: |
1498 | 19.8k | if (!noptargs) { |
1499 | 19.8k | goto skip_optional_kwonly; |
1500 | 19.8k | } |
1501 | 0 | fold = PyLong_AsInt(fastargs[8]); |
1502 | 0 | if (fold == -1 && PyErr_Occurred()) { |
1503 | 0 | goto exit; |
1504 | 0 | } |
1505 | 19.8k | skip_optional_kwonly: |
1506 | 19.8k | return_value = datetime_datetime_impl(type, year, month, day, hour, minute, second, microsecond, tzinfo, fold); |
1507 | | |
1508 | 19.8k | exit: |
1509 | 19.8k | return return_value; |
1510 | 19.8k | } |
1511 | | |
1512 | | PyDoc_STRVAR(datetime_datetime_now__doc__, |
1513 | | "now($type, /, tz=None)\n" |
1514 | | "--\n" |
1515 | | "\n" |
1516 | | "Returns new datetime object representing current time local to tz.\n" |
1517 | | "\n" |
1518 | | " tz\n" |
1519 | | " Timezone object.\n" |
1520 | | "\n" |
1521 | | "If no tz is specified, uses local timezone."); |
1522 | | |
1523 | | #define DATETIME_DATETIME_NOW_METHODDEF \ |
1524 | | {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__}, |
1525 | | |
1526 | | static PyObject * |
1527 | | datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz); |
1528 | | |
1529 | | static PyObject * |
1530 | | datetime_datetime_now(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1531 | 0 | { |
1532 | 0 | PyObject *return_value = NULL; |
1533 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1534 | |
|
1535 | 0 | #define NUM_KEYWORDS 1 |
1536 | 0 | static struct { |
1537 | 0 | PyGC_Head _this_is_not_used; |
1538 | 0 | PyObject_VAR_HEAD |
1539 | 0 | Py_hash_t ob_hash; |
1540 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1541 | 0 | } _kwtuple = { |
1542 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1543 | 0 | .ob_hash = -1, |
1544 | 0 | .ob_item = { &_Py_ID(tz), }, |
1545 | 0 | }; |
1546 | 0 | #undef NUM_KEYWORDS |
1547 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1548 | |
|
1549 | | #else // !Py_BUILD_CORE |
1550 | | # define KWTUPLE NULL |
1551 | | #endif // !Py_BUILD_CORE |
1552 | |
|
1553 | 0 | static const char * const _keywords[] = {"tz", NULL}; |
1554 | 0 | static _PyArg_Parser _parser = { |
1555 | 0 | .keywords = _keywords, |
1556 | 0 | .fname = "now", |
1557 | 0 | .kwtuple = KWTUPLE, |
1558 | 0 | }; |
1559 | 0 | #undef KWTUPLE |
1560 | 0 | PyObject *argsbuf[1]; |
1561 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1562 | 0 | PyObject *tz = Py_None; |
1563 | |
|
1564 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1565 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1566 | 0 | if (!args) { |
1567 | 0 | goto exit; |
1568 | 0 | } |
1569 | 0 | if (!noptargs) { |
1570 | 0 | goto skip_optional_pos; |
1571 | 0 | } |
1572 | 0 | tz = args[0]; |
1573 | 0 | skip_optional_pos: |
1574 | 0 | return_value = datetime_datetime_now_impl((PyTypeObject *)type, tz); |
1575 | |
|
1576 | 0 | exit: |
1577 | 0 | return return_value; |
1578 | 0 | } |
1579 | | |
1580 | | PyDoc_STRVAR(datetime_datetime_utcnow__doc__, |
1581 | | "utcnow($type, /)\n" |
1582 | | "--\n" |
1583 | | "\n" |
1584 | | "Return a new datetime representing UTC day and time."); |
1585 | | |
1586 | | #define DATETIME_DATETIME_UTCNOW_METHODDEF \ |
1587 | | {"utcnow", (PyCFunction)datetime_datetime_utcnow, METH_NOARGS|METH_CLASS, datetime_datetime_utcnow__doc__}, |
1588 | | |
1589 | | static PyObject * |
1590 | | datetime_datetime_utcnow_impl(PyTypeObject *type); |
1591 | | |
1592 | | static PyObject * |
1593 | | datetime_datetime_utcnow(PyObject *type, PyObject *Py_UNUSED(ignored)) |
1594 | 0 | { |
1595 | 0 | return datetime_datetime_utcnow_impl((PyTypeObject *)type); |
1596 | 0 | } |
1597 | | |
1598 | | PyDoc_STRVAR(datetime_datetime_fromtimestamp__doc__, |
1599 | | "fromtimestamp($type, /, timestamp, tz=None)\n" |
1600 | | "--\n" |
1601 | | "\n" |
1602 | | "Create a datetime from a POSIX timestamp.\n" |
1603 | | "\n" |
1604 | | "The timestamp is a number, e.g. created via time.time(), that is\n" |
1605 | | "interpreted as local time."); |
1606 | | |
1607 | | #define DATETIME_DATETIME_FROMTIMESTAMP_METHODDEF \ |
1608 | | {"fromtimestamp", _PyCFunction_CAST(datetime_datetime_fromtimestamp), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_fromtimestamp__doc__}, |
1609 | | |
1610 | | static PyObject * |
1611 | | datetime_datetime_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp, |
1612 | | PyObject *tzinfo); |
1613 | | |
1614 | | static PyObject * |
1615 | | datetime_datetime_fromtimestamp(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1616 | 0 | { |
1617 | 0 | PyObject *return_value = NULL; |
1618 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1619 | |
|
1620 | 0 | #define NUM_KEYWORDS 2 |
1621 | 0 | static struct { |
1622 | 0 | PyGC_Head _this_is_not_used; |
1623 | 0 | PyObject_VAR_HEAD |
1624 | 0 | Py_hash_t ob_hash; |
1625 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1626 | 0 | } _kwtuple = { |
1627 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1628 | 0 | .ob_hash = -1, |
1629 | 0 | .ob_item = { &_Py_ID(timestamp), &_Py_ID(tz), }, |
1630 | 0 | }; |
1631 | 0 | #undef NUM_KEYWORDS |
1632 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1633 | |
|
1634 | | #else // !Py_BUILD_CORE |
1635 | | # define KWTUPLE NULL |
1636 | | #endif // !Py_BUILD_CORE |
1637 | |
|
1638 | 0 | static const char * const _keywords[] = {"timestamp", "tz", NULL}; |
1639 | 0 | static _PyArg_Parser _parser = { |
1640 | 0 | .keywords = _keywords, |
1641 | 0 | .fname = "fromtimestamp", |
1642 | 0 | .kwtuple = KWTUPLE, |
1643 | 0 | }; |
1644 | 0 | #undef KWTUPLE |
1645 | 0 | PyObject *argsbuf[2]; |
1646 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1647 | 0 | PyObject *timestamp; |
1648 | 0 | PyObject *tzinfo = Py_None; |
1649 | |
|
1650 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1651 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1652 | 0 | if (!args) { |
1653 | 0 | goto exit; |
1654 | 0 | } |
1655 | 0 | timestamp = args[0]; |
1656 | 0 | if (!noptargs) { |
1657 | 0 | goto skip_optional_pos; |
1658 | 0 | } |
1659 | 0 | tzinfo = args[1]; |
1660 | 0 | skip_optional_pos: |
1661 | 0 | return_value = datetime_datetime_fromtimestamp_impl((PyTypeObject *)type, timestamp, tzinfo); |
1662 | |
|
1663 | 0 | exit: |
1664 | 0 | return return_value; |
1665 | 0 | } |
1666 | | |
1667 | | PyDoc_STRVAR(datetime_datetime_utcfromtimestamp__doc__, |
1668 | | "utcfromtimestamp($type, timestamp, /)\n" |
1669 | | "--\n" |
1670 | | "\n" |
1671 | | "Create a naive UTC datetime from a POSIX timestamp."); |
1672 | | |
1673 | | #define DATETIME_DATETIME_UTCFROMTIMESTAMP_METHODDEF \ |
1674 | | {"utcfromtimestamp", (PyCFunction)datetime_datetime_utcfromtimestamp, METH_O|METH_CLASS, datetime_datetime_utcfromtimestamp__doc__}, |
1675 | | |
1676 | | static PyObject * |
1677 | | datetime_datetime_utcfromtimestamp_impl(PyTypeObject *type, |
1678 | | PyObject *timestamp); |
1679 | | |
1680 | | static PyObject * |
1681 | | datetime_datetime_utcfromtimestamp(PyObject *type, PyObject *timestamp) |
1682 | 0 | { |
1683 | 0 | PyObject *return_value = NULL; |
1684 | |
|
1685 | 0 | return_value = datetime_datetime_utcfromtimestamp_impl((PyTypeObject *)type, timestamp); |
1686 | |
|
1687 | 0 | return return_value; |
1688 | 0 | } |
1689 | | |
1690 | | PyDoc_STRVAR(datetime_datetime_strptime__doc__, |
1691 | | "strptime($type, string, format, /)\n" |
1692 | | "--\n" |
1693 | | "\n" |
1694 | | "Parse string according to the given date and time format (like time.strptime()).\n" |
1695 | | "\n" |
1696 | | "For a list of supported format codes, see the documentation:\n" |
1697 | | " https://docs.python.org/3/library/datetime.html#format-codes"); |
1698 | | |
1699 | | #define DATETIME_DATETIME_STRPTIME_METHODDEF \ |
1700 | | {"strptime", _PyCFunction_CAST(datetime_datetime_strptime), METH_FASTCALL|METH_CLASS, datetime_datetime_strptime__doc__}, |
1701 | | |
1702 | | static PyObject * |
1703 | | datetime_datetime_strptime_impl(PyTypeObject *type, PyObject *string, |
1704 | | PyObject *format); |
1705 | | |
1706 | | static PyObject * |
1707 | | datetime_datetime_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs) |
1708 | 0 | { |
1709 | 0 | PyObject *return_value = NULL; |
1710 | 0 | PyObject *string; |
1711 | 0 | PyObject *format; |
1712 | |
|
1713 | 0 | if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) { |
1714 | 0 | goto exit; |
1715 | 0 | } |
1716 | 0 | if (!PyUnicode_Check(args[0])) { |
1717 | 0 | _PyArg_BadArgument("strptime", "argument 1", "str", args[0]); |
1718 | 0 | goto exit; |
1719 | 0 | } |
1720 | 0 | string = args[0]; |
1721 | 0 | if (!PyUnicode_Check(args[1])) { |
1722 | 0 | _PyArg_BadArgument("strptime", "argument 2", "str", args[1]); |
1723 | 0 | goto exit; |
1724 | 0 | } |
1725 | 0 | format = args[1]; |
1726 | 0 | return_value = datetime_datetime_strptime_impl((PyTypeObject *)type, string, format); |
1727 | |
|
1728 | 0 | exit: |
1729 | 0 | return return_value; |
1730 | 0 | } |
1731 | | |
1732 | | PyDoc_STRVAR(datetime_datetime_combine__doc__, |
1733 | | "combine($type, /, date, time, tzinfo=<unrepresentable>)\n" |
1734 | | "--\n" |
1735 | | "\n" |
1736 | | "Construct a datetime from a given date and a given time."); |
1737 | | |
1738 | | #define DATETIME_DATETIME_COMBINE_METHODDEF \ |
1739 | | {"combine", _PyCFunction_CAST(datetime_datetime_combine), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_combine__doc__}, |
1740 | | |
1741 | | static PyObject * |
1742 | | datetime_datetime_combine_impl(PyTypeObject *type, PyObject *date, |
1743 | | PyObject *time, PyObject *tzinfo); |
1744 | | |
1745 | | static PyObject * |
1746 | | datetime_datetime_combine(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1747 | 0 | { |
1748 | 0 | PyObject *return_value = NULL; |
1749 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1750 | |
|
1751 | 0 | #define NUM_KEYWORDS 3 |
1752 | 0 | static struct { |
1753 | 0 | PyGC_Head _this_is_not_used; |
1754 | 0 | PyObject_VAR_HEAD |
1755 | 0 | Py_hash_t ob_hash; |
1756 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1757 | 0 | } _kwtuple = { |
1758 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1759 | 0 | .ob_hash = -1, |
1760 | 0 | .ob_item = { &_Py_ID(date), &_Py_ID(time), &_Py_ID(tzinfo), }, |
1761 | 0 | }; |
1762 | 0 | #undef NUM_KEYWORDS |
1763 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1764 | |
|
1765 | | #else // !Py_BUILD_CORE |
1766 | | # define KWTUPLE NULL |
1767 | | #endif // !Py_BUILD_CORE |
1768 | |
|
1769 | 0 | static const char * const _keywords[] = {"date", "time", "tzinfo", NULL}; |
1770 | 0 | static _PyArg_Parser _parser = { |
1771 | 0 | .keywords = _keywords, |
1772 | 0 | .fname = "combine", |
1773 | 0 | .kwtuple = KWTUPLE, |
1774 | 0 | }; |
1775 | 0 | #undef KWTUPLE |
1776 | 0 | PyObject *argsbuf[3]; |
1777 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1778 | 0 | PyObject *date; |
1779 | 0 | PyObject *time; |
1780 | 0 | PyObject *tzinfo = NULL; |
1781 | |
|
1782 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1783 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1784 | 0 | if (!args) { |
1785 | 0 | goto exit; |
1786 | 0 | } |
1787 | 0 | if (!PyObject_TypeCheck(args[0], DATE_TYPE(NO_STATE))) { |
1788 | 0 | _PyArg_BadArgument("combine", "argument 'date'", (DATE_TYPE(NO_STATE))->tp_name, args[0]); |
1789 | 0 | goto exit; |
1790 | 0 | } |
1791 | 0 | date = args[0]; |
1792 | 0 | if (!PyObject_TypeCheck(args[1], TIME_TYPE(NO_STATE))) { |
1793 | 0 | _PyArg_BadArgument("combine", "argument 'time'", (TIME_TYPE(NO_STATE))->tp_name, args[1]); |
1794 | 0 | goto exit; |
1795 | 0 | } |
1796 | 0 | time = args[1]; |
1797 | 0 | if (!noptargs) { |
1798 | 0 | goto skip_optional_pos; |
1799 | 0 | } |
1800 | 0 | tzinfo = args[2]; |
1801 | 0 | skip_optional_pos: |
1802 | 0 | return_value = datetime_datetime_combine_impl((PyTypeObject *)type, date, time, tzinfo); |
1803 | |
|
1804 | 0 | exit: |
1805 | 0 | return return_value; |
1806 | 0 | } |
1807 | | |
1808 | | PyDoc_STRVAR(datetime_datetime_fromisoformat__doc__, |
1809 | | "fromisoformat($type, string, /)\n" |
1810 | | "--\n" |
1811 | | "\n" |
1812 | | "Construct a date from a string in ISO 8601 format."); |
1813 | | |
1814 | | #define DATETIME_DATETIME_FROMISOFORMAT_METHODDEF \ |
1815 | | {"fromisoformat", (PyCFunction)datetime_datetime_fromisoformat, METH_O|METH_CLASS, datetime_datetime_fromisoformat__doc__}, |
1816 | | |
1817 | | static PyObject * |
1818 | | datetime_datetime_fromisoformat_impl(PyTypeObject *type, PyObject *string); |
1819 | | |
1820 | | static PyObject * |
1821 | | datetime_datetime_fromisoformat(PyObject *type, PyObject *arg) |
1822 | 0 | { |
1823 | 0 | PyObject *return_value = NULL; |
1824 | 0 | PyObject *string; |
1825 | |
|
1826 | 0 | if (!PyUnicode_Check(arg)) { |
1827 | 0 | _PyArg_BadArgument("fromisoformat", "argument", "str", arg); |
1828 | 0 | goto exit; |
1829 | 0 | } |
1830 | 0 | string = arg; |
1831 | 0 | return_value = datetime_datetime_fromisoformat_impl((PyTypeObject *)type, string); |
1832 | |
|
1833 | 0 | exit: |
1834 | 0 | return return_value; |
1835 | 0 | } |
1836 | | |
1837 | | PyDoc_STRVAR(datetime_datetime_isoformat__doc__, |
1838 | | "isoformat($self, /, sep=\'T\', timespec=\'auto\')\n" |
1839 | | "--\n" |
1840 | | "\n" |
1841 | | "Return the time formatted according to ISO.\n" |
1842 | | "\n" |
1843 | | "The full format looks like \'YYYY-MM-DD HH:MM:SS.mmmmmm\'.\n" |
1844 | | "By default, the fractional part is omitted if self.microsecond == 0.\n" |
1845 | | "\n" |
1846 | | "If self.tzinfo is not None, the UTC offset is also attached, giving\n" |
1847 | | "a full format of \'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM\'.\n" |
1848 | | "\n" |
1849 | | "Optional argument sep specifies the separator between date and\n" |
1850 | | "time, default \'T\'.\n" |
1851 | | "\n" |
1852 | | "The optional argument timespec specifies the number of additional\n" |
1853 | | "terms of the time to include. Valid options are \'auto\', \'hours\',\n" |
1854 | | "\'minutes\', \'seconds\', \'milliseconds\' and \'microseconds\'."); |
1855 | | |
1856 | | #define DATETIME_DATETIME_ISOFORMAT_METHODDEF \ |
1857 | | {"isoformat", _PyCFunction_CAST(datetime_datetime_isoformat), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_isoformat__doc__}, |
1858 | | |
1859 | | static PyObject * |
1860 | | datetime_datetime_isoformat_impl(PyDateTime_DateTime *self, int sep, |
1861 | | const char *timespec); |
1862 | | |
1863 | | static PyObject * |
1864 | | datetime_datetime_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1865 | 0 | { |
1866 | 0 | PyObject *return_value = NULL; |
1867 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1868 | |
|
1869 | 0 | #define NUM_KEYWORDS 2 |
1870 | 0 | static struct { |
1871 | 0 | PyGC_Head _this_is_not_used; |
1872 | 0 | PyObject_VAR_HEAD |
1873 | 0 | Py_hash_t ob_hash; |
1874 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1875 | 0 | } _kwtuple = { |
1876 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1877 | 0 | .ob_hash = -1, |
1878 | 0 | .ob_item = { &_Py_ID(sep), &_Py_ID(timespec), }, |
1879 | 0 | }; |
1880 | 0 | #undef NUM_KEYWORDS |
1881 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1882 | |
|
1883 | | #else // !Py_BUILD_CORE |
1884 | | # define KWTUPLE NULL |
1885 | | #endif // !Py_BUILD_CORE |
1886 | |
|
1887 | 0 | static const char * const _keywords[] = {"sep", "timespec", NULL}; |
1888 | 0 | static _PyArg_Parser _parser = { |
1889 | 0 | .keywords = _keywords, |
1890 | 0 | .fname = "isoformat", |
1891 | 0 | .kwtuple = KWTUPLE, |
1892 | 0 | }; |
1893 | 0 | #undef KWTUPLE |
1894 | 0 | PyObject *argsbuf[2]; |
1895 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1896 | 0 | int sep = 'T'; |
1897 | 0 | const char *timespec = NULL; |
1898 | |
|
1899 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1900 | 0 | /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1901 | 0 | if (!args) { |
1902 | 0 | goto exit; |
1903 | 0 | } |
1904 | 0 | if (!noptargs) { |
1905 | 0 | goto skip_optional_pos; |
1906 | 0 | } |
1907 | 0 | if (args[0]) { |
1908 | 0 | if (!PyUnicode_Check(args[0])) { |
1909 | 0 | _PyArg_BadArgument("isoformat", "argument 'sep'", "a unicode character", args[0]); |
1910 | 0 | goto exit; |
1911 | 0 | } |
1912 | 0 | if (PyUnicode_GET_LENGTH(args[0]) != 1) { |
1913 | 0 | PyErr_Format(PyExc_TypeError, |
1914 | 0 | "isoformat(): argument 'sep' must be a unicode character, " |
1915 | 0 | "not a string of length %zd", |
1916 | 0 | PyUnicode_GET_LENGTH(args[0])); |
1917 | 0 | goto exit; |
1918 | 0 | } |
1919 | 0 | sep = PyUnicode_READ_CHAR(args[0], 0); |
1920 | 0 | if (!--noptargs) { |
1921 | 0 | goto skip_optional_pos; |
1922 | 0 | } |
1923 | 0 | } |
1924 | 0 | if (!PyUnicode_Check(args[1])) { |
1925 | 0 | _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[1]); |
1926 | 0 | goto exit; |
1927 | 0 | } |
1928 | 0 | timespec = _PyUnicode_AsUTF8NoNUL(args[1]); |
1929 | 0 | if (timespec == NULL) { |
1930 | 0 | goto exit; |
1931 | 0 | } |
1932 | 0 | skip_optional_pos: |
1933 | 0 | return_value = datetime_datetime_isoformat_impl((PyDateTime_DateTime *)self, sep, timespec); |
1934 | |
|
1935 | 0 | exit: |
1936 | 0 | return return_value; |
1937 | 0 | } |
1938 | | |
1939 | | PyDoc_STRVAR(datetime_datetime_replace__doc__, |
1940 | | "replace($self, /, year=unchanged, month=unchanged, day=unchanged,\n" |
1941 | | " hour=unchanged, minute=unchanged, second=unchanged,\n" |
1942 | | " microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n" |
1943 | | "--\n" |
1944 | | "\n" |
1945 | | "Return datetime with new specified fields."); |
1946 | | |
1947 | | #define DATETIME_DATETIME_REPLACE_METHODDEF \ |
1948 | | {"replace", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_replace__doc__}, |
1949 | | |
1950 | | static PyObject * |
1951 | | datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year, |
1952 | | int month, int day, int hour, int minute, |
1953 | | int second, int microsecond, PyObject *tzinfo, |
1954 | | int fold); |
1955 | | |
1956 | | static PyObject * |
1957 | | datetime_datetime_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1958 | 0 | { |
1959 | 0 | PyObject *return_value = NULL; |
1960 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1961 | |
|
1962 | 0 | #define NUM_KEYWORDS 9 |
1963 | 0 | static struct { |
1964 | 0 | PyGC_Head _this_is_not_used; |
1965 | 0 | PyObject_VAR_HEAD |
1966 | 0 | Py_hash_t ob_hash; |
1967 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1968 | 0 | } _kwtuple = { |
1969 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1970 | 0 | .ob_hash = -1, |
1971 | 0 | .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), }, |
1972 | 0 | }; |
1973 | 0 | #undef NUM_KEYWORDS |
1974 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1975 | |
|
1976 | | #else // !Py_BUILD_CORE |
1977 | | # define KWTUPLE NULL |
1978 | | #endif // !Py_BUILD_CORE |
1979 | |
|
1980 | 0 | static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL}; |
1981 | 0 | static _PyArg_Parser _parser = { |
1982 | 0 | .keywords = _keywords, |
1983 | 0 | .fname = "replace", |
1984 | 0 | .kwtuple = KWTUPLE, |
1985 | 0 | }; |
1986 | 0 | #undef KWTUPLE |
1987 | 0 | PyObject *argsbuf[9]; |
1988 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1989 | 0 | int year = GET_YEAR(self); |
1990 | 0 | int month = GET_MONTH(self); |
1991 | 0 | int day = GET_DAY(self); |
1992 | 0 | int hour = DATE_GET_HOUR(self); |
1993 | 0 | int minute = DATE_GET_MINUTE(self); |
1994 | 0 | int second = DATE_GET_SECOND(self); |
1995 | 0 | int microsecond = DATE_GET_MICROSECOND(self); |
1996 | 0 | PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None; |
1997 | 0 | int fold = DATE_GET_FOLD(self); |
1998 | |
|
1999 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2000 | 0 | /*minpos*/ 0, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2001 | 0 | if (!args) { |
2002 | 0 | goto exit; |
2003 | 0 | } |
2004 | 0 | if (!noptargs) { |
2005 | 0 | goto skip_optional_pos; |
2006 | 0 | } |
2007 | 0 | if (args[0]) { |
2008 | 0 | year = PyLong_AsInt(args[0]); |
2009 | 0 | if (year == -1 && PyErr_Occurred()) { |
2010 | 0 | goto exit; |
2011 | 0 | } |
2012 | 0 | if (!--noptargs) { |
2013 | 0 | goto skip_optional_pos; |
2014 | 0 | } |
2015 | 0 | } |
2016 | 0 | if (args[1]) { |
2017 | 0 | month = PyLong_AsInt(args[1]); |
2018 | 0 | if (month == -1 && PyErr_Occurred()) { |
2019 | 0 | goto exit; |
2020 | 0 | } |
2021 | 0 | if (!--noptargs) { |
2022 | 0 | goto skip_optional_pos; |
2023 | 0 | } |
2024 | 0 | } |
2025 | 0 | if (args[2]) { |
2026 | 0 | day = PyLong_AsInt(args[2]); |
2027 | 0 | if (day == -1 && PyErr_Occurred()) { |
2028 | 0 | goto exit; |
2029 | 0 | } |
2030 | 0 | if (!--noptargs) { |
2031 | 0 | goto skip_optional_pos; |
2032 | 0 | } |
2033 | 0 | } |
2034 | 0 | if (args[3]) { |
2035 | 0 | hour = PyLong_AsInt(args[3]); |
2036 | 0 | if (hour == -1 && PyErr_Occurred()) { |
2037 | 0 | goto exit; |
2038 | 0 | } |
2039 | 0 | if (!--noptargs) { |
2040 | 0 | goto skip_optional_pos; |
2041 | 0 | } |
2042 | 0 | } |
2043 | 0 | if (args[4]) { |
2044 | 0 | minute = PyLong_AsInt(args[4]); |
2045 | 0 | if (minute == -1 && PyErr_Occurred()) { |
2046 | 0 | goto exit; |
2047 | 0 | } |
2048 | 0 | if (!--noptargs) { |
2049 | 0 | goto skip_optional_pos; |
2050 | 0 | } |
2051 | 0 | } |
2052 | 0 | if (args[5]) { |
2053 | 0 | second = PyLong_AsInt(args[5]); |
2054 | 0 | if (second == -1 && PyErr_Occurred()) { |
2055 | 0 | goto exit; |
2056 | 0 | } |
2057 | 0 | if (!--noptargs) { |
2058 | 0 | goto skip_optional_pos; |
2059 | 0 | } |
2060 | 0 | } |
2061 | 0 | if (args[6]) { |
2062 | 0 | microsecond = PyLong_AsInt(args[6]); |
2063 | 0 | if (microsecond == -1 && PyErr_Occurred()) { |
2064 | 0 | goto exit; |
2065 | 0 | } |
2066 | 0 | if (!--noptargs) { |
2067 | 0 | goto skip_optional_pos; |
2068 | 0 | } |
2069 | 0 | } |
2070 | 0 | if (args[7]) { |
2071 | 0 | tzinfo = args[7]; |
2072 | 0 | if (!--noptargs) { |
2073 | 0 | goto skip_optional_pos; |
2074 | 0 | } |
2075 | 0 | } |
2076 | 0 | skip_optional_pos: |
2077 | 0 | if (!noptargs) { |
2078 | 0 | goto skip_optional_kwonly; |
2079 | 0 | } |
2080 | 0 | fold = PyLong_AsInt(args[8]); |
2081 | 0 | if (fold == -1 && PyErr_Occurred()) { |
2082 | 0 | goto exit; |
2083 | 0 | } |
2084 | 0 | skip_optional_kwonly: |
2085 | 0 | return_value = datetime_datetime_replace_impl((PyDateTime_DateTime *)self, year, month, day, hour, minute, second, microsecond, tzinfo, fold); |
2086 | |
|
2087 | 0 | exit: |
2088 | 0 | return return_value; |
2089 | 0 | } |
2090 | | |
2091 | | PyDoc_STRVAR(datetime_datetime_astimezone__doc__, |
2092 | | "astimezone($self, /, tz=None)\n" |
2093 | | "--\n" |
2094 | | "\n" |
2095 | | "Convert to local time in new timezone tz."); |
2096 | | |
2097 | | #define DATETIME_DATETIME_ASTIMEZONE_METHODDEF \ |
2098 | | {"astimezone", _PyCFunction_CAST(datetime_datetime_astimezone), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_astimezone__doc__}, |
2099 | | |
2100 | | static PyObject * |
2101 | | datetime_datetime_astimezone_impl(PyDateTime_DateTime *self, |
2102 | | PyObject *tzinfo); |
2103 | | |
2104 | | static PyObject * |
2105 | | datetime_datetime_astimezone(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2106 | 0 | { |
2107 | 0 | PyObject *return_value = NULL; |
2108 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2109 | |
|
2110 | 0 | #define NUM_KEYWORDS 1 |
2111 | 0 | static struct { |
2112 | 0 | PyGC_Head _this_is_not_used; |
2113 | 0 | PyObject_VAR_HEAD |
2114 | 0 | Py_hash_t ob_hash; |
2115 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2116 | 0 | } _kwtuple = { |
2117 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2118 | 0 | .ob_hash = -1, |
2119 | 0 | .ob_item = { &_Py_ID(tz), }, |
2120 | 0 | }; |
2121 | 0 | #undef NUM_KEYWORDS |
2122 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2123 | |
|
2124 | | #else // !Py_BUILD_CORE |
2125 | | # define KWTUPLE NULL |
2126 | | #endif // !Py_BUILD_CORE |
2127 | |
|
2128 | 0 | static const char * const _keywords[] = {"tz", NULL}; |
2129 | 0 | static _PyArg_Parser _parser = { |
2130 | 0 | .keywords = _keywords, |
2131 | 0 | .fname = "astimezone", |
2132 | 0 | .kwtuple = KWTUPLE, |
2133 | 0 | }; |
2134 | 0 | #undef KWTUPLE |
2135 | 0 | PyObject *argsbuf[1]; |
2136 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
2137 | 0 | PyObject *tzinfo = Py_None; |
2138 | |
|
2139 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2140 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2141 | 0 | if (!args) { |
2142 | 0 | goto exit; |
2143 | 0 | } |
2144 | 0 | if (!noptargs) { |
2145 | 0 | goto skip_optional_pos; |
2146 | 0 | } |
2147 | 0 | tzinfo = args[0]; |
2148 | 0 | skip_optional_pos: |
2149 | 0 | return_value = datetime_datetime_astimezone_impl((PyDateTime_DateTime *)self, tzinfo); |
2150 | |
|
2151 | 0 | exit: |
2152 | 0 | return return_value; |
2153 | 0 | } |
2154 | | |
2155 | | PyDoc_STRVAR(datetime_datetime___reduce_ex____doc__, |
2156 | | "__reduce_ex__($self, proto, /)\n" |
2157 | | "--\n" |
2158 | | "\n"); |
2159 | | |
2160 | | #define DATETIME_DATETIME___REDUCE_EX___METHODDEF \ |
2161 | | {"__reduce_ex__", (PyCFunction)datetime_datetime___reduce_ex__, METH_O, datetime_datetime___reduce_ex____doc__}, |
2162 | | |
2163 | | static PyObject * |
2164 | | datetime_datetime___reduce_ex___impl(PyDateTime_DateTime *self, int proto); |
2165 | | |
2166 | | static PyObject * |
2167 | | datetime_datetime___reduce_ex__(PyObject *self, PyObject *arg) |
2168 | 0 | { |
2169 | 0 | PyObject *return_value = NULL; |
2170 | 0 | int proto; |
2171 | |
|
2172 | 0 | proto = PyLong_AsInt(arg); |
2173 | 0 | if (proto == -1 && PyErr_Occurred()) { |
2174 | 0 | goto exit; |
2175 | 0 | } |
2176 | 0 | return_value = datetime_datetime___reduce_ex___impl((PyDateTime_DateTime *)self, proto); |
2177 | |
|
2178 | 0 | exit: |
2179 | 0 | return return_value; |
2180 | 0 | } |
2181 | | |
2182 | | PyDoc_STRVAR(datetime_datetime___reduce____doc__, |
2183 | | "__reduce__($self, /)\n" |
2184 | | "--\n" |
2185 | | "\n"); |
2186 | | |
2187 | | #define DATETIME_DATETIME___REDUCE___METHODDEF \ |
2188 | | {"__reduce__", (PyCFunction)datetime_datetime___reduce__, METH_NOARGS, datetime_datetime___reduce____doc__}, |
2189 | | |
2190 | | static PyObject * |
2191 | | datetime_datetime___reduce___impl(PyDateTime_DateTime *self); |
2192 | | |
2193 | | static PyObject * |
2194 | | datetime_datetime___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
2195 | 0 | { |
2196 | 0 | return datetime_datetime___reduce___impl((PyDateTime_DateTime *)self); |
2197 | 0 | } |
2198 | | /*[clinic end generated code: output=380121f4e088e032 input=a9049054013a1b77]*/ |