RFC: extend string arg handling for some python c modules

Noel Power noel.power at gmail.com
Mon Apr 16 16:00:21 UTC 2018


I know some don't really follow the github pull requests [1] so I'd like to mention this patch here in the list too.

Many of the python c-modules don't handle unicode as string types when passed say an object (where that object is a string). This wasn't really a problem in a python2 only world. With code ported to be python2/python3 compatible it seems (at least in code we are porting) that we now find objects that were previously string in python2 now getting passed as unicode types in python2. This is a side affect of trying to cater for variables returned from functions as 'bytes' in python3 that are returned as 'string' in python2. To convert the code to be python2/python3 compatible we normally do something like

   py2py3compat_var.decode('utf8')

To ensure the bytes provided in python3 are converted to 'str' The same line of code when running under python2 will convert the 'str' type to 'unicode'

IMHO we really should handle 'unicode' anyway as it is a 'text type. For example python2 code that use the ParseTuplexxxx functions to handle arguments already automatically handle 'str' or 'unicode' when passed a 'string' format. I think this should make the the c python modules more forgiving and make the porting easier. That said I am not that familiar with the nitty-gritty of the c-modules api so it would be great to ensure that the changes a) make sense generally b) make sense for the individual modules arg handling

Noel

[1] https://github.com/samba-team/samba/pull/166 (which is passing the CI)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: handle-unicode-as-string.patch
Type: text/x-patch
Size: 15178 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20180416/901e05b2/handle-unicode-as-string.bin>


More information about the samba-technical mailing list