[liblouis-liblouisxml] [liblouis] r610 committed - Some initial python3 code, not guaranteed to be fully working but wort...

  • From: liblouis@xxxxxxxxxxxxxx
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Sun, 13 May 2012 21:54:23 +0000

Revision: 610
Author:   mwhapples@xxxxxxxxx
Date:     Sun May 13 14:54:14 2012
Log: Some initial python3 code, not guaranteed to be fully working but worth testing
http://code.google.com/p/liblouis/source/detail?r=610

Added:
 /trunk/python3
Modified:
 /trunk/python3/louis/__init__.py.in
 /trunk/windows/configure.mk

=======================================
--- /trunk/python/louis/__init__.py.in  Mon Feb 27 01:13:17 2012
+++ /trunk/python3/louis/__init__.py.in Sun May 13 14:54:14 2012
@@ -35,6 +35,11 @@
 import struct
 import atexit

+# 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])
+
 #{ Module Configuration
 #: Specifies the number by which the input length should be multiplied
 #: to calculate the maximum output length.
@@ -85,7 +90,7 @@
         the release date and perhaps notable changes.
     @rtype: str
     """
-    return liblouis.lou_version()
+    return liblouis.lou_version().decode("ASCII")

 def translate(tableList, inbuf, typeform=None,cursorPos=0, mode=0):
     """Translate a string of characters, providing position information.
@@ -108,8 +113,8 @@
     @raise RuntimeError: If a complete translation could not be done.
     @see: lou_translate in the liblouis documentation
     """
-    tablesString = ",".join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    tablesString = _createTablesString(tableList)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -143,8 +148,8 @@
     @raise RuntimeError: If a complete translation could not be done.
     @see: lou_translateString in the liblouis documentation
     """
-    tablesString = ",".join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    tablesString = _createTablesString(tableList)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value*outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -179,8 +184,8 @@
     @raises RuntimeError: If back translation could not be completed.
     @see: lou_backTranslate in the liblouis documentation.
     """
-    tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    tablestring = _createTablesString(tableList)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -214,8 +219,8 @@
     @raises RuntimeError: If a full back translation could not be done.
     @see: lou_backTranslateString in the liblouis documentation.
     """
-    tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    tablestring = _createTablesString(tableList)
+    inbuf = str(inbuf)
     inlen = c_int(len(inbuf))
     outlen = c_int(inlen.value * outlenMultiplier)
     outbuf = create_unicode_buffer(outlen.value)
@@ -247,12 +252,12 @@
     @raises RuntimeError: If hyphenation data could not be produced.
     @see: lou_hyphenate in the liblouis documentation.
     """
-    tablestring = ','.join([str(x) for x in tableList])
-    inbuf = unicode(inbuf)
+    tablesString = _createTablesString(tableList)
+    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): - raise RuntimeError("Can't hyphenate tables %s, inbuf %s, mode %d" %(tablestring, inbuf, mode)) + if not liblouis.lou_hyphenate(tablesString, inbuf, inlen, hyphen_string, mode): + raise RuntimeError("Can't hyphenate tables %s, inbuf %s, mode %d" %(tablesString, inbuf, mode))
     return hyphen_string.value

 def compileString(tableList, inString):
@@ -264,7 +269,8 @@
     @raise RuntimeError: If compilation of the entry failed.
     @see: lou_compileString in the liblouis documentation
     """
-    tablesString = ",".join([str(x) for x in tableList])
+    tablesString = _createTablesString(tableList)
+ inBytes = inString.encode("ASCII") if isinstance(inString, str) else bytes(inString)
     if not liblouis.lou_compileString(tablesString, inString):
raise RuntimeError("Can't compile entry: tables %s, inString %s" % (tableList, inString))

@@ -288,5 +294,6 @@

 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([b'../tables/en-us-g2.ctb'], 'Hello world!', cursorPos=5))
+
=======================================
--- /trunk/windows/configure.mk Sun Jun 12 15:24:29 2011
+++ /trunk/windows/configure.mk Sun May 13 14:54:14 2012
@@ -1,2 +1,2 @@
-UCS=2
-
+UCS=4
+
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] r610 committed - Some initial python3 code, not guaranteed to be fully working but wort... - liblouis