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 \ |
| 15 | {"get", (PyCFunction)_contextvars_Context_get, METH_FASTCALL, _contextvars_Context_get__doc__}, |
| 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 | |
| 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 | |
| 35 | exit: |
| 36 | return return_value; |
| 37 | } |
| 38 | |
| 39 | PyDoc_STRVAR(_contextvars_Context_items__doc__, |
| 40 | "items($self, /)\n" |
| 41 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 42 | "\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 Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 46 | |
| 47 | #define _CONTEXTVARS_CONTEXT_ITEMS_METHODDEF \ |
| 48 | {"items", (PyCFunction)_contextvars_Context_items, METH_NOARGS, _contextvars_Context_items__doc__}, |
| 49 | |
| 50 | static PyObject * |
| 51 | _contextvars_Context_items_impl(PyContext *self); |
| 52 | |
| 53 | static PyObject * |
| 54 | _contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 55 | { |
| 56 | return _contextvars_Context_items_impl(self); |
| 57 | } |
| 58 | |
| 59 | PyDoc_STRVAR(_contextvars_Context_keys__doc__, |
| 60 | "keys($self, /)\n" |
| 61 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 62 | "\n" |
| 63 | "Return a list of all variables in the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 64 | |
| 65 | #define _CONTEXTVARS_CONTEXT_KEYS_METHODDEF \ |
| 66 | {"keys", (PyCFunction)_contextvars_Context_keys, METH_NOARGS, _contextvars_Context_keys__doc__}, |
| 67 | |
| 68 | static PyObject * |
| 69 | _contextvars_Context_keys_impl(PyContext *self); |
| 70 | |
| 71 | static PyObject * |
| 72 | _contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 73 | { |
| 74 | return _contextvars_Context_keys_impl(self); |
| 75 | } |
| 76 | |
| 77 | PyDoc_STRVAR(_contextvars_Context_values__doc__, |
| 78 | "values($self, /)\n" |
| 79 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 80 | "\n" |
| 81 | "Return a list of all variables’ values in the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 82 | |
| 83 | #define _CONTEXTVARS_CONTEXT_VALUES_METHODDEF \ |
| 84 | {"values", (PyCFunction)_contextvars_Context_values, METH_NOARGS, _contextvars_Context_values__doc__}, |
| 85 | |
| 86 | static PyObject * |
| 87 | _contextvars_Context_values_impl(PyContext *self); |
| 88 | |
| 89 | static PyObject * |
| 90 | _contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 91 | { |
| 92 | return _contextvars_Context_values_impl(self); |
| 93 | } |
| 94 | |
| 95 | PyDoc_STRVAR(_contextvars_Context_copy__doc__, |
| 96 | "copy($self, /)\n" |
| 97 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 98 | "\n" |
| 99 | "Return a shallow copy of the context object."); |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 100 | |
| 101 | #define _CONTEXTVARS_CONTEXT_COPY_METHODDEF \ |
| 102 | {"copy", (PyCFunction)_contextvars_Context_copy, METH_NOARGS, _contextvars_Context_copy__doc__}, |
| 103 | |
| 104 | static PyObject * |
| 105 | _contextvars_Context_copy_impl(PyContext *self); |
| 106 | |
| 107 | static PyObject * |
| 108 | _contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored)) |
| 109 | { |
| 110 | return _contextvars_Context_copy_impl(self); |
| 111 | } |
| 112 | |
| 113 | PyDoc_STRVAR(_contextvars_ContextVar_get__doc__, |
| 114 | "get($self, default=None, /)\n" |
| 115 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 116 | "\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 Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 124 | |
| 125 | #define _CONTEXTVARS_CONTEXTVAR_GET_METHODDEF \ |
| 126 | {"get", (PyCFunction)_contextvars_ContextVar_get, METH_FASTCALL, _contextvars_ContextVar_get__doc__}, |
| 127 | |
| 128 | static PyObject * |
| 129 | _contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value); |
| 130 | |
| 131 | static 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 | |
| 144 | exit: |
| 145 | return return_value; |
| 146 | } |
| 147 | |
| 148 | PyDoc_STRVAR(_contextvars_ContextVar_set__doc__, |
| 149 | "set($self, value, /)\n" |
| 150 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 151 | "\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 Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 158 | |
| 159 | #define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF \ |
| 160 | {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__}, |
| 161 | |
| 162 | PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__, |
| 163 | "reset($self, token, /)\n" |
| 164 | "--\n" |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 165 | "\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 Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 170 | |
| 171 | #define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \ |
| 172 | {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__}, |
Peter Lamut | 20678fd | 2018-07-30 16:15:44 +0100 | [diff] [blame] | 173 | /*[clinic end generated code: output=33414d13716d0648 input=a9049054013a1b77]*/ |