You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2019/06/19 04:08:42 UTC

[zookeeper] branch branch-3.5 updated: ZOOKEEPER-3105: Character coding problem occur when create a node using python3

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

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


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

commit 3813d407e86afbea9bdcab97cbb830cc9e8e99df
Author: lordofkey <yy...@163.com>
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 <yy...@163.com>
    Author: yanghao <yy...@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 <ph...@apache.org>
---
 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" ) ) );