From 0c98d73e68782631f17f413a3a7451773dfd8197 Mon Sep 17 00:00:00 2001 From: László Németh Date: Tue, 4 Dec 2012 13:01:35 +0100 Subject: Python 3.3 port --- ChangeLog | 3 +++ Dialog.py | 24 ++++++++++++------------ Lightproof.py | 2 +- make.py | 21 ++++++++++++++------- pythonpath/lightproof___implname__.py | 1 + pythonpath/lightproof_compile___implname__.py | 8 ++++---- pythonpath/lightproof_impl___implname__.py | 6 +++--- src/en/en.cfg | 2 +- src/en/en.dat | 8 ++++---- src/hu_HU/ChangeLog | 3 +++ src/hu_HU/hu_HU.cfg | 2 +- src/hu_HU/hu_HU.dat | 12 ++++++------ 12 files changed, 53 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index a35e6ae..3113fab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2012-12-04 László Németh : + - Python 3.3 port + 2012-11-23 László Németh : - fix strange false positives resulted by a synchronization problem (missing alternatives with unloaded dictionary), the problem reported by Olivier Ronez diff --git a/Dialog.py b/Dialog.py index b652618..a405cc9 100644 --- a/Dialog.py +++ b/Dialog.py @@ -1,14 +1,14 @@ # -*- encoding: UTF-8 -*- +from __future__ import unicode_literals import sys import re -from string import split import os import codecs -comment = re.compile(ur"[\n#]") -ids = re.compile(ur"\w+:\s*\*?\w+(,\s*\*?\w+)*") -langu = re.compile(ur"\[.+=.+\]\s*") -titl = re.compile(ur"\w+\s*=\s*") +comment = re.compile(r"[\n#]") +ids = re.compile(r"\w+:\s*\*?\w+(,\s*\*?\w+)*") +langu = re.compile(r"\[.+=.+\]\s*") +titl = re.compile(r"\w+\s*=\s*") helptexts = [] xdl_header = """ @@ -30,17 +30,17 @@ oor:name="%s" oor:package="org.openoffice" xml:lang="en-US"> """ -xcs_leaf_header = ur""" +xcs_leaf_header = r""" The data for one leaf. """ -xcs_leaf = ur""" +xcs_leaf = r""" """ -xcs_leaf_footer = ur""" +xcs_leaf_footer = r""" """ xcs_component_header = """ @@ -128,13 +128,13 @@ def create_xdl(pkg, lines, target, lang): if state == 0: ok = True if ids.match(i.strip()): - j = split(i.strip(),":") + j = i.strip().split(":") f2 = f2 + xdl_group%(j[0].strip(), k, k2 * 10 + 5, j[0].strip()) - for l in split(j[1],","): + for l in j[1].split(","): k = k + 1 k2 = k2 + 1 l = l.strip() - la = split(l, " ") + la = l.split(" ") l3 = 0 itemlen = int(240 / len(la)) for l2 in la: @@ -175,7 +175,7 @@ def create_xdl(pkg, lines, target, lang): hlp[0] = hlp[0] + "\n" f2 = f2 + hlp[0] elif not ok: - print "Syntax error in line %d: %s" %(lin, i) + print ("Syntax error in line %d: %s" %(lin, i)) if "xdl" in f2n: f2 = f2 + xdl_footer target.writestr(f2n, f2) diff --git a/Lightproof.py b/Lightproof.py index 71d8be4..11afeab 100644 --- a/Lightproof.py +++ b/Lightproof.py @@ -1,6 +1,6 @@ # -*- encoding: UTF-8 -*- # Lightproof grammar checker for LibreOffice and OpenOffice.org -# 2009-2012 (c) László Németh (nemeth at numbertext org), license: MPL 1.1 / GPLv3+ / LGPLv3+ +# 2009-2012 (c) Laszlo Nemeth (nemeth at numbertext org), license: MPL 1.1 / GPLv3+ / LGPLv3+ import uno, unohelper, os, sys, traceback from lightproof_impl_${implname} import locales diff --git a/make.py b/make.py index f836e8a..c9381f3 100644 --- a/make.py +++ b/make.py @@ -1,6 +1,13 @@ # -*- encoding: UTF-8 -*- +#from __future__ import unicode_literals import sys, os, zipfile, traceback, Dialog -import ConfigParser as cp # configparser in Python 3 +try: + import ConfigParser as cp # configparser in Python 3 + uni = lambda i: unicode(i, "UTF-8") +except: + import configparser as cp + uni = str + import pythonpath.lightproof_compile___implname__ from string import Template @@ -10,14 +17,14 @@ def dist(fn, a): distname = a['implname'] + "-" + a['version'] + '.oxt' z = zipfile.ZipFile(distname, mode='w', compression = zipfile.ZIP_DEFLATED) f = open(fn + ".dat",'r') - code = pythonpath.lightproof_compile___implname__.c(unicode(f.read(), "UTF-8"), a['lang']) + code = pythonpath.lightproof_compile___implname__.c(uni(f.read()), a['lang']) a["code"] = code["code"] a['data'] = code["rules"] for i in ["META-INF/manifest.xml", "description.xml", "Linguistic.xcu", "Lightproof.py", \ "pythonpath/lightproof_handler___implname__.py", "pythonpath/lightproof_impl___implname__.py", \ "pythonpath/lightproof___implname__.py" ]: - z.writestr(i.replace("__implname__", a["implname"]), Template(open(i, "r").read()).safe_substitute(a)) + z.writestr(i.replace("__implname__", a["implname"]), Template(uni(open(i, "r").read())).safe_substitute(a)) for i in a["extras"].split(","): z.writestr(i.strip().replace("../", "").replace("__implname__", a["implname"]), \ @@ -30,8 +37,8 @@ def dist(fn, a): z.writestr("pythonpath/lightproof_opts_%s.py"%a["implname"], "") if len(sys.argv) == 1: - print """Synopsis: python make.py config_file -eg. python make.py src/en/en.cfg""" + print ("""Synopsis: python make.py config_file +eg. python make.py src/en/en.cfg""") sys.exit(0) fArgs = cp.SafeConfigParser() @@ -40,6 +47,6 @@ for i in sys.argv[1:]: fArgs.read(i) dist(i[:-4], fArgs._sections['args']) except: - print traceback.format_exc() - print "missing config file or options: ", i + print (traceback.format_exc()) + print ("missing config file or options: " + str(i)) sys.exit(0) diff --git a/pythonpath/lightproof___implname__.py b/pythonpath/lightproof___implname__.py index c1fe0ce..a0699be 100644 --- a/pythonpath/lightproof___implname__.py +++ b/pythonpath/lightproof___implname__.py @@ -1,3 +1,4 @@ # -*- encoding: UTF-8 -*- +from __future__ import unicode_literals dic = ${data} diff --git a/pythonpath/lightproof_compile___implname__.py b/pythonpath/lightproof_compile___implname__.py index 3e9e598..c3d1e53 100644 --- a/pythonpath/lightproof_compile___implname__.py +++ b/pythonpath/lightproof_compile___implname__.py @@ -1,5 +1,5 @@ +from __future__ import unicode_literals import sys, re, traceback -from string import split repl = {} tests = [] @@ -105,9 +105,9 @@ def mysplit(s, line, oldline, debug): # modes if mode == "[Word]" or mode == "[word]": if s1[0] == '^': - s1 = ur"((?<=[!?.] )|^)" + s1[1:] + ur"(?![-\w\u2013\u00AD])" + s1 = r"((?<=[!?.] )|^)" + s1[1:] + r"(?![-\w\u2013\u00AD])" else: - s1 = ur"(? {a}{_}{vow}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an -a{_}{vow}{etc} <- ({vow} <> {vow}.upper()) and not ({vow} in aA or +a{_}{vow}{etc} <- ({vow} != {vow}.upper()) and not ({vow} in aA or {vow}.lower() in aA) and spell({vow}) -> an{_}{vow}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an a{_}{con}{etc} <- {con} in aAN or {con}.lower() in aAN -> an{_}{con}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an -{a}n{_}{con}{etc} <- ({con} <> {con}.upper()) and not ({con} in aA or +{a}n{_}{con}{etc} <- ({con} != {con}.upper()) and not ({con} in aA or {con}.lower() in aAN) and not {con} in aB and spell({con}) -> {a}{_}{con}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an # rules for sentences beginning with "A" -^A{_}{vow}{etc} <- ({vow} <> {vow}.upper()) and not ({vow} in aA or +^A{_}{vow}{etc} <- ({vow} != {vow}.upper()) and not ({vow} in aA or {vow}.lower() in aA) and spell({vow}) -> An{_}{vow}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an ^A{_}{con}{etc} <- {con} in aAN or {con}.lower() in aAN -> An{_}{con}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an @@ -379,5 +379,5 @@ def measurement(mnum, min, mout, mstr, decimal, remove): m = calc("CONVERT_ADD", (float(eval(mnum.replace(remove, "").replace(decimal, ".").replace(u"−", "-"))), min, mout)) a = list(set([str(calc("ROUND", (m, 0)))[:-2], str(calc("ROUND", (m, 1))), str(calc("ROUND", (m, 2))), str(m)])) # remove duplicated rounded items a.sort(lambda x, y: len(x) - len(y)) # sort by string length - return join(a, mstr + "\n").replace(".", decimal).replace("-", u"−") + mstr + return (mstr + "\n").join(a).replace(".", decimal).replace("-", u"−") + mstr diff --git a/src/hu_HU/ChangeLog b/src/hu_HU/ChangeLog index a93dab9..e469b0f 100644 --- a/src/hu_HU/ChangeLog +++ b/src/hu_HU/ChangeLog @@ -1,3 +1,6 @@ +2012-12-04 László Németh : +- Python 3.3 támogatás + 2012-08-23 László Németh : - „a 1,5” („a másfél”) nem névelőhasználati hiba. Pénzes Dávid hívta fel a figyelmet a problémára. diff --git a/src/hu_HU/hu_HU.cfg b/src/hu_HU/hu_HU.cfg index b64ed39..f73efa9 100644 --- a/src/hu_HU/hu_HU.cfg +++ b/src/hu_HU/hu_HU.cfg @@ -3,7 +3,7 @@ lang = hu_HU locales = hu_HU name = Lightproof grammar checker (magyar) version = 1.4.4 -author = László Németh +author = Laszlo Nemeth provider = FSF.hu implname = lightproof_hu link = http://www.fsf.hu diff --git a/src/hu_HU/hu_HU.dat b/src/hu_HU/hu_HU.dat index b0d3a46..ae623ca 100644 --- a/src/hu_HU/hu_HU.dat +++ b/src/hu_HU/hu_HU.dat @@ -30,7 +30,7 @@ hogy-hogy -> hogyhogy # Egybeírás. ###################### nagybetűsítés ################# [code] -abbrev=re.compile(ur"(?i)\b([a-zöüóőúéáűíÖÜÓŐÚÉÁŰÍ]|Áe|Áht|AkH|al|ált|ápr|aug|Avtv|bek|Bp|br|bt|Btk|cca|ci(i|ii|v|x)?|cl(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii|xxx|xxxi|xxxii|xxxiii|xxxiv|xxxix|xxxv|xxxvi|xxxvii|xxxviii)?|Co|cv(i|ii|iii)?|cx(c|ci|cii|ciii|civ|cix|cv|cvi|cvii|cviii|i|ii|iii|iv|ix|l|li|lii|liii|liv|lix|lv|lvi|lvii|lviii|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii)?|cs|Csjt|Cstv|csüt|dec|dk|dny|dr|du|dz(s)?|egy|ék|ÉKsz|em|ény|Épt|érk|etc|Etv|eü|ev|évf|febr|felv|Flt|ford|főisk|fsz(la|t)?|Ftv|gimn|gör|gr|Gt|gy|Gyvt|habil|hg|hiv|Hjt|honv|Hpt|hrsz|hsz|Hszt|htb|id|ifj|ig(h)?|ii(i)?|ill|Inc|ind|isk|iv|ix|izr|jan|jegyz|júl|jún|kat|kb|Kbt|ker|kft|kgy|kht|kir|kiv|Kjt|kk(t)?|koll|korm|köv|kp|Kr|krt|Kt(v)?|ld|li(i|ii|v|x)?|Ltd|ltp|Ltv|luth|lv(i|ii|iii)?|lx(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii)?|ly|máj|márc|mat|max|mb|megh|megj|MHSz|min|mk|Mo|Mt|NB|nov|ny(á)?|Nyilv|nyrt|okl|okt|olv|op|orsz|ort|ov(h)?|össz|Ötv|özv|Pf|pl(d)?|prof|prot|Ptk|pu|ref|rk(p)?|róm|röv|rt|sgt|spec|stb|sz(ept|erk)?|Szjt|szoc|Szt(v)?|szül|Tbj|tc|tel|tkp|tszf|tvr|ty|ua|ui|úm|ún|uo|Ve|Vhr|vi(i|ii)?|vö|vsz|Vt(v)?|xc(i|ii|iii|iv|ix|v|vi|vii|viii)?|xi(i|ii|v|x)?|xl(i|ii|iii|iv|ix|v|vi|vii|viii)?|xv(i|ii|iii)?|xx(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii)?|zrt)\.") +abbrev=re.compile(r"(?i)\b([a-zöüóőúéáűíÖÜÓŐÚÉÁŰÍ]|Áe|Áht|AkH|al|ált|ápr|aug|Avtv|bek|Bp|br|bt|Btk|cca|ci(i|ii|v|x)?|cl(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii|xxx|xxxi|xxxii|xxxiii|xxxiv|xxxix|xxxv|xxxvi|xxxvii|xxxviii)?|Co|cv(i|ii|iii)?|cx(c|ci|cii|ciii|civ|cix|cv|cvi|cvii|cviii|i|ii|iii|iv|ix|l|li|lii|liii|liv|lix|lv|lvi|lvii|lviii|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii)?|cs|Csjt|Cstv|csüt|dec|dk|dny|dr|du|dz(s)?|egy|ék|ÉKsz|em|ény|Épt|érk|etc|Etv|eü|ev|évf|febr|felv|Flt|ford|főisk|fsz(la|t)?|Ftv|gimn|gör|gr|Gt|gy|Gyvt|habil|hg|hiv|Hjt|honv|Hpt|hrsz|hsz|Hszt|htb|id|ifj|ig(h)?|ii(i)?|ill|Inc|ind|isk|iv|ix|izr|jan|jegyz|júl|jún|kat|kb|Kbt|ker|kft|kgy|kht|kir|kiv|Kjt|kk(t)?|koll|korm|köv|kp|Kr|krt|Kt(v)?|ld|li(i|ii|v|x)?|Ltd|ltp|Ltv|luth|lv(i|ii|iii)?|lx(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii|xx|xxi|xxii|xxiii|xxiv|xxix|xxv|xxvi|xxvii|xxviii)?|ly|máj|márc|mat|max|mb|megh|megj|MHSz|min|mk|Mo|Mt|NB|nov|ny(á)?|Nyilv|nyrt|okl|okt|olv|op|orsz|ort|ov(h)?|össz|Ötv|özv|Pf|pl(d)?|prof|prot|Ptk|pu|ref|rk(p)?|róm|röv|rt|sgt|spec|stb|sz(ept|erk)?|Szjt|szoc|Szt(v)?|szül|Tbj|tc|tel|tkp|tszf|tvr|ty|ua|ui|úm|ún|uo|Ve|Vhr|vi(i|ii)?|vö|vsz|Vt(v)?|xc(i|ii|iii|iv|ix|v|vi|vii|viii)?|xi(i|ii|v|x)?|xl(i|ii|iii|iv|ix|v|vi|vii|viii)?|xv(i|ii|iii)?|xx(i|ii|iii|iv|ix|v|vi|vii|viii|x|xi|xii|xiii|xiv|xix|xv|xvi|xvii|xviii)?|zrt)\.") # pattern for paragraph checking paralcap = re.compile(u"(?u)^[a-zöüóőúéáűí].*[.?!] [A-ZÖÜÓŐÚÉÁŰÍ].*[.?!][)”]?$") @@ -139,7 +139,7 @@ b {abc}* calc("NUMBERTEXT", ("1", "hu")) and calc("NUMBERTEXT", (re.sub(u"[   .]", "", \1), "hu")).replace(u"kettő", u"két").replace(u"ezeregyszáz", u"ezerszáz") != # változatok: száz vagy egyszáz, ezer vagy egyezer, kettő vagy két - re.sub(ur"\begy(száz|ezer)", r"\g<1>", \3).replace(u"ezeregyszáz", u"ezerszáz").replace(u"kettő", u"két") + re.sub(r"\begy(száz|ezer)", r"\g<1>", \3).replace(u"ezeregyszáz", u"ezerszáz").replace(u"kettő", u"két") -> = \1 + \2 + calc("NUMBERTEXT", (re.sub(u"[   .]", "", \1), "hu")) + \4 # A két összeg nem egyezik. @@ -379,7 +379,7 @@ fő(irány\w*|közlekedés\w*|szabály\w*|szervező\w*) -> fő \1 # A „fő mű hátba (támadás\w*) -> hátba\1 # Egybeírás. időről-időre -> időről időre # Különírás. jing és jang -> jin és jang # Helyesen jin és jang. -kőr((öz|út|ut)\w*) <- morph(\0, ur"st:kőr\b") -> kör\1 # Rövid ö-vel a kör összetételeiben. +kőr((öz|út|ut)\w*) <- morph(\0, r"st:kőr\b") -> kör\1 # Rövid ö-vel a kör összetételeiben. légyszíves -> légy szíves|legyél szíves # Legyél szíves értelemben különírjuk. legalább is -> legalábbis # Egybeírás. Lichten(stein\w*) -> Liechten\1 # Helyesen Liechtenstein. @@ -414,7 +414,7 @@ aword [aáeéiíoóöőuúüűAÁEÉIÍOÓÖŐUÚÜŰ]\w* a(?! 1,5\b) <- word(1) and re.match(r"(1|5\d*|[15]\d\d\d)[.]?$", word(1)) -> az # Hibás névelő. az <- not option("grammar") and word(2) and - re.match(ur"(alfejezet|alszakasz|ábr|bekezdés|diagram|fejezet|kép|lap|oldal|paragrafus|szakasz|táblázat)\w*", word(2)) and + re.match(r"(alfejezet|alszakasz|ábr|bekezdés|diagram|fejezet|kép|lap|oldal|paragrafus|szakasz|táblázat)\w*", word(2)) and re.match(r"([02-46-9]|[1-46-9]\d|[1-46-9]\d\d|[2346-9]\d\d\d)[.]", word(1)) -> a # Hibás névelő? az <- option("grammar") and word(1) and @@ -758,7 +758,7 @@ W \w{4,5} # rövid (kétbetűs) tagot tartalmazó összetett szó W \w{4,} -{W} <- option("compound") and morph({W}, ur"(?u)pa:\w\w\b") -> =suggest({W}) # Biztos, hogy helyes összetett szó? +{W} <- option("compound") and morph({W}, r"(?u)pa:\w\w\b") -> =suggest({W}) # Biztos, hogy helyes összetett szó? # minden képzett összetett szó @@ -912,4 +912,4 @@ def measurement(mnum, min, mout, mstr): m = calc("CONVERT_ADD", (float(mnum.replace(",", ".").replace(u"−", "-")), min, mout)) a = list(set([str(calc("ROUND", (m, 0)))[:-2], str(calc("ROUND", (m, 1))), str(calc("ROUND", (m, 2))), str(m)])) # remove duplicated rounded items a.sort(lambda x, y: len(x) - len(y)) # sort by string length - return join(a, mstr + "|").replace(".", ",").replace("-", u"−") + mstr + return (mstr + "|").join(a).replace(".", ",").replace("-", u"−") + mstr -- cgit v1.2.3