diff options
author | lordofkey <yyyhhh125@163.com> | 2019-06-18 21:07:14 -0700 |
---|---|---|
committer | Patrick Hunt <phunt@apache.org> | 2019-06-18 21:08:26 -0700 |
commit | 3813d407e86afbea9bdcab97cbb830cc9e8e99df (patch) | |
tree | 54fc3b0791f83e27bc917f6171435a5fac23044d | |
parent | 5503fef20d2ce58f41fad3814d2c13a131ce611c (diff) | |
download | zookeeper-3813d407e86afbea9bdcab97cbb830cc9e8e99df.tar.gz |
ZOOKEEPER-3105: Character coding problem occur when create a node using python3
when creating a node using python3, InvalidACLException occurs all the time. it`s caused by imcompatible way of parsing acl passed through python3 api.
so
```
acls->data[i].id.id = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "id" ) ) );
acls->data[i].id.scheme = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "scheme" ) ) );
```
is changed to
```
acls->data[i].id.id = strdup( PyBytes_AS_STRING( PyUnicode_AsASCIIString( PyDict_GetItemString( a, "id" ) ) ) );
acls->data[i].id.scheme = strdup( PyBytes_AS_STRING( PyUnicode_AsASCIIString( PyDict_GetItemString( a, "scheme" ) ) ) );
```
because `acls->data[i].id.id` and `acls->data[i].id.scheme` must be an ASCII string.
Author: lordofkey <yyyhhh125@163.com>
Author: yanghao <yyyhhh125@163.com>
Reviewers: phunt@apache.org
Closes #586 from lordofkey/ZOOKEEPER-3105 and squashes the following commits:
24a60d982 [lordofkey] Update zookeeper.c
9f2fd54ca [lordofkey] ZOOKEEPER-3105:Character coding problem occur when create a node usin… …
519a7805f [lordofkey] Merge remote-tracking branch 'shared/master' into HEAD
5a441ed60 [yanghao] ZOOKEEPER-3105:Character coding problem occur when create a node using python3
Change-Id: I72c104edc4c77159f75db1211fcd62b33c7d33d6
(cherry picked from commit 52dcf72b0a035116f83431e30c7acf7301982a28)
Signed-off-by: Patrick Hunt <phunt@apache.org>
-rw-r--r-- | zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c b/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c index 447466186..add1e9b36 100644 --- a/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c +++ b/zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c @@ -387,8 +387,13 @@ int parse_acls(struct ACL_vector *acls, PyObject *pyacls) PyObject *perms = PyDict_GetItemString( a, "perms" ); #if PY_MAJOR_VERSION >= 3 acls->data[i].perms = (int32_t)(PyLong_AsLong(perms)); - acls->data[i].id.id = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "id" ) ) ); - acls->data[i].id.scheme = strdup( PyUnicode_AsUnicode( PyDict_GetItemString( a, "scheme" ) ) ); + PyObject *tem_utfstring; + tem_utfstring = PyUnicode_AsEncodedString(PyDict_GetItemString( a, "id" ), "utf-8", NULL ); + acls->data[i].id.id = strdup( PyBytes_AS_STRING(tem_utfstring)); + Py_DECREF(tem_utfstring); + tem_utfstring = PyUnicode_AsEncodedString(PyDict_GetItemString( a, "scheme" ), "utf-8", NULL ); + acls->data[i].id.scheme = strdup( PyBytes_AS_STRING(tem_utfstring) ); + Py_DECREF(tem_utfstring); #else acls->data[i].perms = (int32_t)(PyInt_AsLong(perms)); acls->data[i].id.id = strdup( PyString_AsString( PyDict_GetItemString( a, "id" ) ) ); |