[python-ldap] Patch: ldap.syncrepl UUID constructors use bytes (Python 3 compatbility)
Karl Kornel
akkornel at stanford.edu
Mon Jun 5 00:15:41 EDT 2017
Hello!
I have a patch for python-ldap’s syncrepl.py. This is specially a patch for Python 3 support in syncrepl.
Even though python-ldap does not have Python 3 support, I noticed that python-ldap has not made any changes to syncrepl.py. So, I tested this code first in python-ldap 2.4.35.1. I then tested the code using python-ldap 2.4.39. I also used my t_syncrepl.py test script, and the tests pass.
The problem is this: In Python 3, the UUID class constructor’s “bytes” input requires that you provide a bytes object. In Python 3, the current syncrepl code gives an exception like this:
… snip part of the traceback …
File "/Users/akkornel/Library/Python/3.6/lib/python/site-packages/ldap/syncrepl.py", line 135, in decodeControlValue
uuid = UUID(bytes=d[0].getComponentByName('entryUUID'))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/uuid.py", line 150, in __init__
assert isinstance(bytes, bytes_), repr(bytes)
AssertionError: syncUUID(hexValue='25a19266b609102b8a810bcc11d0e1be')
Since Python 3 strings are Unicode by default, passing strings as “bytes” does not work anymore. There are two places where UUID objects are constructed; in both places, my patch wraps the string value in a “bytes” call.
I was originally thinking of sending this to python-ldap directly, but this change seems like a no-op on Python 2.7, so I decided to send it in here!
This patch also works on test code I have in development (https://github.com/akkornel/syncrepl), running on Python 2.7 with python-ldap 2.4.38. But, I understand that you might not want to accept this until the t_syncrepl.py is more complete.
I think that’s it. Please let me know your questions and comments!
--
A. Karl Kornel | System Administrator
Research Computing | Stanford University
+1 (650) 736-9327
-------------- next part --------------
A non-text attachment was scrubbed...
Name: syncrepl.py.diff
Type: application/octet-stream
Size: 1110 bytes
Desc: syncrepl.py.diff
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20170605/c1ef0bdf/attachment.obj>
More information about the python-ldap
mailing list