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.

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