Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -102,11 +102,11 @@ for sOption, lRuleGroup in chain(_rules.lParagraphRules, _rules.lSentenceRules): if sOption != "@@@@": for aRule in lRuleGroup: try: aRule[0] = re.compile(aRule[0]) - except: + except (IndexError, re.error): echo("Bad regular expression in # " + str(aRule[2])) aRule[0] = "(?i)" def ignoreRule (sRuleId): @@ -127,11 +127,11 @@ def listRules (sFilter=None): "generator: returns typle (sOption, sLineId, sRuleId)" if sFilter: try: zFilter = re.compile(sFilter) - except: + except re.error: echo("# Error. List rules: wrong regex.") sFilter = None for sOption, lRuleGroup in chain(_getRules(True), _getRules(False)): if sOption != "@@@@": for _, _, sLineId, sRuleId, _, _ in lRuleGroup: @@ -278,10 +278,11 @@ except: raise return self.dError.values() # this is a view (iterable) def parseText (self, sText, sText0, bParagraph, nOffset, sCountry, dOptions, bShowRuleId, bDebug, bContext): + "parse the text with rules" bChange = False for sOption, lRuleGroup in _getRules(bParagraph): if sOption == "@@@@": # graph rules if not bParagraph and bChange: @@ -615,12 +616,11 @@ if bShowRuleId: sMessage += " # " + sLineId + " # " + sRuleId # if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) - else: - return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) + return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) def _createErrorFromTokens (self, sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext): # suggestions if sSugg[0:1] == "=": sSugg = globals()[sSugg[1:]](self.lToken, nTokenOffset, nLastToken) @@ -636,12 +636,11 @@ if bShowRuleId: sMessage += " " + sLineId + " # " + sRuleId # if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) - else: - return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) + return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) def _createErrorForWriter (self, nStart, nLen, sRuleId, sOption, sMessage, lSugg, sURL): xErr = SingleProofreadingError() # uno.createUnoStruct( "com.sun.star.linguistic2.SingleProofreadingError" ) xErr.nErrorStart = nStart xErr.nErrorLength = nLen @@ -752,11 +751,11 @@ "rewrite the sentence, modify tokens, purge the token list" if bDebug: echo("REWRITE") lNewToken = [] nMergeUntil = 0 - dTokenMerger = None + dTokenMerger = {} for iToken, dToken in enumerate(self.lToken): bKeepToken = True if dToken["sType"] != "INFO": if nMergeUntil and iToken <= nMergeUntil: dTokenMerger["sValue"] += " " * (dToken["nStart"] - dTokenMerger["nEnd"]) + dToken["sValue"] @@ -789,14 +788,13 @@ self.sSentence = self.sSentence[:dToken["nStart"]] + sNewRepl + self.sSentence[dToken["nEnd"]:] del dToken["sNewValue"] else: try: del self.dTokenPos[dToken["nStart"]] - except: + except KeyError: echo(self) echo(dToken) - exit() if bDebug: echo(" TEXT REWRITED: " + self.sSentence) self.lToken.clear() self.lToken = lNewToken @@ -862,11 +860,11 @@ if not m: return False try: sWord = m.group(1) nPos = m.start(1) + nOffset - except: + except IndexError: return False return morph(dTokenPos, (nPos, sWord), sPatternGroup1, sNegPatternGroup1) @@ -899,14 +897,13 @@ if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) - else: - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) @@ -918,14 +915,13 @@ # check negative condition if sNegPattern: if sNegPattern == "*": zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) - else: - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) @@ -968,14 +964,13 @@ if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) - else: - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) @@ -993,14 +988,13 @@ if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) - else: - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) @@ -1016,14 +1010,13 @@ zPattern = re.compile(sPattern) bResult = all(zPattern.search(sMorph) for sMorph in lMorph) if bResult and bSetMorph: dToken1["lMorph"] = lMorph return bResult - else: - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) bResult = any(zPattern.search(sMorph) for sMorph in lMorph) if bResult and bSetMorph: dToken1["lMorph"] = lMorph Index: gc_core/py/lang_core/gc_options.py ================================================================== --- gc_core/py/lang_core/gc_options.py +++ gc_core/py/lang_core/gc_options.py @@ -24,11 +24,11 @@ "returns dictionary of options colors" dOptColor = _dOptColor[sTheme] if sTheme in _dOptColor else _dOptColor["Default"] dColorType = _dColorType[sColorType] if sColorType in _dColorType else _dColorType["aRGB"] try: return { sOpt: dColorType[sColor] for sOpt, sColor in dOptColor.items() } - except: + except KeyError: traceback.print_exc() return {} lStructOpt = ${lStructOpt} Index: gc_lang/fr/modules/gce_analyseur.py ================================================================== --- gc_lang/fr/modules/gce_analyseur.py +++ gc_lang/fr/modules/gce_analyseur.py @@ -2,10 +2,11 @@ from . import cregex as cr def g_morphVC (dToken, sPattern, sNegPattern=""): + "lance la fonction g_morph() sur la première partie d’un verbe composé (ex: vient-il)" nEnd = dToken["sValue"].rfind("-") if "-t-" in dToken["sValue"]: nEnd = nEnd - 2 return g_morph(dToken, sPattern, sNegPattern, 0, nEnd, False) Index: gc_lang/fr/modules/gce_date_verif.py ================================================================== --- gc_lang/fr/modules/gce_date_verif.py +++ gc_lang/fr/modules/gce_date_verif.py @@ -31,11 +31,11 @@ sMonth = _dMonth.get(sMonth.lower(), "13") try: return datetime.date(int(sYear), int(sMonth), int(sDay)) except ValueError: return False - except: + except TypeError: return True def checkDay (sWeekday, sDay, sMonth, sYear): "return True if sWeekday is valid according to the given date" @@ -66,11 +66,10 @@ # 1582 if xDate.month < 12 or xDate.day <= 9: # Calendrier julien sGregorianDay = _lDay[xDate.weekday()] return _dGregorianToJulian.get(sGregorianDay, "Erreur: jour inconnu") - elif xDate.day >= 20: + if xDate.day >= 20: # Calendrier grégorien return _lDay[xDate.weekday()] - else: - # 10 - 19 décembre 1582: jours inexistants en France. - return "" + # 10 - 19 décembre 1582: jours inexistants en France. + return "" Index: gc_lang/fr/modules/gce_suggestions.py ================================================================== --- gc_lang/fr/modules/gce_suggestions.py +++ gc_lang/fr/modules/gce_suggestions.py @@ -179,11 +179,11 @@ if not lMorph: return "" sGender = cr.getGender(lMorph) if sGender == ":m": return suggMasPlur(sFlex) - elif sGender == ":f": + if sGender == ":f": return suggFemPlur(sFlex) aSugg = set() if "-" not in sFlex: if sFlex.endswith("l"): if sFlex.endswith("al") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"ux"): @@ -417,11 +417,11 @@ def suggCeOrCet (sWord): "suggest “ce” or “cet” or both according to the first letter of " if re.match("(?i)[aeéèêiouyâîï]", sWord): return "cet" - if sWord[0:1] == "h" or sWord[0:1] == "H": + if sWord[0:1] in "hH": return "ce|cet" return "ce" def suggLesLa (sWord): @@ -473,30 +473,30 @@ try: m = re.match("NF[  -]?(C|E|P|Q|S|X|Z|EN(?:[  -]ISO|))[  -]?([0-9]+(?:[/‑-][0-9]+|))", s) if not m: return "" return "NF " + m.group(1).upper().replace(" ", " ").replace("-", " ") + " " + m.group(2).replace("/", "‑").replace("-", "‑") - except: + except (re.error, IndexError): traceback.print_exc() return "# erreur #" def undoLigature (c): "typography: split ligature character in several chars" if c == "fi": return "fi" - elif c == "fl": + if c == "fl": return "fl" - elif c == "ff": + if c == "ff": return "ff" - elif c == "ffi": + if c == "ffi": return "ffi" - elif c == "ffl": + if c == "ffl": return "ffl" - elif c == "ſt": + if c == "ſt": return "ft" - elif c == "st": + if c == "st": return "st" return "_"