diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-25 11:23:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-25 11:23:47 (GMT) |
commit | 32d96a2b5bc3136d45a66adbdb45fac351b520ce (patch) | |
tree | acf51c9945f764ab103597c9cba376f154aa600d /Modules/clinic/_ssl.c.h | |
parent | 65ce60aef150776f884715b4315a10a0d6ae769e (diff) | |
download | cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.zip cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.gz cpython-32d96a2b5bc3136d45a66adbdb45fac351b520ce.tar.bz2 |
bpo-23867: Argument Clinic: inline parsing code for a single positional parameter. (GH-9689)
Diffstat (limited to 'Modules/clinic/_ssl.c.h')
-rw-r--r-- | Modules/clinic/_ssl.c.h | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 82dc197..e149077 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -36,7 +36,7 @@ _ssl__test_decode_cert(PyObject *module, PyObject *arg) PyObject *return_value = NULL; PyObject *path; - if (!PyArg_Parse(arg, "O&:_test_decode_cert", PyUnicode_FSConverter, &path)) { + if (!PyUnicode_FSConverter(arg, &path)) { goto exit; } return_value = _ssl__test_decode_cert_impl(module, path); @@ -211,7 +211,11 @@ _ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer b = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &b)) { + if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&b, 'C')) { + _PyArg_BadArgument("write", "contiguous buffer", arg); goto exit; } return_value = _ssl__SSLSocket_write_impl(self, &b); @@ -400,7 +404,17 @@ _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg) PyObject *return_value = NULL; const char *cipherlist; - if (!PyArg_Parse(arg, "s:set_ciphers", &cipherlist)) { + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("set_ciphers", "str", arg); + goto exit; + } + Py_ssize_t cipherlist_length; + cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length); + if (cipherlist == NULL) { + goto exit; + } + if (strlen(cipherlist) != (size_t)cipherlist_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist); @@ -448,7 +462,11 @@ _ssl__SSLContext__set_npn_protocols(PySSLContext *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer protos = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:_set_npn_protocols", &protos)) { + if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&protos, 'C')) { + _PyArg_BadArgument("_set_npn_protocols", "contiguous buffer", arg); goto exit; } return_value = _ssl__SSLContext__set_npn_protocols_impl(self, &protos); @@ -480,7 +498,11 @@ _ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer protos = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:_set_alpn_protocols", &protos)) { + if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&protos, 'C')) { + _PyArg_BadArgument("_set_alpn_protocols", "contiguous buffer", arg); goto exit; } return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos); @@ -823,7 +845,11 @@ _ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg) PyObject *return_value = NULL; Py_buffer b = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &b)) { + if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&b, 'C')) { + _PyArg_BadArgument("write", "contiguous buffer", arg); goto exit; } return_value = _ssl_MemoryBIO_write_impl(self, &b); @@ -912,7 +938,13 @@ _ssl_RAND_bytes(PyObject *module, PyObject *arg) PyObject *return_value = NULL; int n; - if (!PyArg_Parse(arg, "i:RAND_bytes", &n)) { + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + n = _PyLong_AsInt(arg); + if (n == -1 && PyErr_Occurred()) { goto exit; } return_value = _ssl_RAND_bytes_impl(module, n); @@ -942,7 +974,13 @@ _ssl_RAND_pseudo_bytes(PyObject *module, PyObject *arg) PyObject *return_value = NULL; int n; - if (!PyArg_Parse(arg, "i:RAND_pseudo_bytes", &n)) { + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + n = _PyLong_AsInt(arg); + if (n == -1 && PyErr_Occurred()) { goto exit; } return_value = _ssl_RAND_pseudo_bytes_impl(module, n); @@ -995,7 +1033,7 @@ _ssl_RAND_egd(PyObject *module, PyObject *arg) PyObject *return_value = NULL; PyObject *path; - if (!PyArg_Parse(arg, "O&:RAND_egd", PyUnicode_FSConverter, &path)) { + if (!PyUnicode_FSConverter(arg, &path)) { goto exit; } return_value = _ssl_RAND_egd_impl(module, path); @@ -1078,7 +1116,13 @@ _ssl_nid2obj(PyObject *module, PyObject *arg) PyObject *return_value = NULL; int nid; - if (!PyArg_Parse(arg, "i:nid2obj", &nid)) { + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nid = _PyLong_AsInt(arg); + if (nid == -1 && PyErr_Occurred()) { goto exit; } return_value = _ssl_nid2obj_impl(module, nid); @@ -1193,4 +1237,4 @@ exit: #ifndef _SSL_ENUM_CRLS_METHODDEF #define _SSL_ENUM_CRLS_METHODDEF #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ -/*[clinic end generated code: output=d87f783224be8fca input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c2dca2ef4cbef4e2 input=a9049054013a1b77]*/ |