You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.2 KiB

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