[liblouis-liblouisxml] Re: Python 3 and/or GObject introspection support?

  • From: Hammer Attila <hammera@xxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Sun, 13 May 2012 07:58:29 +0200

Hy Joanie,

I now installed a python 3.2 environment my Ubuntu 12.04 system.
Testing purpose I tryed the automatic migration tool (2to3 script with part of python 3.2). I sending a patch what want change the script in python/louis/__init__.py.in file. When I patched the file, recompiled Liblouis and run __init__.py file in the python/louis directory, I experienced following: 1. If I use python __init__.py command, the script runs under default pythor 2.7 interpreter, all basic test actions happened right. Right present Liblouis version, and the test english translated braille output.

2. If I use python3.2 __init__.py command, I get following error:
root@hammera-Satellite-L300:/usr/src/liblouis/liblouis/python/louis# python3.2 __init__.py
b'2.3.0'
Traceback (most recent call last):
  File "__init__.py", line 292, in <module>
print(translate(['../tables/en-us-g2.ctb'], 'Hello world!', cursorPos=5))
  File "__init__.py", line 124, in translate
    None, outPos, inPos, byref(cursorPos), mode):
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
root@hammera-Satellite-L300:/usr/src/liblouis/liblouis/python/louis#

Attila
Index: __init__.py.in
===================================================================
--- __init__.py.in      (revision 609)
+++ __init__.py.in      (working copy)
@@ -109,7 +109,7 @@
     @see: lou_translate in the liblouis documentation
     """
     tablesString = ",".join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -144,7 +144,7 @@
     @see: lou_translateString in the liblouis documentation
     """
     tablesString = ",".join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -180,7 +180,7 @@
     @see: lou_backTranslate in the liblouis documentation.
     """
     tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -215,7 +215,7 @@
     @see: lou_backTranslateString in the liblouis documentation.
     """
     tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -248,7 +248,7 @@
     @see: lou_hyphenate in the liblouis documentation.
     """
     tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     hyphen_string = create_string_buffer(inlen.value)
     if not liblouis.lou_hyphenate(tablestring, inbuf, inlen, hyphen_string, 
mode):
@@ -288,5 +288,5 @@
 
 if __name__ == '__main__':
     # Just some common tests.
-    print version()
-    print translate(['../tables/en-us-g2.ctb'], u'Hello world!', cursorPos=5)
+    print(version())
+    print(translate(['../tables/en-us-g2.ctb'], 'Hello world!', cursorPos=5))

Other related posts: