Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/PC/clinic/_testconsole.c.h
12 views
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
#if defined(MS_WINDOWS)
12
13
PyDoc_STRVAR(_testconsole_write_input__doc__,
14
"write_input($module, /, file, s)\n"
15
"--\n"
16
"\n"
17
"Writes UTF-16-LE encoded bytes to the console as if typed by a user.");
18
19
#define _TESTCONSOLE_WRITE_INPUT_METHODDEF \
20
{"write_input", _PyCFunction_CAST(_testconsole_write_input), METH_FASTCALL|METH_KEYWORDS, _testconsole_write_input__doc__},
21
22
static PyObject *
23
_testconsole_write_input_impl(PyObject *module, PyObject *file,
24
PyBytesObject *s);
25
26
static PyObject *
27
_testconsole_write_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
28
{
29
PyObject *return_value = NULL;
30
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
31
32
#define NUM_KEYWORDS 2
33
static struct {
34
PyGC_Head _this_is_not_used;
35
PyObject_VAR_HEAD
36
PyObject *ob_item[NUM_KEYWORDS];
37
} _kwtuple = {
38
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
39
.ob_item = { &_Py_ID(file), &_Py_ID(s), },
40
};
41
#undef NUM_KEYWORDS
42
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
43
44
#else // !Py_BUILD_CORE
45
# define KWTUPLE NULL
46
#endif // !Py_BUILD_CORE
47
48
static const char * const _keywords[] = {"file", "s", NULL};
49
static _PyArg_Parser _parser = {
50
.keywords = _keywords,
51
.fname = "write_input",
52
.kwtuple = KWTUPLE,
53
};
54
#undef KWTUPLE
55
PyObject *argsbuf[2];
56
PyObject *file;
57
PyBytesObject *s;
58
59
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
60
if (!args) {
61
goto exit;
62
}
63
file = args[0];
64
if (!PyBytes_Check(args[1])) {
65
_PyArg_BadArgument("write_input", "argument 's'", "bytes", args[1]);
66
goto exit;
67
}
68
s = (PyBytesObject *)args[1];
69
return_value = _testconsole_write_input_impl(module, file, s);
70
71
exit:
72
return return_value;
73
}
74
75
#endif /* defined(MS_WINDOWS) */
76
77
#if defined(MS_WINDOWS)
78
79
PyDoc_STRVAR(_testconsole_read_output__doc__,
80
"read_output($module, /, file)\n"
81
"--\n"
82
"\n"
83
"Reads a str from the console as written to stdout.");
84
85
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF \
86
{"read_output", _PyCFunction_CAST(_testconsole_read_output), METH_FASTCALL|METH_KEYWORDS, _testconsole_read_output__doc__},
87
88
static PyObject *
89
_testconsole_read_output_impl(PyObject *module, PyObject *file);
90
91
static PyObject *
92
_testconsole_read_output(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
93
{
94
PyObject *return_value = NULL;
95
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
96
97
#define NUM_KEYWORDS 1
98
static struct {
99
PyGC_Head _this_is_not_used;
100
PyObject_VAR_HEAD
101
PyObject *ob_item[NUM_KEYWORDS];
102
} _kwtuple = {
103
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
104
.ob_item = { &_Py_ID(file), },
105
};
106
#undef NUM_KEYWORDS
107
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
108
109
#else // !Py_BUILD_CORE
110
# define KWTUPLE NULL
111
#endif // !Py_BUILD_CORE
112
113
static const char * const _keywords[] = {"file", NULL};
114
static _PyArg_Parser _parser = {
115
.keywords = _keywords,
116
.fname = "read_output",
117
.kwtuple = KWTUPLE,
118
};
119
#undef KWTUPLE
120
PyObject *argsbuf[1];
121
PyObject *file;
122
123
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
124
if (!args) {
125
goto exit;
126
}
127
file = args[0];
128
return_value = _testconsole_read_output_impl(module, file);
129
130
exit:
131
return return_value;
132
}
133
134
#endif /* defined(MS_WINDOWS) */
135
136
#ifndef _TESTCONSOLE_WRITE_INPUT_METHODDEF
137
#define _TESTCONSOLE_WRITE_INPUT_METHODDEF
138
#endif /* !defined(_TESTCONSOLE_WRITE_INPUT_METHODDEF) */
139
140
#ifndef _TESTCONSOLE_READ_OUTPUT_METHODDEF
141
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF
142
#endif /* !defined(_TESTCONSOLE_READ_OUTPUT_METHODDEF) */
143
/*[clinic end generated code: output=208c72e2c873555b input=a9049054013a1b77]*/
144
145