LCOV - code coverage report
Current view: top level - Python/clinic - context.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 31 33 93.9 %
Date: 2022-07-07 18:19:46 Functions: 6 6 100.0 %

          Line data    Source code
       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"
       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             : 
      17             : static PyObject *
      18             : _contextvars_Context_get_impl(PyContext *self, PyObject *key,
      19             :                               PyObject *default_value);
      20             : 
      21             : static PyObject *
      22          83 : _contextvars_Context_get(PyContext *self, PyObject *const *args, Py_ssize_t nargs)
      23             : {
      24          83 :     PyObject *return_value = NULL;
      25             :     PyObject *key;
      26          83 :     PyObject *default_value = Py_None;
      27             : 
      28          83 :     if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
      29           0 :         goto exit;
      30             :     }
      31          83 :     key = args[0];
      32          83 :     if (nargs < 2) {
      33          80 :         goto skip_optional;
      34             :     }
      35           3 :     default_value = args[1];
      36          83 : skip_optional:
      37          83 :     return_value = _contextvars_Context_get_impl(self, key, default_value);
      38             : 
      39          83 : exit:
      40          83 :     return return_value;
      41             : }
      42             : 
      43             : PyDoc_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             : 
      54             : static PyObject *
      55             : _contextvars_Context_items_impl(PyContext *self);
      56             : 
      57             : static PyObject *
      58           1 : _contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored))
      59             : {
      60           1 :     return _contextvars_Context_items_impl(self);
      61             : }
      62             : 
      63             : PyDoc_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             : 
      72             : static PyObject *
      73             : _contextvars_Context_keys_impl(PyContext *self);
      74             : 
      75             : static PyObject *
      76           4 : _contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored))
      77             : {
      78           4 :     return _contextvars_Context_keys_impl(self);
      79             : }
      80             : 
      81             : PyDoc_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             : 
      90             : static PyObject *
      91             : _contextvars_Context_values_impl(PyContext *self);
      92             : 
      93             : static PyObject *
      94           1 : _contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored))
      95             : {
      96           1 :     return _contextvars_Context_values_impl(self);
      97             : }
      98             : 
      99             : PyDoc_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             : 
     108             : static PyObject *
     109             : _contextvars_Context_copy_impl(PyContext *self);
     110             : 
     111             : static PyObject *
     112           1 : _contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored))
     113             : {
     114           1 :     return _contextvars_Context_copy_impl(self);
     115             : }
     116             : 
     117             : PyDoc_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             : 
     132             : static PyObject *
     133             : _contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value);
     134             : 
     135             : static PyObject *
     136       42112 : _contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_t nargs)
     137             : {
     138       42112 :     PyObject *return_value = NULL;
     139       42112 :     PyObject *default_value = NULL;
     140             : 
     141       42112 :     if (!_PyArg_CheckPositional("get", nargs, 0, 1)) {
     142           0 :         goto exit;
     143             :     }
     144       42112 :     if (nargs < 1) {
     145       42102 :         goto skip_optional;
     146             :     }
     147          10 :     default_value = args[0];
     148       42112 : skip_optional:
     149       42112 :     return_value = _contextvars_ContextVar_get_impl(self, default_value);
     150             : 
     151       42112 : exit:
     152       42112 :     return return_value;
     153             : }
     154             : 
     155             : PyDoc_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             : 
     169             : PyDoc_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]*/

Generated by: LCOV version 1.14