1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_contextvars_Context_get__doc__,
6"get($self, key, default=None, /)\n"
7"--\n"
8"\n"
9"Return the value for `key` if `key` has the value in the context object.\n"
10"\n"
11"If `key` does not exist, return `default`. If `default` is not given,\n"
12"return None.");
13
14#define _CONTEXTVARS_CONTEXT_GET_METHODDEF    \
15    {"get", _PyCFunction_CAST(_contextvars_Context_get), METH_FASTCALL, _contextvars_Context_get__doc__},
16
17static PyObject *
18_contextvars_Context_get_impl(PyContext *self, PyObject *key,
19                              PyObject *default_value);
20
21static PyObject *
22_contextvars_Context_get(PyContext *self, PyObject *const *args, Py_ssize_t nargs)
23{
24    PyObject *return_value = NULL;
25    PyObject *key;
26    PyObject *default_value = Py_None;
27
28    if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
29        goto exit;
30    }
31    key = args[0];
32    if (nargs < 2) {
33        goto skip_optional;
34    }
35    default_value = args[1];
36skip_optional:
37    return_value = _contextvars_Context_get_impl(self, key, default_value);
38
39exit:
40    return return_value;
41}
42
43PyDoc_STRVAR(_contextvars_Context_items__doc__,
44"items($self, /)\n"
45"--\n"
46"\n"
47"Return all variables and their values in the context object.\n"
48"\n"
49"The result is returned as a list of 2-tuples (variable, value).");
50
51#define _CONTEXTVARS_CONTEXT_ITEMS_METHODDEF    \
52    {"items", (PyCFunction)_contextvars_Context_items, METH_NOARGS, _contextvars_Context_items__doc__},
53
54static PyObject *
55_contextvars_Context_items_impl(PyContext *self);
56
57static PyObject *
58_contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored))
59{
60    return _contextvars_Context_items_impl(self);
61}
62
63PyDoc_STRVAR(_contextvars_Context_keys__doc__,
64"keys($self, /)\n"
65"--\n"
66"\n"
67"Return a list of all variables in the context object.");
68
69#define _CONTEXTVARS_CONTEXT_KEYS_METHODDEF    \
70    {"keys", (PyCFunction)_contextvars_Context_keys, METH_NOARGS, _contextvars_Context_keys__doc__},
71
72static PyObject *
73_contextvars_Context_keys_impl(PyContext *self);
74
75static PyObject *
76_contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored))
77{
78    return _contextvars_Context_keys_impl(self);
79}
80
81PyDoc_STRVAR(_contextvars_Context_values__doc__,
82"values($self, /)\n"
83"--\n"
84"\n"
85"Return a list of all variables\' values in the context object.");
86
87#define _CONTEXTVARS_CONTEXT_VALUES_METHODDEF    \
88    {"values", (PyCFunction)_contextvars_Context_values, METH_NOARGS, _contextvars_Context_values__doc__},
89
90static PyObject *
91_contextvars_Context_values_impl(PyContext *self);
92
93static PyObject *
94_contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored))
95{
96    return _contextvars_Context_values_impl(self);
97}
98
99PyDoc_STRVAR(_contextvars_Context_copy__doc__,
100"copy($self, /)\n"
101"--\n"
102"\n"
103"Return a shallow copy of the context object.");
104
105#define _CONTEXTVARS_CONTEXT_COPY_METHODDEF    \
106    {"copy", (PyCFunction)_contextvars_Context_copy, METH_NOARGS, _contextvars_Context_copy__doc__},
107
108static PyObject *
109_contextvars_Context_copy_impl(PyContext *self);
110
111static PyObject *
112_contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored))
113{
114    return _contextvars_Context_copy_impl(self);
115}
116
117PyDoc_STRVAR(_contextvars_ContextVar_get__doc__,
118"get($self, default=<unrepresentable>, /)\n"
119"--\n"
120"\n"
121"Return a value for the context variable for the current context.\n"
122"\n"
123"If there is no value for the variable in the current context, the method will:\n"
124" * return the value of the default argument of the method, if provided; or\n"
125" * return the default value for the context variable, if it was created\n"
126"   with one; or\n"
127" * raise a LookupError.");
128
129#define _CONTEXTVARS_CONTEXTVAR_GET_METHODDEF    \
130    {"get", _PyCFunction_CAST(_contextvars_ContextVar_get), METH_FASTCALL, _contextvars_ContextVar_get__doc__},
131
132static PyObject *
133_contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value);
134
135static PyObject *
136_contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_t nargs)
137{
138    PyObject *return_value = NULL;
139    PyObject *default_value = NULL;
140
141    if (!_PyArg_CheckPositional("get", nargs, 0, 1)) {
142        goto exit;
143    }
144    if (nargs < 1) {
145        goto skip_optional;
146    }
147    default_value = args[0];
148skip_optional:
149    return_value = _contextvars_ContextVar_get_impl(self, default_value);
150
151exit:
152    return return_value;
153}
154
155PyDoc_STRVAR(_contextvars_ContextVar_set__doc__,
156"set($self, value, /)\n"
157"--\n"
158"\n"
159"Call to set a new value for the context variable in the current context.\n"
160"\n"
161"The required value argument is the new value for the context variable.\n"
162"\n"
163"Returns a Token object that can be used to restore the variable to its previous\n"
164"value via the `ContextVar.reset()` method.");
165
166#define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF    \
167    {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__},
168
169PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__,
170"reset($self, token, /)\n"
171"--\n"
172"\n"
173"Reset the context variable.\n"
174"\n"
175"The variable is reset to the value it had before the `ContextVar.set()` that\n"
176"created the token was used.");
177
178#define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF    \
179    {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__},
180/*[clinic end generated code: output=2436b16a92452869 input=a9049054013a1b77]*/
181