From a73caae577de282ae9e754eb6a9ba13cb8725980 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 23 Apr 2017 23:42:07 +0300 Subject: [PATCH] Fix encodings in m_lib/rus --- m_lib/rus/lat2rus.py | 15 ++++----------- m_lib/rus/rus2lat.py | 17 +++++------------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/m_lib/rus/lat2rus.py b/m_lib/rus/lat2rus.py index 16d82f1..86d0107 100755 --- a/m_lib/rus/lat2rus.py +++ b/m_lib/rus/lat2rus.py @@ -2,6 +2,7 @@ # -*- coding: koi8-r -*- from __future__ import print_function +from ..lazy.dict import LazyDictInitFunc # # Lat -> Rus translation @@ -88,14 +89,10 @@ lat2koi_d = { def make_lat2xxx(encoding="cp1251"): d = {} for k, v in lat2koi_d.items(): - if isinstance(v, bytes): - v = v.decode("koi8-r") - v = v.encode(encoding) d[k] = v return d -from ..lazy.dict import LazyDictInitFunc lat2win_d = LazyDictInitFunc(make_lat2xxx, encoding="cp1251") @@ -103,10 +100,8 @@ def lat2rus(instr, lat2rus_d = lat2koi_d): out = [] for c in instr: c = lat2rus_d.get(c, c) - if isinstance(c, bytes): - c = c.decode('koi8-r') - out.append(c.encode('koi8-r')) - return b''.join(out) + out.append(c) + return ''.join(out) lat2koi = lat2rus @@ -120,6 +115,4 @@ if __name__ == "__main__": print("Test:", Test) print("ôÅÓÔ:", lat2koi(Test)) test = lat2win(Test) - if isinstance(test, bytes): - test = test.decode("cp1251") - print("ôÅÓÔ:", test.encode("koi8-r")) + print("ôÅÓÔ:", test) diff --git a/m_lib/rus/rus2lat.py b/m_lib/rus/rus2lat.py index e7f731b..ae78616 100755 --- a/m_lib/rus/rus2lat.py +++ b/m_lib/rus/rus2lat.py @@ -2,6 +2,7 @@ # -*- coding: koi8-r -*- from __future__ import print_function +from ..lazy.dict import LazyDictInitFunc # # Rus -> Lat transliteration (koi2lat and win2lat) @@ -77,14 +78,10 @@ koi2lat_d = { def make_xxx2lat(encoding="cp1251"): d = {} for k, v in koi2lat_d.items(): - if isinstance(k, bytes): - k = k.decode("koi8-r") - k = k.encode(encoding) d[k] = v return d -from ..lazy.dict import LazyDictInitFunc win2lat_d = LazyDictInitFunc(make_xxx2lat, encoding="cp1251") @@ -92,12 +89,10 @@ def rus2lat(instr, rus2lat_d = koi2lat_d): out = [] for c in instr: c = rus2lat_d.get(c, c) - if isinstance(c, bytes): - c = c.decode('ascii') - elif isinstance(c, int): + if isinstance(c, int): c = chr(c) - out.append(c.encode('ascii')) - return b''.join(out) + out.append(c) + return ''.join(out) koi2lat = rus2lat @@ -110,6 +105,4 @@ if __name__ == "__main__": Test = "ýÅÒÂÁËÏ× éÇÏÒØ çÒÉÇÏÒØÅ×ÉÞ. áâ÷ xyz ÁÂ× øøüàñ ßØÜÀÑ" print("Test:", Test) print("ôÅÓÔ:", koi2lat(Test)) - if isinstance(Test, bytes): - Test = Test.decode("cp1251") - print("ôÅÓÔ:", win2lat(Test.encode("cp1251"))) + print("ôÅÓÔ:", win2lat(Test)) -- 2.39.5