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