Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_contextvars_Context_get__doc__, |
| 6 | "get($self, key, default=None, /)\n" |
| 7 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 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."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 13 | |
| 14 | #define _CONTEXTVARS_CONTEXT_GET_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 15 | {"get", (PyCFunction)(void(*)(void))_contextvars_Context_get, METH_FASTCALL, _contextvars_Context_get__doc__}, |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 16 | |
| 17 | static PyObject * |
| 18 | _contextvars_Context_get_impl(PyContext *self, PyObject *key, |
| 19 | PyObject *default_value); |
| 20 | |
| 21 | static 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 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 28 | if (!_PyArg_CheckPositional("get", nargs, 1, 2)) { |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 29 | goto exit; |
| 30 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 31 | key = args[0]; |
| 32 | if (nargs < 2) { |
| 33 | goto skip_optional; |
| 34 | } |
| 35 | default_value = args[1]; |
| 36 | skip_optional: |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 37 | return_value = _contextvars_Context_get_impl(self, key, default_value); |
| 38 | |
| 39 | exit: |
| 40 | return return_value; |
| 41 | } |
| 42 | |
| 43 | PyDoc_STRVAR(_contextvars_Context_items__doc__, |
| 44 | "items($self, /)\n" |
| 45 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 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)."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 50 | |
| 51 | #define _CONTEXTVARS_CONTEXT_ITEMS_METHODDEF \ |
| 52 | {"items", (PyCFunction)_contextvars_Context_items, METH_NOARGS, _contextvars_Context_items__doc__}, |
| 53 | |
| 54 | static PyObject * |
| 55 | _contextvars_Context_items_impl(PyContext *self); |
| 56 | |
| 57 | static PyObject * |
| 58 | _contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 59 | { |
| 60 | return _contextvars_Context_items_impl(self); |
| 61 | } |
| 62 | |
| 63 | PyDoc_STRVAR(_contextvars_Context_keys__doc__, |
| 64 | "keys($self, /)\n" |
| 65 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 66 | "\n" |
| 67 | "Return a list of all variables in the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 68 | |
| 69 | #define _CONTEXTVARS_CONTEXT_KEYS_METHODDEF \ |
| 70 | {"keys", (PyCFunction)_contextvars_Context_keys, METH_NOARGS, _contextvars_Context_keys__doc__}, |
| 71 | |
| 72 | static PyObject * |
| 73 | _contextvars_Context_keys_impl(PyContext *self); |
| 74 | |
| 75 | static PyObject * |
| 76 | _contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 77 | { |
| 78 | return _contextvars_Context_keys_impl(self); |
| 79 | } |
| 80 | |
| 81 | PyDoc_STRVAR(_contextvars_Context_values__doc__, |
| 82 | "values($self, /)\n" |
| 83 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 84 | "\n" |
animalize | 463572c | 2019-02-25 07:18:48 +0800 | [diff] [blame] | 85 | "Return a list of all variables\' values in the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 86 | |
| 87 | #define _CONTEXTVARS_CONTEXT_VALUES_METHODDEF \ |
| 88 | {"values", (PyCFunction)_contextvars_Context_values, METH_NOARGS, _contextvars_Context_values__doc__}, |
| 89 | |
| 90 | static PyObject * |
| 91 | _contextvars_Context_values_impl(PyContext *self); |
| 92 | |
| 93 | static PyObject * |
| 94 | _contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 95 | { |
| 96 | return _contextvars_Context_values_impl(self); |
| 97 | } |
| 98 | |
| 99 | PyDoc_STRVAR(_contextvars_Context_copy__doc__, |
| 100 | "copy($self, /)\n" |
| 101 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 102 | "\n" |
| 103 | "Return a shallow copy of the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 104 | |
| 105 | #define _CONTEXTVARS_CONTEXT_COPY_METHODDEF \ |
| 106 | {"copy", (PyCFunction)_contextvars_Context_copy, METH_NOARGS, _contextvars_Context_copy__doc__}, |
| 107 | |
| 108 | static PyObject * |
| 109 | _contextvars_Context_copy_impl(PyContext *self); |
| 110 | |
| 111 | static PyObject * |
| 112 | _contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 113 | { |
| 114 | return _contextvars_Context_copy_impl(self); |
| 115 | } |
| 116 | |
| 117 | PyDoc_STRVAR(_contextvars_ContextVar_get__doc__, |
| 118 | "get($self, default=None, /)\n" |
| 119 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 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."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 128 | |
| 129 | #define _CONTEXTVARS_CONTEXTVAR_GET_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 130 | {"get", (PyCFunction)(void(*)(void))_contextvars_ContextVar_get, METH_FASTCALL, _contextvars_ContextVar_get__doc__}, |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 131 | |
| 132 | static PyObject * |
| 133 | _contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value); |
| 134 | |
| 135 | static 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 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 141 | if (!_PyArg_CheckPositional("get", nargs, 0, 1)) { |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 142 | goto exit; |
| 143 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 144 | if (nargs < 1) { |
| 145 | goto skip_optional; |
| 146 | } |
| 147 | default_value = args[0]; |
| 148 | skip_optional: |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 149 | return_value = _contextvars_ContextVar_get_impl(self, default_value); |
| 150 | |
| 151 | exit: |
| 152 | return return_value; |
| 153 | } |
| 154 | |
| 155 | PyDoc_STRVAR(_contextvars_ContextVar_set__doc__, |
| 156 | "set($self, value, /)\n" |
| 157 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 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."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 165 | |
| 166 | #define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF \ |
| 167 | {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__}, |
| 168 | |
| 169 | PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__, |
| 170 | "reset($self, token, /)\n" |
| 171 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 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."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 177 | |
| 178 | #define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \ |
| 179 | {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__}, |
animalize | 463572c | 2019-02-25 07:18:48 +0800 | [diff] [blame] | 180 | /*[clinic end generated code: output=a86b66e1516c25d4 input=a9049054013a1b77]*/ |