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