def transliterate(text, inFormat, outFormat, requestOptions={}):
def asciiEncode(chr):<EOL><INDENT>value = ord(chr)<EOL>if value > <NUM_LIT:255>:<EOL><INDENT>return '<STR_LIT>' % (value)<EOL><DEDENT>return chr<EOL><DEDENT>try:<EOL><INDENT>options.update(requestOptions)<EOL>"""<STR_LIT>"""<EOL>basestring = (str, bytes)<EOL>"""<STR_LIT>"""<EOL>def findFormat(fmt):<EOL><INDENT>if isinstance(fmt, basestring):<EOL><INDENT>try:<EOL><INDENT>fmt = _names[fmt.upper()]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise (ValueError, '<STR_LIT>' + fmt)<EOL><DEDENT><DEDENT>return fmt<EOL><DEDENT>inFormat = findFormat(inFormat)<EOL>outFormat = findFormat(outFormat)<EOL>"""<STR_LIT>"""<EOL>if not isinstance(text, basestring): <EOL><INDENT>raise (TypeError, "<STR_LIT>")<EOL><DEDENT>def getBlock(format):<EOL><INDENT>if isinstance(format, CharacterBlock):<EOL><INDENT>return format<EOL><DEDENT>else:<EOL><INDENT>return format.block<EOL><DEDENT><DEDENT>inBlock = getBlock(inFormat)<EOL>outBlock = getBlock(outFormat)<EOL>if not inBlock is outBlock:<EOL><INDENT>raise (ValueError, "<STR_LIT>")<EOL><DEDENT>if inFormat is outFormat:<EOL><INDENT>if inFormat._longestEntry == <NUM_LIT:1>:<EOL><INDENT>[inFormat[c] for c in set(text) if not c.isspace()] <EOL>return text<EOL><DEDENT><DEDENT>"""<STR_LIT>"""<EOL>result = inFormat._transliterate(text, outFormat)<EOL>if options['<STR_LIT>']:<EOL><INDENT>result = [asciiEncode(c) for c in result]<EOL><DEDENT>return u'<STR_LIT>'.join(result).encode(options['<STR_LIT>'])<EOL><DEDENT>finally:<EOL><INDENT>resetOptions()<EOL><DEDENT>
Transliterate a text.

    Keyword arguments:
    text -- a unicode string containing the text to be transliterated
    inFormat -- the "from" CharacterBlock or TransliterationScheme, or its name
    outFormat -- the target CharacterBlock or TransliterationScheme, or its name
    requestOptions -- optional dict containing option settings that override the
                      defaults for this request.

    Returns a unicode object containing the text transliterated into the
    target character set.

    Raises:
    ValueError -- unrecognised input or output format.
    KeyError -- a character in text is not a member of inFormat, or has no
    corresponding character defined in outFormat.