7322N/ABackport of Python 3 changes from upstream git:
7322N/A+# Some general utility functions
7322N/A+def _createTablesString(tablesList):
7322N/A+ """Creates a tables string for liblouis calls"""
7322N/A+ return b",".join([
x.encode("ASCII") if isinstance(x, str) else bytes(x) for x in tablesList])
7322N/A+ createStr = lambda x: unicode(x)
7322N/A+ createStr = lambda x: str(x)
7322N/A #: Specifies the number by which the input length should be multiplied
7322N/A the release date and perhaps notable changes.
7322N/A def translate(tableList, inbuf, typeform=None,cursorPos=0, mode=0):
7322N/A """Translate a string of characters, providing position information.
7322N/A @param tableList: A list of translation tables.
7322N/A @type tableList: list of str
7322N/A @param inbuf: The string to translate.
7322N/A @param typeform: A list of typeform constants indicating the typeform for each position in inbuf,
7322N/A C{None} for no typeform information.
7322N/A @type typeform: list of int
7322N/A a list of input positions for each position in the output,
7322N/A a list of output positions for each position in the input, and
7322N/A the position of the cursor in the output.
7322N/A- @rtype: (unicode, list of int, list of int, int)
7322N/A+ @rtype: (str, list of int, list of int, int)
7322N/A @raise RuntimeError: If a complete translation could not be done.
7322N/A @see: lou_translate in the liblouis documentation
7322N/A- tablesString = ",".join([str(x) for x in tableList])
7322N/A+ tablesString = _createTablesString(tableList)
7322N/A @param tableList: A list of translation tables.
7322N/A @type tableList: list of str
7322N/A @param inbuf: The string to translate.
7322N/A @param typeform: A list of typeform constants indicating the typeform for each position in inbuf,
7322N/A C{None} for no typeform information.
7322N/A @type typeform: list of int
7322N/A @param mode: The translation mode; add multiple values for a combined mode.
7322N/A @return: The translated string.
7322N/A @raise RuntimeError: If a complete translation could not be done.
7322N/A @see: lou_translateString in the liblouis documentation
7322N/A- tablesString = ",".join([str(x) for x in tableList])
7322N/A+ tablesString = _createTablesString(tableList)
7322N/A @param tableList: A list of translation tables.
7322N/A @type tableList: list of str
7322N/A @param inbuf: Braille to back translate.
7322N/A @param typeform: List where typeform constants will be placed.
7322N/A @param cursorPos: Position of cursor.
7322N/A a list of input positions for each position in the output,
7322N/A a list of the output positions for each position in the input and
7322N/A the position of the cursor in the output.
7322N/A- @rtype: (unicode, list of int, list of int, int)
7322N/A+ @rtype: (str, list of int, list of int, int)
7322N/A @raises RuntimeError: If back translation could not be completed.
7322N/A @see: lou_backTranslate in the liblouis documentation.
7322N/A- tablestring = ','.join([str(x) for x in tableList])
7322N/A+ tablestring = _createTablesString(tableList)
7322N/A @param tableList: A list of translation tables.
7322N/A @type tableList: list of str
7322N/A @param inbuf: The Braille to back translate.
7322N/A @param typeform: List for typeform constants to be put in.
7322N/A If you don't want typeform data then give None
7322N/A @param mode: The translation mode
7322N/A @return: The back translation of inbuf.
7322N/A @raises RuntimeError: If a full back translation could not be done.
7322N/A @see: lou_backTranslateString in the liblouis documentation.
7322N/A- tablestring = ','.join([str(x) for x in tableList])
7322N/A+ tablestring = _createTablesString(tableList)
7322N/A @param inbuf: The text to get hyphenation information about.
7322N/A and punctuation is ignored.
7322N/A @param mode: Lets liblouis know if inbuf is plain text or Braille.
7322N/A Set to 0 for text and anyother value for Braille.
7322N/A @raises RuntimeError: If hyphenation data could not be produced.
7322N/A @see: lou_hyphenate in the liblouis documentation.
7322N/A- tablestring = ','.join([str(x) for x in tableList])
7322N/A+ tablesString = _createTablesString(tableList)
7322N/A- raise RuntimeError("Can't hyphenate tables %s, inbuf %s, mode %d" %(tablestring, inbuf, mode))
7322N/A+ raise RuntimeError("Can't hyphenate tables %s, inbuf %s, mode %d" %(tablesString, inbuf, mode))
7322N/A def compileString(tableList, inString):
7322N/A """Compile a table entry on the fly at run-time.
7322N/A @raise RuntimeError: If compilation of the entry failed.
7322N/A @see: lou_compileString in the liblouis documentation
7322N/A- tablesString = ",".join([str(x) for x in tableList])
7322N/A+ tablesString = _createTablesString(tableList)
7322N/A raise RuntimeError("Can't compile entry: tables %s, inString %s" % (tableList, inString))