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
10
11 PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
12 "fromtimestamp($type, timestamp, /)\n"
13 "--\n"
14 "\n"
15 "Create a date from a POSIX timestamp.\n"
16 "\n"
17 "The timestamp is a number, e.g. created via time.time(), that is interpreted\n"
18 "as local time.");
19
20 #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \
21 {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
22
23 static PyObject *
24 iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
25 int weekday);
26
27 static PyObject *
28 iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
29 {
30 PyObject *return_value = NULL;
31 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
32
33 #define NUM_KEYWORDS 3
34 static struct {
35 PyGC_Head _this_is_not_used;
36 PyObject_VAR_HEAD
37 PyObject *ob_item[NUM_KEYWORDS];
38 } _kwtuple = {
39 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
40 .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(weekday), },
41 };
42 #undef NUM_KEYWORDS
43 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
44
45 #else // !Py_BUILD_CORE
46 # define KWTUPLE NULL
47 #endif // !Py_BUILD_CORE
48
49 static const char * const _keywords[] = {"year", "week", "weekday", NULL};
50 static _PyArg_Parser _parser = {
51 .keywords = _keywords,
52 .fname = "IsoCalendarDate",
53 .kwtuple = KWTUPLE,
54 };
55 #undef KWTUPLE
56 PyObject *argsbuf[3];
57 PyObject * const *fastargs;
58 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
59 int year;
60 int week;
61 int weekday;
62
63 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 3, 3, 0, argsbuf);
64 if (!fastargs) {
65 goto exit;
66 }
67 year = _PyLong_AsInt(fastargs[0]);
68 if (year == -1 && PyErr_Occurred()) {
69 goto exit;
70 }
71 week = _PyLong_AsInt(fastargs[1]);
72 if (week == -1 && PyErr_Occurred()) {
73 goto exit;
74 }
75 weekday = _PyLong_AsInt(fastargs[2]);
76 if (weekday == -1 && PyErr_Occurred()) {
77 goto exit;
78 }
79 return_value = iso_calendar_date_new_impl(type, year, week, weekday);
80
81 exit:
82 return return_value;
83 }
84
85 PyDoc_STRVAR(datetime_datetime_now__doc__,
86 "now($type, /, tz=None)\n"
87 "--\n"
88 "\n"
89 "Returns new datetime object representing current time local to tz.\n"
90 "\n"
91 " tz\n"
92 " Timezone object.\n"
93 "\n"
94 "If no tz is specified, uses local timezone.");
95
96 #define DATETIME_DATETIME_NOW_METHODDEF \
97 {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
98
99 static PyObject *
100 datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
101
102 static PyObject *
103 datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
104 {
105 PyObject *return_value = NULL;
106 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
107
108 #define NUM_KEYWORDS 1
109 static struct {
110 PyGC_Head _this_is_not_used;
111 PyObject_VAR_HEAD
112 PyObject *ob_item[NUM_KEYWORDS];
113 } _kwtuple = {
114 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
115 .ob_item = { &_Py_ID(tz), },
116 };
117 #undef NUM_KEYWORDS
118 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
119
120 #else // !Py_BUILD_CORE
121 # define KWTUPLE NULL
122 #endif // !Py_BUILD_CORE
123
124 static const char * const _keywords[] = {"tz", NULL};
125 static _PyArg_Parser _parser = {
126 .keywords = _keywords,
127 .fname = "now",
128 .kwtuple = KWTUPLE,
129 };
130 #undef KWTUPLE
131 PyObject *argsbuf[1];
132 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
133 PyObject *tz = Py_None;
134
135 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
136 if (!args) {
137 goto exit;
138 }
139 if (!noptargs) {
140 goto skip_optional_pos;
141 }
142 tz = args[0];
143 skip_optional_pos:
144 return_value = datetime_datetime_now_impl(type, tz);
145
146 exit:
147 return return_value;
148 }
149 /*[clinic end generated code: output=42654669940e0e3a input=a9049054013a1b77]*/