1
0
mirror of https://github.com/samba-team/samba.git synced 2025-09-11 09:44:19 +03:00

python3: Use "y#" instead of "s#" for binary data in PyArg_ParseTuple

The "s#" format code for PyArg_ParseTupleAndKeywords and Py_BuildValue
converts a char* and size to/from Python str (with utf-8 encoding under
Python 3).
In some cases, we want bytes (str on Python 2, bytes on 3) instead. The
code for this is "y#" in Python 3, but that is not available in 2.

Introduce a PYARG_BYTES_LEN macro that expands to "s#" or "y#", and use
that in:
- credentials.get_ntlm_response (for input and output)
- ndr_unpack argument in PIDL generated code

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Petr Viktorin
2017-05-03 16:57:07 +02:00
committed by Andrew Bartlett
parent b691f6d32f
commit 40e409bf9e
3 changed files with 15 additions and 5 deletions

View File

@@ -98,6 +98,10 @@
PyMODINIT_FUNC PyInit_ ## name(void); \
PyMODINIT_FUNC PyInit_ ## name(void)
/* PyArg_ParseTuple/Py_BuildValue argument */
#define PYARG_BYTES_LEN "y#"
#else
/***** Python 2 *****/
@@ -140,6 +144,10 @@
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
#define _PyBytes_Resize _PyString_Resize
/* PyArg_ParseTuple/Py_BuildValue argument */
#define PYARG_BYTES_LEN "s#"
/* Module init */
#define PyModuleDef_HEAD_INIT 0