From a5f2c345285fdfb708411b8cfcf220ad5a3c86ea Mon Sep 17 00:00:00 2001 From: Akshay S Dinesh Date: Sat, 23 May 2020 21:22:12 +0530 Subject: [PATCH] refactor: fix flake errors ambitiously --- Makefile | 4 ++-- libindic/payyans/__init__.py | 1 + libindic/payyans/core.py | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 3fc16ec..d55ca56 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ test: coverage run --source=libindic -m unittest discover -s libindic flake: - flake8 --max-complexity 10 --ignore F401,E402 libindic/payyans + flake8 --max-complexity 10 libindic travis: test flake - + clean: find . -iname "*.pyc" -exec rm -vf {} \; find . -iname "__pycache__" -delete diff --git a/libindic/payyans/__init__.py b/libindic/payyans/__init__.py index 5e15921..7282dc4 100755 --- a/libindic/payyans/__init__.py +++ b/libindic/payyans/__init__.py @@ -1,3 +1,4 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- +__all__ = ["Payyans", "getInstance"] from .core import Payyans, getInstance diff --git a/libindic/payyans/core.py b/libindic/payyans/core.py index 8ee7199..60642d4 100755 --- a/libindic/payyans/core.py +++ b/libindic/payyans/core.py @@ -31,8 +31,7 @@ അമേരിക്കാ-ഇറാഖ് യുദ്ധം താഴെപ്പറയും വിധമാകുന്നു. ''' -'''ആവശ്യത്തിനുള്ള കോപ്പുകള്‍ കൂട്ടുക ''' -import sys # കുന്തം +# ആവശ്യത്തിനുള്ള കോപ്പുകള്‍ കൂട്ടുക import codecs # കൊടച്ചക്രം import os # ശീലക്കുട from libindic.normalizer import Normalizer @@ -132,14 +131,18 @@ def ASCII2Unicode(self, ascii_text, font): if self.isPostbase(next_ucode_letter): postbase_letter = next_ucode_letter index = index + 1 - if ((unicode_letter.encode('utf-8') == "എ") | - (unicode_letter.encode('utf-8') == "ഒ")): - unicode_text = unicode_text + postbase_letter + \ - self.getVowelSign(prebase_letter, - unicode_letter) + if ((unicode_letter.encode('utf-8') == "എ") + | (unicode_letter.encode('utf-8') == "ഒ")): + vowel_sign = self.getVowelSign(prebase_letter, + unicode_letter) + unicode_text = (unicode_text + + postbase_letter + + vowel_sign) else: - unicode_text = unicode_text + unicode_letter + \ - postbase_letter + prebase_letter + unicode_text = (unicode_text + + unicode_letter + + postbase_letter + + prebase_letter) prebase_letter = "" postbase_letter = "" index = index + charNo @@ -175,10 +178,8 @@ def isPrebase(self, letter): എന്നു പയ്യന്റെ ഗുരു പയ്യഗുരു പയ്യെ മൊഴിഞ്ഞിട്ടുണ്ടു്. ''' unicode_letter = letter.encode('utf-8') - if ((unicode_letter == "േ") | - (unicode_letter == "ൈ") | (unicode_letter == "ൊ") | - (unicode_letter == "ോ") | (unicode_letter == "ൌ") | - (unicode_letter == "്ര") | (unicode_letter == "െ")): + prebase_letters = ["േ", "ൈ", "ൊ", "ോ", "ൌ", "്ര", "െ"] + if (unicode_letter in prebase_letters): return True # "ഇതു സത്യം... അ...സത്യം.... അസത്യം...!" else: return False @@ -251,6 +252,7 @@ def LoadRules(self): rules_dict[lhs] = rhs else: rules_dict[rhs] = lhs + rules_file.close() return rules_dict def get_module_name(self):