You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by lordofkey <gi...@git.apache.org> on 2018/07/27 07:41:54 UTC
[GitHub] zookeeper pull request #586: Zookeeper 3105:Character coding problem occur w...
GitHub user lordofkey opened a pull request:
https://github.com/apache/zookeeper/pull/586
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.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/lordofkey/zookeeper ZOOKEEPER-3105
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/zookeeper/pull/586.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #586
----
commit 5a441ed6058740458b8ec549fd32931757ce4e3a
Author: yanghao <yy...@...>
Date: 2018-07-27T07:35:41Z
ZOOKEEPER-3105:Character coding problem occur when create a node using python3
----
---
[GitHub] zookeeper pull request #586: Zookeeper 3105:Character coding problem occur w...
Posted by breed <gi...@git.apache.org>.
Github user breed commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/586#discussion_r212781950
--- Diff: src/contrib/zkpython/src/c/zookeeper.c ---
@@ -387,8 +387,8 @@ 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" ) ) );
+ acls->data[i].id.id = strdup( PyBytes_AS_STRING( PyUnicode_AsASCIIString( PyDict_GetItemString( a, "id" ) ) ) );
--- End diff --
i think we can have id be "أليس" and i believe it will get messed up by this code. we need to use UTF-8 encoding. (unfortunately, i'm not familiar enough with python C-bindings to know how to do it correctly...
---
[GitHub] zookeeper pull request #586: Zookeeper 3105:Character coding problem occur w...
Posted by lordofkey <gi...@git.apache.org>.
Github user lordofkey commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/586#discussion_r207772138
--- Diff: src/contrib/zkpython/src/c/zookeeper.c ---
@@ -387,8 +387,8 @@ 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" ) ) );
+ acls->data[i].id.id = strdup( PyBytes_AS_STRING( PyUnicode_AsASCIIString( PyDict_GetItemString( a, "id" ) ) ) );
--- End diff --
i thought the value of id can be "anyone" or ip or the string like "usrname:password", either of them can be represented as a string. then i tried "anyone", "127.0.0.1/16" and "usrname:password", and they all worked.
---
[GitHub] zookeeper issue #586: Zookeeper 3105:Character coding problem occur when cre...
Posted by lvfangmin <gi...@git.apache.org>.
Github user lvfangmin commented on the issue:
https://github.com/apache/zookeeper/pull/586
LGTM, it would be great to have test case to cover the coding/decoding part in the python C bind.
---
[GitHub] zookeeper issue #586: Zookeeper 3105:Character coding problem occur when cre...
Posted by lordofkey <gi...@git.apache.org>.
Github user lordofkey commented on the issue:
https://github.com/apache/zookeeper/pull/586
utf-8 encoding is now implemented before passed to a char pointer.
---
[GitHub] zookeeper issue #586: Zookeeper 3105:Character coding problem occur when cre...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:
https://github.com/apache/zookeeper/pull/586
Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/2272/
---
[GitHub] zookeeper pull request #586: Zookeeper 3105:Character coding problem occur w...
Posted by breed <gi...@git.apache.org>.
Github user breed commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/586#discussion_r207599621
--- Diff: src/contrib/zkpython/src/c/zookeeper.c ---
@@ -387,8 +387,8 @@ 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" ) ) );
+ acls->data[i].id.id = strdup( PyBytes_AS_STRING( PyUnicode_AsASCIIString( PyDict_GetItemString( a, "id" ) ) ) );
--- End diff --
this only works for ascii strings. that should be ok for scheme, but maybe not for id.
---