#! /usr/bin/env python
# -*- coding: koi8-r -*-
+from __future__ import print_function
+
#
# Lat -> Rus translation
#
"%": ":",
"^": ",",
"&": ".",
- "*": ";"
+ "*": ";",
}
def make_lat2xxx(encoding="cp1251"):
d = {}
for k, v in lat2koi_d.items():
- v = unicode(v, "koi8-r").encode(encoding)
+ if isinstance(v, bytes):
+ v = v.decode("koi8-r")
+ v = v.encode(encoding)
d[k] = v
return d
-from m_lib.lazy.dict import LazyDictInitFunc
+from ..lazy.dict import LazyDictInitFunc
lat2win_d = LazyDictInitFunc(make_lat2xxx, encoding="cp1251")
def lat2rus(instr, lat2rus_d = lat2koi_d):
out = []
for c in instr:
- out.append(lat2rus_d.get(c, c))
- return ''.join(out)
+ 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)
lat2koi = lat2rus
if __name__ == "__main__":
Test = "Ghbdtn nt,t^ ghtrhfcysq vbh!"
- print "Test:", Test
- print "Тест:", lat2koi(Test)
- print "Тест:", unicode(lat2win(Test), "cp1251").encode("koi8-r")
+ print("Test:", Test)
+ print("Тест:", lat2koi(Test))
+ test = lat2win(Test)
+ if isinstance(test, bytes):
+ test = test.decode("cp1251")
+ print("Тест:", test.encode("koi8-r"))