MCPcopy Create free account
hub / github.com/python/cpython / parse_arg

Method parse_arg

Tools/clinic/libclinic/converters.py:30–83  ·  view source on GitHub ↗
(self, argname: str, displayname: str, *, limited_capi: bool)

Source from the content-addressed store, hash-verified

28 f'{self.converter}()')
29
30 def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None:
31 if self.bitwise:
32 result = self.format_code("""
33 {{{{
34 Py_ssize_t _bytes = PyLong_AsNativeBytes({argname}, &{paramname}, sizeof({type}),
35 Py_ASNATIVEBYTES_NATIVE_ENDIAN |
36 Py_ASNATIVEBYTES_ALLOW_INDEX |
37 Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
38 if (_bytes < 0) {{{{
39 goto exit;
40 }}}}
41 if ((size_t)_bytes > sizeof({type})) {{{{
42 if (PyErr_WarnEx(PyExc_DeprecationWarning,
43 "integer value out of range", 1) < 0)
44 {{{{
45 goto exit;
46 }}}}
47 }}}}
48 }}}}
49 """,
50 argname=argname,
51 type=self.type,
52 bad_argument=self.bad_argument(displayname, 'int', limited_capi=limited_capi))
53 if self.format_unit in ('k', 'K'):
54 result = self.format_code("""
55 if (!PyIndex_Check({argname})) {{{{
56 {bad_argument}
57 goto exit;
58 }}}}""",
59 argname=argname,
60 bad_argument=self.bad_argument(displayname, 'int', limited_capi=limited_capi)) + result
61 return result
62
63 if not limited_capi:
64 return super().parse_arg(argname, displayname, limited_capi=limited_capi)
65 return self.format_code("""
66 {{{{
67 Py_ssize_t _bytes = PyLong_AsNativeBytes({argname}, &{paramname}, sizeof({type}),
68 Py_ASNATIVEBYTES_NATIVE_ENDIAN |
69 Py_ASNATIVEBYTES_ALLOW_INDEX |
70 Py_ASNATIVEBYTES_REJECT_NEGATIVE |
71 Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
72 if (_bytes < 0) {{{{
73 goto exit;
74 }}}}
75 if ((size_t)_bytes > sizeof({type})) {{{{
76 PyErr_SetString(PyExc_OverflowError,
77 "Python int too large for C {type}");
78 goto exit;
79 }}}}
80 }}}}
81 """,
82 argname=argname,
83 type=self.type)
84
85
86class uint8_converter(BaseUnsignedIntConverter):

Callers

nothing calls this directly

Calls 4

superClass · 0.85
format_codeMethod · 0.80
bad_argumentMethod · 0.80
parse_argMethod · 0.45

Tested by

no test coverage detected