Hi.
I'm currently working on resolving unbound build issues in Fedora due to Python3. I'm reworking the Fedora package to ship Python2 and also Python3 libunbound and pythonmode bindings.
The python examples in libunbound seem like a good tests for comparing that the Python3 version gives the same results as Python2 version. However in case of the Python2 run, the built-in print statement is used instead of print function, which makes the output different on Python2 and Python3, thus comparing the results using a script hard.
Also results in output of some examples (e.g. mx-lookup.py) were randomly shuffled, thus hard to compare. I wrapped all lists with sorted() to produce predictable output all the time.
I'm attaching a patch to use print_function (available since Python 2.6) also with Python2
example of output before:
[root@unused-4-247 ~]# python2 /usr/share/doc/python-unbound/async-lookup.py
('Call_back:', {'done_flag': False, 'arbitrary': 'object'})
('Result:', ['217.31.205.50'])
[root@unused-4-247 ~]# python3 /usr/share/doc/python-unbound/async-lookup.py
Call_back: {'done_flag': False, 'arbitrary': 'object'}
Result: ['217.31.205.50']
Now:
[root@unused-4-247 ~]# python2 /usr/share/doc/python-unbound/async-lookup.py
Call_back: {'done_flag': False, 'arbitrary': 'object'}
Result: ['217.31.205.50']
[root@unused-4-247 ~]# python3 /usr/share/doc/python-unbound/async-lookup.py
Call_back: {'done_flag': False, 'arbitrary': 'object'}
Result: ['217.31.205.50']
I also have simple script I used for running the examples on Fedora with Python2 and Python3 and comparing the output. It was useful for testing. I can attach it too, if you think it would be useful for others.
Another issue was with unbound.ub_ctx_debugout() function which takes FILE* as parameter. I used the file_py3.i from ldns. Added typemap for "typecheck" due to how the function is declared. I also removed the typemap "freearg" since the FILE* is later used internally by the library for logging. This caused nasty crashes like:
[root@unused-4-247 ~]# python3 /usr/share/doc/python-unbound/dnssec-valid.py
*** Error in `python3': corrupted double-linked list: 0x0000000000fcb1b0 ***
*** Error in `python3': corrupted double-linked list: 0x0000000000fcb1b0 ***
There is still an issue with IDN and encoding when using Python3, but after 3 days fighting the Python3 + SWIG I need some rest from it. :) There is most probably some issue with wrong usage of PyBytes_* PyUnicode_* and PyString_*