This is an automated email from the ASF dual-hosted git repository.

phunt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 52dcf72  ZOOKEEPER-3105: Character coding problem occur when create a 
node using python3
52dcf72 is described below

commit 52dcf72b0a035116f83431e30c7acf7301982a28
Author: lordofkey <[email protected]>
AuthorDate: Tue Jun 18 21:07:14 2019 -0700

    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 <[email protected]>
    Author: yanghao <[email protected]>
    
    Reviewers: [email protected]
    
    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
---
 zookeeper-contrib/zookeeper-contrib-zkpython/src/c/zookeeper.c | 9 +++++++--
 1 file 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 4474661..add1e9b 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" ) ) );

Reply via email to