diff options
author | Noel Power <noel.power@suse.com> | 2018-12-11 15:18:10 +0000 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2019-01-21 09:48:14 +0100 |
commit | d253c470ae410436a5fbde817cb66cea92c1243c (patch) | |
tree | 4b22a1a84bdb87ccaca1436bf050af131320d8c2 /python | |
parent | 38c459223d217bf8be6858bfc7066c9c9d3adbdd (diff) | |
download | samba-d253c470ae410436a5fbde817cb66cea92c1243c.tar.gz |
python: Add new compat PYARG_STR_UNI format
In python2 PYARG_STR_UNI evaluates to et which allows str type
(e.g bytes) pass through unencoded and accepts unicode objects
encoded as utf8
In python3 PYARG_STR_UNI evaluates to es which allows str type
encoded as named/specified encoding
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
(cherry picked from commit 253af8b85450c2830a442084e98734ca338c1b2f)
Diffstat (limited to 'python')
-rw-r--r-- | python/py3compat.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/python/py3compat.h b/python/py3compat.h index 5fa57f323d5..89b7552c791 100644 --- a/python/py3compat.h +++ b/python/py3compat.h @@ -118,6 +118,7 @@ /* PyArg_ParseTuple/Py_BuildValue argument */ #define PYARG_BYTES_LEN "y#" +#define PYARG_STR_UNI "es" #else @@ -179,6 +180,15 @@ /* PyArg_ParseTuple/Py_BuildValue argument */ #define PYARG_BYTES_LEN "s#" +/* + * We want a format that will ensure unicode is encoded using the + * specified encoding 'utf8' (to obtain the char* array) + * In python3 we use "es" but in python2 the specifiying 'es' will + * result in the any incomming 'str' type being decoded first to ascii + * then encoded to the specified 'utf8' encoding. In order to avoid that + * we use format 'et' in python2 instead. + */ +#define PYARG_STR_UNI "et" /* Module init */ |