blob: 683b9d7902f7ed299e8ffdaefc0e58297fd99311 [file] [log] [blame]
Yury Selivanovf23746a2018-01-22 19:11:18 -05001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_contextvars_Context_get__doc__,
6"get($self, key, default=None, /)\n"
7"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +01008"\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.");
Yury Selivanovf23746a2018-01-22 19:11:18 -050013
14#define _CONTEXTVARS_CONTEXT_GET_METHODDEF \
15 {"get", (PyCFunction)_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_UnpackStack(args, nargs, "get",
29 1, 2,
30 &key, &default_value)) {
31 goto exit;
32 }
33 return_value = _contextvars_Context_get_impl(self, key, default_value);
34
35exit:
36 return return_value;
37}
38
39PyDoc_STRVAR(_contextvars_Context_items__doc__,
40"items($self, /)\n"
41"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +010042"\n"
43"Return all variables and their values in the context object.\n"
44"\n"
45"The result is returned as a list of 2-tuples (variable, value).");
Yury Selivanovf23746a2018-01-22 19:11:18 -050046
47#define _CONTEXTVARS_CONTEXT_ITEMS_METHODDEF \
48 {"items", (PyCFunction)_contextvars_Context_items, METH_NOARGS, _contextvars_Context_items__doc__},
49
50static PyObject *
51_contextvars_Context_items_impl(PyContext *self);
52
53static PyObject *
54_contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored))
55{
56 return _contextvars_Context_items_impl(self);
57}
58
59PyDoc_STRVAR(_contextvars_Context_keys__doc__,
60"keys($self, /)\n"
61"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +010062"\n"
63"Return a list of all variables in the context object.");
Yury Selivanovf23746a2018-01-22 19:11:18 -050064
65#define _CONTEXTVARS_CONTEXT_KEYS_METHODDEF \
66 {"keys", (PyCFunction)_contextvars_Context_keys, METH_NOARGS, _contextvars_Context_keys__doc__},
67
68static PyObject *
69_contextvars_Context_keys_impl(PyContext *self);
70
71static PyObject *
72_contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored))
73{
74 return _contextvars_Context_keys_impl(self);
75}
76
77PyDoc_STRVAR(_contextvars_Context_values__doc__,
78"values($self, /)\n"
79"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +010080"\n"
81"Return a list of all variables’ values in the context object.");
Yury Selivanovf23746a2018-01-22 19:11:18 -050082
83#define _CONTEXTVARS_CONTEXT_VALUES_METHODDEF \
84 {"values", (PyCFunction)_contextvars_Context_values, METH_NOARGS, _contextvars_Context_values__doc__},
85
86static PyObject *
87_contextvars_Context_values_impl(PyContext *self);
88
89static PyObject *
90_contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored))
91{
92 return _contextvars_Context_values_impl(self);
93}
94
95PyDoc_STRVAR(_contextvars_Context_copy__doc__,
96"copy($self, /)\n"
97"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +010098"\n"
99"Return a shallow copy of the context object.");
Yury Selivanovf23746a2018-01-22 19:11:18 -0500100
101#define _CONTEXTVARS_CONTEXT_COPY_METHODDEF \
102 {"copy", (PyCFunction)_contextvars_Context_copy, METH_NOARGS, _contextvars_Context_copy__doc__},
103
104static PyObject *
105_contextvars_Context_copy_impl(PyContext *self);
106
107static PyObject *
108_contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored))
109{
110 return _contextvars_Context_copy_impl(self);
111}
112
113PyDoc_STRVAR(_contextvars_ContextVar_get__doc__,
114"get($self, default=None, /)\n"
115"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +0100116"\n"
117"Return a value for the context variable for the current context.\n"
118"\n"
119"If there is no value for the variable in the current context, the method will:\n"
120" * return the value of the default argument of the method, if provided; or\n"
121" * return the default value for the context variable, if it was created\n"
122" with one; or\n"
123" * raise a LookupError.");
Yury Selivanovf23746a2018-01-22 19:11:18 -0500124
125#define _CONTEXTVARS_CONTEXTVAR_GET_METHODDEF \
126 {"get", (PyCFunction)_contextvars_ContextVar_get, METH_FASTCALL, _contextvars_ContextVar_get__doc__},
127
128static PyObject *
129_contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value);
130
131static PyObject *
132_contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_t nargs)
133{
134 PyObject *return_value = NULL;
135 PyObject *default_value = NULL;
136
137 if (!_PyArg_UnpackStack(args, nargs, "get",
138 0, 1,
139 &default_value)) {
140 goto exit;
141 }
142 return_value = _contextvars_ContextVar_get_impl(self, default_value);
143
144exit:
145 return return_value;
146}
147
148PyDoc_STRVAR(_contextvars_ContextVar_set__doc__,
149"set($self, value, /)\n"
150"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +0100151"\n"
152"Call to set a new value for the context variable in the current context.\n"
153"\n"
154"The required value argument is the new value for the context variable.\n"
155"\n"
156"Returns a Token object that can be used to restore the variable to its previous\n"
157"value via the `ContextVar.reset()` method.");
Yury Selivanovf23746a2018-01-22 19:11:18 -0500158
159#define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF \
160 {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__},
161
162PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__,
163"reset($self, token, /)\n"
164"--\n"
Peter Lamut20678fd2018-07-30 16:15:44 +0100165"\n"
166"Reset the context variable.\n"
167"\n"
168"The variable is reset to the value it had before the `ContextVar.set()` that\n"
169"created the token was used.");
Yury Selivanovf23746a2018-01-22 19:11:18 -0500170
171#define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \
172 {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__},
Peter Lamut20678fd2018-07-30 16:15:44 +0100173/*[clinic end generated code: output=33414d13716d0648 input=a9049054013a1b77]*/