[liblouis-liblouisxml] [liblouis] r619 committed - Changed the python3 bindings so they should work for both python2 and ...

  • From: liblouis@xxxxxxxxxxxxxx
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Tue, 15 May 2012 09:53:05 +0000

Revision: 619
Author:   mwhapples@xxxxxxxxx
Date:     Tue May 15 02:52:48 2012
Log: Changed the python3 bindings so they should work for both python2 and python3, tests only work for python2 though.

http://code.google.com/p/liblouis/source/detail?r=619

Modified:
 /trunk/python3/louis/__init__.py.in

=======================================
--- /trunk/python3/louis/__init__.py.in Sun May 13 18:41:29 2012
+++ /trunk/python3/louis/__init__.py.in Tue May 15 02:52:48 2012
@@ -34,12 +34,19 @@
 from ctypes import *
 import struct
 import atexit
+import sys

 # Some general utility functions
 def _createTablesString(tablesList):
     """Creates a tables string for liblouis calls"""
return b",".join([x.encode("ASCII") if isinstance(x, str) else bytes(x) for x in tablesList])

+createStr = None
+if sys.version_info[0] == 2:
+    createStr = lambda x: unicode(x)
+else:
+    createStr = lambda x: str(x)
+
 #{ Module Configuration
 #: Specifies the number by which the input length should be multiplied
 #: to calculate the maximum output length.
@@ -114,7 +121,7 @@
     @see: lou_translate in the liblouis documentation
     """
     tablesString = _createTablesString(tableList)
-    inbuf = str(inbuf)
+    inbuf = createStr(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -149,7 +156,7 @@
     @see: lou_translateString in the liblouis documentation
     """
     tablesString = _createTablesString(tableList)
-    inbuf = str(inbuf)
+    inbuf = createStr(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -185,7 +192,7 @@
     @see: lou_backTranslate in the liblouis documentation.
     """
     tablestring = _createTablesString(tableList)
-    inbuf = str(inbuf)
+    inbuf = createStr(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -220,7 +227,7 @@
     @see: lou_backTranslateString in the liblouis documentation.
     """
     tablestring = _createTablesString(tableList)
-    inbuf = str(inbuf)
+    inbuf = createStr(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -253,7 +260,7 @@
     @see: lou_hyphenate in the liblouis documentation.
     """
     tablesString = _createTablesString(tableList)
-    inbuf = str(inbuf)
+    inbuf = createStr(inbuf)
     inlen = c_int(len(inbuf))
     hyphen_string = create_string_buffer(inlen.value)
if not liblouis.lou_hyphenate(tablesString, inbuf, inlen, hyphen_string, mode):
@@ -297,3 +304,4 @@
     print(version())
print(translate([b'../tables/en-us-g2.ctb'], 'Hello world!', cursorPos=5))

+
For a description of the software, to download it and links to
project pages go to http://www.abilitiessoft.com

Other related posts:

  • » [liblouis-liblouisxml] [liblouis] r619 committed - Changed the python3 bindings so they should work for both python2 and ... - liblouis