# -*- coding: utf-8 -*- import sys, re, string, urllib, htmlentitydefs import edbm def wrap(text, width): """ A word-wrap function that preserves existing line breaks and most spaces in the text. Expects that existing line breaks are posix newlines (\n). """ return reduce(lambda line, word, width=width: '%s%s%s' % (line, [' ', '\n '][(len(line[line.rfind('\n')+1:]) + len(word.split('\n',1)[0]) >= width)], word), text.split(' ')) def url_escape(text): return urllib.quote_plus(text) def html_escape(text): text = string.replace(text, '&', '&') text = string.replace(text, '<', '<') text = string.replace(text, '>', '>') return text def iso2ascii(text): for c in '\xc0\xc1\xc2\xc3\xc5\xe0\xe1\xe2\xe3\xe5': text = string.replace(text, c, 'a') for c in '\xc7\xe7': text = string.replace(text, c, 'c') for c in '\xc8\xc9\xca\xcb\xe8\xe9\xea\xeb': text = string.replace(text, c, 'e') for c in '\xcc\xcd\xce\xcf\xec\xed\xee\xef': text = string.replace(text, c, 'i') for c in '\xd1\xf1': text = string.replace(text, c, 'n') for c in '\xd2\xd3\xd4\xd5\xf2\xf3\xf4\xf5': text = string.replace(text, c, 'o') for c in '\xd9\xda\xdb\xf9\xfa\xfb': text = string.replace(text, c, 'u') for c in '\xdd\xfd\xff': text = string.replace(text, c, 'y') text = string.replace(text, '\xe4', 'ae') text = string.replace(text, '\xf6', 'oe') text = string.replace(text, '\xfc', 'ue') text = string.replace(text, '\xc4', 'Ae') text = string.replace(text, '\xd6', 'Oe') text = string.replace(text, '\xdc', 'Ue') text = string.replace(text, '\xdf', 'ss') text = string.replace(text, '\xd8', 'o') text = string.replace(text, '\xf8', 'O') text = string.replace(text, '\xc6', 'ae') text = string.replace(text, '\xe6', 'AE') return text def utf82ascii(text): chars = { 'A' : ['\xc3\x80', '\xc3\x81', '\xc3\x82', '\xc3\x83', '\xc3\x85', '\xc4\x80', '\xc4\x82', '\xc4\x84'], 'C' : ['\xc3\x87', '\xc4\x86', '\xc4\x88', '\xc4\x8a', '\xc4\x8c'], 'D' : ['\xc4\x8e', '\xc4\x90'], 'E' : ['\xc3\x88', '\xc3\x89', '\xc3\x8a', '\xc3\x8b', '\xc4\x92', '\xc4\x94', '\xc4\x96', '\xc4\x98', '\xc4\x9a'], 'G' : ['\xc4\x9c', '\xc4\x9e', '\xc4\xa0', '\xc4\xa2'], 'H' : ['\xc4\xa4', '\xc4\xa6'], 'I' : ['\xc3\x8c', '\xc3\x8d', '\xc3\x8e', '\xc3\x8f', '\xc4\xa8', '\xc4\xaa', '\xc4\xac', '\xc4\xae', '\xc4\xb0'], 'J' : ['\xc4\xb4'], 'K' : ['\xc4\xb6'], 'L' : ['\xc4\xb9', '\xc4\xbb', '\xc4\xbd', '\xc4\xbf', '\xc5\x81'], 'N' : ['\xc3\x91', '\xc5\x83', '\xc5\x85', '\xc5\x87'], 'O' : ['\xc3\x92', '\xc3\x93', '\xc3\x94', '\xc3\x95', '\xc3\x96', '\xc3\x98', '\xc5\x8c', '\xc5\x8e', '\xc5\x90'], 'R' : ['\xc5\x94', '\xc5\x96', '\xc5\x98'], 'S' : ['\xc5\x9a', '\xc5\x9c', '\xc5\x9e', '\xc5\xa0'], 'T' : ['\xc5\xa2', '\xc5\xa4', '\xc5\xa6'], 'U' : ['\xc3\x99', '\xc3\x9a', '\xc3\x9b', '\xc5\xa8', '\xc5\xaa', '\xc5\xac', '\xc5\xae', '\xc5\xb0', '\xc5\xb2'], 'W' : ['\xc5\xb4'], 'Y' : ['\xc3\x9d', '\xc5\xb6', '\xc5\xb8'], 'Z' : ['\xc5\xb9', '\xc5\xbb', '\xc5\xbd'], 'a' : ['\xc3\xa0', '\xc3\xa1', '\xc3\xa2', '\xc3\xa3', '\xc3\xa5', '\xc4\x81', '\xc4\x83', '\xc4\x85'], 'c' : ['\xc3\xa7', '\xc4\x87', '\xc4\x89', '\xc4\x8b', '\xc4\x8d'], 'd' : ['\xc4\x8f', '\xc4\x91'], 'e' : ['\xc3\xa8', '\xc3\xa9', '\xc3\xaa', '\xc3\xab', '\xc4\x93', '\xc4\x95', '\xc4\x97', '\xc4\x99', '\xc4\x9b'], 'g' : ['\xc4\x9d', '\xc4\x9f', '\xc4\xa1', '\xc4\xa3'], 'h' : ['\xc4\xa5', '\xc4\xa7'], 'i' : ['\xc3\xac', '\xc3\xad', '\xc3\xae', '\xc3\xaf', '\xc4\xa9', '\xc4\xab', '\xc4\xad', '\xc4\xaf', '\xc4\xb1'], 'j' : ['\xc4\xb5'], 'k' : ['\xc4\xb7'], 'l' : ['\xc4\xba', '\xc4\xbc', '\xc4\xbe', '\xc5\x80', '\xc5\x82'], 'n' : ['\xc3\xb1', '\xc5\x84', '\xc5\x86', '\xc5\x88', '\xc5\x89'], 'o' : ['\xc3\xb2', '\xc3\xb3', '\xc3\xb4', '\xc3\xb5', '\xc3\xb8', '\xc5\x8d', '\xc5\x8f', '\xc5\x91'], 'r' : ['\xc5\x95', '\xc5\x97', '\xc5\x99'], 's' : ['\xc5\x9b', '\xc5\x9d', '\xc5\x9f', '\xc5\xa1'], 't' : ['\xc5\xa3', '\xc5\xa5', '\xc5\xa7'], 'u' : ['\xc3\xb9', '\xc3\xba', '\xc3\xbb', '\xc5\xa9', '\xc5\xab', '\xc5\xad', '\xc5\xaf', '\xc5\xb1', '\xc5\xb3'], 'w' : ['\xc5\xb5'], 'y' : ['\xc3\xbd', '\xc3\xbf', '\xc5\xb7'], 'z' : ['\xc5\xba', '\xc5\xbc', '\xc5\xbe'], } umlauts = { 'Ae' : ['\xc3\x84'], 'Oe' : ['\xc3\x96'], 'Ue' : ['\xc3\x9c'], 'ae' : ['\xc3\xa4', '\xc3\xa6'], 'oe' : ['\xc3\xb6', '\xc5\x93'], 'ue' : ['\xc3\xbc'], 'ss' : ['\xc3\x9f'], 'AE' : ['\xc3\x86'], 'OE' : ['\xc5\x92'], } greek = { r'\Alpha ' : ['\xce\x91'], r'\Beta ' : ['\xce\x92'], r'\Gamma ' : ['\xce\x93'], r'\Delta ' : ['\xce\x94'], r'\Epsilon ' : ['\xce\x95'], r'\Zeta ' : ['\xce\x96'], r'\Eta ' : ['\xce\x97'], r'\Theta ' : ['\xce\x98'], r'\Iota ' : ['\xce\x99'], r'\Kappa ' : ['\xce\x9a'], r'\Lamda ' : ['\xce\x9b'], r'\Mu ' : ['\xce\x9c'], r'\Nu ' : ['\xce\x9d'], r'\Xi ' : ['\xce\x9e'], r'\Omicron ' : ['\xce\x9f'], r'\Pi ' : ['\xce\xa0'], r'\Rho ' : ['\xce\xa1'], r'\Sigma ' : ['\xce\xa3'], r'\Tau ' : ['\xce\xa4'], r'\Upsilon ' : ['\xce\xa5'], r'\Phi ' : ['\xce\xa6'], r'\Chi ' : ['\xce\xa7'], r'\Psi ' : ['\xce\xa8'], r'\Omega ' : ['\xce\xa9'], r'\alpha ' : ['\xce\xb1'], r'\beta ' : ['\xce\xb2'], r'\gamma ' : ['\xce\xb3'], r'\delta ' : ['\xce\xb4'], r'\epsilon' : ['\xcf\xb5'], r'\zeta ' : ['\xce\xb6'], r'\eta ' : ['\xce\xb7'], r'\theta' : ['\xce\xb8'], r'\iota ' : ['\xce\xb9'], r'\kappa ' : ['\xce\xba'], r'\lamda ' : ['\xce\xbb'], r'\mu ' : ['\xce\xbc'], r'\nu ' : ['\xce\xbd'], r'\xi ' : ['\xce\xbe'], r'\omicron ' : ['\xce\xbf'], r'\pi' : ['\xcf\x80'], r'\rho' : ['\xcf\x81'], r'\sigma' : ['\xcf\x83'], r'\tau ' : ['\xcf\x84'], r'\upsilon ' : ['\xcf\x85'], r'\phi' : ['\xcf\x95'], r'\chi ' : ['\xcf\x87'], r'\psi ' : ['\xcf\x88'], r'\omega ' : ['\xcf\x89'], r'\varepsilon' : ['\xce\xb5'], r'\vartheta' : ['\xcf\x91'], r'\varpi' : ['\xcf\x96'], r'\varrho' : ['\xcf\xb1'], r'\varsigma' : ['\xcf\x82'], r'\varphi' : ['\xcf\x86'], } for char, list in umlauts.items() + chars.items(): for code in list: text = string.replace(text, code, char) return text def text2html(text): for key, value in htmlentitydefs.codepoint2name.items(): if key < 256 and key != 34: text = text.replace(chr(key), "&%s;" % (value)) text = re.sub('[\x80-\xff]+', ' ', text) return text _ascii_patterns = [ [r"\\\" *([AOUaou])","\\1e", 0], [r"\\[\"H] *{([AOUaou])}","\\1e", 0], [r"\\H +([AOUaou])","\\1e", 0], [r"{\\[`'^~=.\"uvtcdbHBD] *{(.)}}", "\\1", 0], [r"{\\[`'^~=.\"uvtcdbHBD] *(.)}", "\\1", 0], [r"\\[`'^~=.\"uvtcdbHBD] *{(.)}", "\\1", 0], [r"\\[`'^~=.\"] *", "", 0], [r"\\[uvtcdbHBD] +", "", 0], [r"(\\[`'^~=.\"uvtcdbHBD])[\\{]", "", 1], [r"{\\['\"`^~=.] *\\i}", "i", 0], [r"{\\['\"`^~=.uvtcdbHBD] *{\\i}}", "i", 0], [r"\\([ijlL]) *{(.?)}", "\\1\\2", 0], [r"\\([ijlL]) +", "\\1", 0], [r"(\\i)([\\{\d\W]|$)", "i", 1], [r"(\\j)([\\{\d\W]|$)", "j", 1], [r"{\\([ijlL]) *}", "\\1", 0], [r"(\\l)([\\{\d\W]|$)", "l", 1], [r"(\\L)([\\{\d\W]|$)", "L", 1], [r"\\AA *{(.?)}","A\\1", 0], [r"(\\AA)([\\{\d\W]|$)", "A", 1], [r"\\AA +","A", 0], [r"{\\AA *}","A", 0], [r"\\AE *{(.?)}","AE\\1", 0], [r"\\AE +","AE", 0], [r"(\\AE)([\\{\d\W]|$)","AE", 1], [r"{\\AE *}","AE", 0], [r"\\O *{(.?)}","OE\\1", 0], [r"(\\O)([\\{\d\W]|$)","OE", 1], [r"\\O +","OE", 0], [r"{\\O *}","OE", 0], [r"\\o *{(.?)}","oe\\1", 0], [r"(\\o)([\\{\d\W]|$)","oe", 1], [r"\\o +","oe", 0], [r"{\\o *}","oe", 0], [r"\\OE *{(.?)}", "OE\\1", 0], [r"\\OE +","OE", 0], [r"(\\OE)([\\{\d\W]|$)", "OE", 1], [r"{\\OE *}","OE", 0], [r"\\oe *{(.?)}", "oe\\1", 0], [r"\\oe +","oe", 0], [r"(\\oe)([\\{\d\W]|$)", "oe", 1], [r"{\\oe *}","oe", 0], [r"\\aa *{(.?)}","a\\1", 0], [r"\\aa +","a", 0], [r"(\\aa)([\\{\d\W]|$)", "a", 1], [r"{\\aa *}","a", 0], [r"\\ae *{(.?)}","ae\\1", 0], [r"\\ae +","ae", 0], [r"(\\ae)([\\{\d\W]|$)", "ae", 1], [r"{\\ae *}","ae", 0], [r"\\uu *{(.?)}", "u\\1", 0], [r"\\uu +","u", 0], [r"(\\uu)([\\{\d\W]|$)", "u", 1], [r"{\\uu *}","u", 0], [r"\\oo *{(.?)}", "o\\1", 0], [r"\\oo +","o", 0], [r"(\\oo)([\\{\d\W]|$)", "o", 1], [r"{\\oo *}", "o", 0], [r"\\UU *{(.?)}", "U\\1", 0], [r"\\UU +","U", 0], [r"(\\UU)([\\{\d\W]|$)", "U", 1], [r"{\\UU *}","U", 0], [r"\\[^\"`'] *\\j( *{}| +|$)", "j", 0], [r"\\[^\"`'] *\\j([\d\W])", "j\\1", 0], [r"\\dj *{(.?)}", "dj\\1", 0], [r"\\dj +", "dj", 0], [r"(\\dj)([\\{\d\W]|$)", "d", 1], [r"{\\dj *}", "dj", 0], [r"\\Dj *{(.?)}", "Dj\\1", 0], [r"\\Dj +", "Dj", 0], [r"(\\Dj)(\\| *{)", "Dj", 0], [r"{\\Dj *}", "Dj", 0], [r"\\oe *{(.?)}", "oe\\1", 0], [r"\\oe +","oe", 0], [r"(\\oe)([\\{\d\W]|$)","oe", 1], [r"\\ss *{(.?)}","ss\\1", 0], [r"\\ss +","ss", 0], [r"(\\ss)([\\{\d\W]|$)", "ss", 1], [r"{\\ss *}","ss", 0], ] edbm.chconv.set_ascii_patterns(_ascii_patterns) def tex2ascii(text): text = edbm.chconv.tex2ascii(text) text = re.sub("{([a-zA-Z]+)}", r"\1", text) return text _iso_patterns = [ [r'\\[H"] *{(\w)}', 5, 0], [r'\\" *(\w)',5, 0], [r'{\\" *(\w)}',5, 0], [r'{\\" *{\\(.)}}',5, 0], [r"\\` *{(\w)}",2, 0], [r"\\` *(\w)",2, 0], [r"{\\` *(\w)}",2, 0], [r"\\' *{(\w)}",1, 0], [r"\\' *(\w)",1, 0], [r"{\\' *(\w)}",1, 0], [r"\\\^ *{(\w)}",3, 0], [r"\\\^ *(\w)",3, 0], [r"{\\\^ *(\w)}",3, 0], [r"\\~ *{(\w)}",4, 0], [r"\\~ *(\w)",4, 0], [r"{\\~ *(\w)}",4, 0], [r"\\H +(\w)",5, 0], [r"{\\H +(\w)}",5, 0], [r"\\' *{\\(.)}", 1, 0], [r"\\' *\\(.)( +|$)", 1, 0], [r"{\\' *\\(.)}", 1, 0], [r"{\\' *{\\(.)}}", 1, 0], [r"\\` *{\\(.)}", 2, 0], [r"\\` *\\(.)( +|$)", 2, 0], [r"{\\` *\\(.)}", 2, 0], [r"\\\^ *{\\(.)}", 3, 0], [r"\\\^ *\\(.)( +|$)", 3, 0], [r"{\\\^ *\\(.)}", 3, 0], [r"{\\\^ *{\\(.)}}", 3, 0], [r'{\\["H] *\\i}', "\357", 0], [r'\\["H] *\\i *{(.?)}',"\357\\1", 0], [r'\\["H] *\\i( +|$)',"\357", 0], [r'(\\["H] *\\i)([\d\W]|$)',"\357", 1], [r"\\' *\\i *{(.?)}","\355\\1", 0], [r"(\\' *\\i)([\d\W]|$)","\355", 1], [r'\\["H] *{\\i *}',"\357", 0], [r"\\[^\"`'] *\\j( *{}| +|$)", "j", 0], [r"\\[^\"`'] *\\j([\d\W])", "j\\1", 0], [r"\\c( +c| *{c})","\347", 0], [r"{\\c{c}}","\347", 0], [r"\\c( +C| *{C})","\307", 0], [r"\\[`'^~=.\"uvtcdbHBD] *{(.)}", "\\1", 0], [r"{\\[`'^~=.\"uvtcdbHBD] *{(.)}}", "\\1", 0], [r"\\[`'^~=.\"] *", "", 0], [r"{\\[`'^~=.\"]([a-zA-Z])}", "\\1", 0], [r"\\[uvtcdbHBD] +", "", 0], [r"{\\[uvtcdbHBD]{\\(.)}}", "\\1", 0], [r"(\\[`'^~=.\"uvtcdbHBD])[\\{]", "", 1], [r"\\([ijlL]) *{(.?)}", "\\1\\2", 0], [r"\\([ijlL]) +", "\\1", 0], [r"(\\i)([\d\W]|$)", "i", 1], [r"(\\j)([\d\W]|$)", "j", 1], [r"{\\([ijlL]) *}", "\\1", 0], [r"(\\l)([\d\W]|$)", "l", 1], [r"(\\L)([\d\W]|$)", "L", 1], [r"\\AA *{(.?)}","\305\\1", 0], [r"(\\AA)([\d\W]|$)", "\305", 0], [r"\\AA +","\305", 0], [r"{\\AA *}","\305", 0], [r"\\AE *{(.?)}","AE\\1", 0], [r"\\AE +","AE", 0], [r"(\\AE)([\d\W]|$)","AE", 1], [r"{\\AE *}","AE", 0], [r"\\O *{(.?)}","\330\\1", 0], [r"(\\O)([\d\W]|$)","\330", 1], [r"\\O +","\330", 0], [r"{\\O *}","\330", 0], [r"\\o *{(.?)}","\370\\1", 0], [r"(\\o)([\d\W]|$)","\370", 1], [r"\\o +","\370", 0], [r"{\\o *}","\370", 0], [r"\\OE *{(.?)}", "OE\\1", 0], [r"\\OE +","OE", 0], [r"(\\OE)([\d\W]|$)", "OE", 1], [r"{\\OE *}","OE", 0], [r"\\aa *{(.?)}","\345\\1", 0], [r"\\aa +","\345", 0], [r"(\\aa)([\d\W]|$)", "\345", 1], [r"{\\aa *}","\345", 0], [r"\\ae *{(.?)}","ae\\1", 0], [r"\\ae +","ae", 0], [r"(\\ae)([\d\W]|$)", "ae", 1], [r"{\\ae *}","ae", 0], [r"\\uu *{(.?)}", "u\\1", 0], [r"\\uu +","u", 0], [r"(\\uu)([\d\W]|$)", "u", 1], [r"{\\uu *}","u", 0], [r"\\oo *{(.?)}", "o\\1", 0], [r"\\oo +","o", 0], [r"(\\oo)([\d\W]|$)", "o", 1], [r"{\\oo *}", "o", 0], [r"\\UU *{(.?)}", "U\\1", 0], [r"\\UU +","U", 0], [r"(\\UU)([\d\W]|$)", "U", 1], [r"{\\UU *}","U", 0], [r"\\[^\"`'] *\\j( *{}| +|$)", "j", 0], [r"\\[^\"`'] *\\j([\d\W])", "j\\1", 0], [r"\\dj *{(.?)}", "dj\\1", 0], [r"\\dj +", "dj", 0], [r"(\\dj)([\d\W]|$)", "dj", 1], [r"{\\dj *}", "dj", 0], [r"\\Dj *{(.?)}", "Dj\\1", 0], [r"\\Dj +", "Dj", 0], [r"(\\Dj)([\d\W]|$)", "Dj", 0], [r"{\\Dj *}", "Dj", 0], [r"\\oe *{(.?)}", "oe\\1", 0], [r"\\oe +","oe", 0], [r"(\\oe)([\d\W]|$)","oe", 1], [r"{\\oe *}","oe", 0], [r"\\ss *{(.?)}","\337\\1", 0], [r"\\ss +","\337", 0], [r"(\\ss)([\d\W]|$)", "\337", 1], [r"{\\ss *}","\337", 0], ] edbm.chconv.set_iso_patterns(_iso_patterns) def tex2iso(text): text = edbm.chconv.tex2iso(text) text = re.sub("{([a-zA-Z]+)}", r"\1", text) return text _utf8_patterns = [ [r"\\' *(\w)", 1, 0], [r"\\' *{(\w)}", 1, 0], [r"{\\' *(\w)}", 1, 0], [r"{\\' *{\\([ijIJ])}}", 1, 0], [r"\\` *(\w)", 2, 0], [r"\\` *{(\w)}", 2, 0], [r"{\\` *(\w)}", 2, 0], [r"\\\^ *(\w)", 3, 0], [r"\\\^ *{(\w)}", 3, 0], [r"{\\\^ *(\w)}", 3, 0], [r"\\~ *(\w)", 4, 0], [r"\\~ *{(\w)}", 4, 0], [r"{\\~ *(\w)}", 4, 0], [r'\\\"(\w)', 5, 0], [r'\\\"{(\w)}', 5, 0], [r'{\\\"(\w)}', 5, 0], [r'\\H +(\w)', 5, 0], [r'\\H +{(\w)}', 5, 0], [r'{\\H +(\w)}', 5, 0], [r"\\c +(\w)", 6, 0], [r"\\c *{(\w)}", 6, 0], [r"{\\c +(\w)}", 6, 0], [r"\\=(\w)", 7, 0], [r"\\={(\w)}", 7, 0], [r"{\\=(\w)}", 7, 0], [r"\\B +(\w)", 7, 0], [r"\\B +{(\w)}", 7, 0], [r"{\\B +(\w)}", 7, 0], [r"\\u +(\w)", 8, 0], [r"\\u *{(\w)}", 8, 0], [r"{\\u +(\w)}", 8, 0], [r"\\\.(\w)", 9, 0], [r"\\\.{(\w)}", 9, 0], [r"{\\\.(\w)}", 9, 0], [r"\\D +(\w)", 9, 0], [r"\\D +{(\w)}", 9, 0], [r"{\\D +(\w)}", 9, 0], [r"\\v +(\w)", 10, 0], [r"\\v *{(\w)}", 10, 0], [r"{\\v +(\w)}", 10, 0], [r"\\d +(\w)", 11, 0], [r"\\d *{(\w)}", 11, 0], [r"{\\d +(\w)}", 11, 0], [r"\\b +(\w)", 12, 0], [r"\\b *{(\w)}", 12, 0], [r"{\\b +(\w)}", 12, 0], [r"\\' *\\AE( +|$)", 0, 0x01fc], [r"\\AA( +|$)", 0, 0x00c5], [r"{\\AA}", 0, 0x00c5], [r"\\aa( +|$)", 0, 0x00e5], [r"{\\aa}", 0, 0x00e5], [r"{\\l}", 0, 0x0142], [r"{\\L}", 0, 0x0141], [r"\\l( +|$)", 0, 0x0142], [r"\\L( +|$)", 0, 0x0141], [r"\\i( +|$)", 0, 0x69], [r"{\\i}", 0, 0x69], [r"{\\o}", 0, 0x00f8], [r"\\o +", 0, 0x00f8], [r"{\\O}", 0, 0x00d8], [r"\\O +", 0, 0x00d8], ] edbm.chconv.set_utf8_patterns(_utf8_patterns) def tex2utf8(text): text = re.sub(r'{\\([ij])}', r' \1', text) text = string.replace(text, r'{\ss}', 'ss') text = string.replace(text, r'{\ae}', 'ae') text = string.replace(text, r'{\oe}', 'oe') text = string.replace(text, r'{\uu}', 'uu') text = edbm.chconv.tex2utf8(text) if 0: text = string.replace(text, r'$\Alpha$', '\xce\x91') text = string.replace(text, r'$\Beta$', '\xce\x92') text = string.replace(text, r'$\Gamma$', '\xce\x93') text = string.replace(text, r'$\Delta$', '\xce\x94') text = string.replace(text, r'$\Epsilon$', '\xce\x95') text = string.replace(text, r'$\Zeta$', '\xce\x96') text = string.replace(text, r'$\Eta$', '\xce\x97') text = string.replace(text, r'$\Theta$', '\xce\x98') text = string.replace(text, r'$\Iota$', '\xce\x99') text = string.replace(text, r'$\Kappa$', '\xce\x9a') text = string.replace(text, r'$\Lamda$', '\xce\x9b') text = string.replace(text, r'$\Mu$', '\xce\x9c') text = string.replace(text, r'$\Nu$', '\xce\x9d') text = string.replace(text, r'$\Xi$', '\xce\x9e') text = string.replace(text, r'$\Omicron$', '\xce\x9f') text = string.replace(text, r'$\Pi$', '\xce\xa0') text = string.replace(text, r'$\Rho$', '\xce\xa1') text = string.replace(text, r'$\Sigma$', '\xce\xa3') text = string.replace(text, r'$\Tau$', '\xce\xa4') text = string.replace(text, r'$\Upsilon$', '\xce\xa5') text = string.replace(text, r'$\Phi$', '\xce\xa6') text = string.replace(text, r'$\Chi$', '\xce\xa7') text = string.replace(text, r'$\Psi$', '\xce\xa8') text = string.replace(text, r'$\Omega$', '\xce\xa9') text = string.replace(text, r'$\alpha$', '\xce\xb1') text = string.replace(text, r'$\beta$', '\xce\xb2') text = string.replace(text, r'$\gamma$', '\xce\xb3') text = string.replace(text, r'$\delta$', '\xce\xb4') text = string.replace(text, r'$\epsilon$', '\xcf\xb5') text = string.replace(text, r'$\zeta$', '\xce\xb6') text = string.replace(text, r'$\eta$', '\xce\xb7') text = string.replace(text, r'$\theta$', '\xce\xb8') text = string.replace(text, r'$\iota$', '\xce\xb9') text = string.replace(text, r'$\kappa$', '\xce\xba') text = string.replace(text, r'$\lamda$', '\xce\xbb') text = string.replace(text, r'$\mu$', '\xce\xbc') text = string.replace(text, r'$\nu$', '\xce\xbd') text = string.replace(text, r'$\xi$', '\xce\xbe') text = string.replace(text, r'$\omicron$', '\xce\xbf') text = string.replace(text, r'$\pi$', '\xcf\x80') text = string.replace(text, r'$\rho$', '\xcf\x81') text = string.replace(text, r'$\sigma$', '\xcf\x83') text = string.replace(text, r'$\tau$', '\xcf\x84') text = string.replace(text, r'$\upsilon$', '\xcf\x85') text = string.replace(text, r'$\phi$', '\xcf\x95') text = string.replace(text, r'$\chi$', '\xcf\x87') text = string.replace(text, r'$\psi$', '\xcf\x88') text = string.replace(text, r'$\omega$', '\xcf\x89') text = string.replace(text, r'$\varepsilon$', '\xce\xb5') text = string.replace(text, r'$\vartheta$', '\xcf\x91') text = string.replace(text, r'$\varpi$', '\xcf\x96') text = string.replace(text, r'$\varrho$', '\xcf\xb1') text = string.replace(text, r'$\varsigma$', '\xcf\x82') text = string.replace(text, r'$\varphi$', '\xcf\x86') text = string.replace(text, r'\Alpha', '\xce\x91') text = string.replace(text, r'\Beta', '\xce\x92') text = string.replace(text, r'\Gamma', '\xce\x93') text = string.replace(text, r'\Delta', '\xce\x94') text = string.replace(text, r'\Epsilon', '\xce\x95') text = string.replace(text, r'\Zeta', '\xce\x96') text = string.replace(text, r'\Eta', '\xce\x97') text = string.replace(text, r'\Theta', '\xce\x98') text = string.replace(text, r'\Iota', '\xce\x99') text = string.replace(text, r'\Kappa', '\xce\x9a') text = string.replace(text, r'\Lamda', '\xce\x9b') text = string.replace(text, r'\Mu', '\xce\x9c') text = string.replace(text, r'\Nu', '\xce\x9d') text = string.replace(text, r'\Xi', '\xce\x9e') text = string.replace(text, r'\Omicron', '\xce\x9f') text = string.replace(text, r'\Pi', '\xce\xa0') text = string.replace(text, r'\Rho', '\xce\xa1') text = string.replace(text, r'\Sigma', '\xce\xa3') text = string.replace(text, r'\Tau', '\xce\xa4') text = string.replace(text, r'\Upsilon', '\xce\xa5') text = string.replace(text, r'\Phi', '\xce\xa6') text = string.replace(text, r'\Chi', '\xce\xa7') text = string.replace(text, r'\Psi', '\xce\xa8') text = string.replace(text, r'\Omega', '\xce\xa9') text = string.replace(text, r'\alpha', '\xce\xb1') text = string.replace(text, r'\beta', '\xce\xb2') text = string.replace(text, r'\gamma', '\xce\xb3') text = string.replace(text, r'\delta', '\xce\xb4') text = string.replace(text, r'\epsilon', '\xcf\xb5') text = string.replace(text, r'\zeta', '\xce\xb6') text = string.replace(text, r'\eta', '\xce\xb7') text = string.replace(text, r'\theta', '\xce\xb8') text = string.replace(text, r'\iota', '\xce\xb9') text = string.replace(text, r'\kappa', '\xce\xba') text = string.replace(text, r'\lamda', '\xce\xbb') text = string.replace(text, r'\mu', '\xce\xbc') text = string.replace(text, r'\nu', '\xce\xbd') text = string.replace(text, r'\xi', '\xce\xbe') text = string.replace(text, r'\omicron', '\xce\xbf') text = string.replace(text, r'\pi', '\xcf\x80') text = string.replace(text, r'\rho', '\xcf\x81') text = string.replace(text, r'\sigma', '\xcf\x83') text = string.replace(text, r'\tau', '\xcf\x84') text = string.replace(text, r'\upsilon', '\xcf\x85') text = string.replace(text, r'\phi', '\xcf\x95') text = string.replace(text, r'\chi', '\xcf\x87') text = string.replace(text, r'\psi', '\xcf\x88') text = string.replace(text, r'\omega', '\xcf\x89') text = string.replace(text, r'\varepsilon', '\xce\xb5') text = string.replace(text, r'\vartheta', '\xcf\x91') text = string.replace(text, r'varpi', '\xcf\x96') text = string.replace(text, r'\varrho', '\xcf\xb1') text = string.replace(text, r'\varsigma', '\xcf\x82') text = string.replace(text, r'\varphi', '\xcf\x86') return text