# -*- coding: koi8-r -*-
from __future__ import print_function
+from ..lazy.dict import LazyDictInitFunc
#
# Lat -> Rus translation
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")
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
print("Test:", Test)
print("Тест:", lat2koi(Test))
test = lat2win(Test)
- if isinstance(test, bytes):
- test = test.decode("cp1251")
- print("Тест:", test.encode("koi8-r"))
+ print("Тест:", test)
# -*- coding: koi8-r -*-
from __future__ import print_function
+from ..lazy.dict import LazyDictInitFunc
#
# Rus -> Lat transliteration (koi2lat and win2lat)
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")
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
Test = "Щербаков Игорь Григорьевич. АБВ xyz абв ЬЬЭЮЯ ъьэюя"
print("Test:", Test)
print("Тест:", koi2lat(Test))
- if isinstance(Test, bytes):
- Test = Test.decode("cp1251")
- print("Тест:", win2lat(Test.encode("cp1251")))
+ print("Тест:", win2lat(Test))