"ы": "y",
"э": "e",
"ю": "yu",
- "я": "ya"
+ "я": "ya",
}
def make_xxx2lat(encoding="cp1251"):
d = {}
for k, v in koi2lat_d.items():
- k = unicode(k, "koi8-r").encode(encoding)
+ if isinstance(k, bytes):
+ k = k.decode("koi8-r")
+ k = k.encode(encoding)
d[k] = v
return d
-from m_lib.lazy.dict import LazyDictInitFunc
+from ..lazy.dict import LazyDictInitFunc
win2lat_d = LazyDictInitFunc(make_xxx2lat, encoding="cp1251")
def rus2lat(instr, rus2lat_d = koi2lat_d):
out = []
for c in instr:
- out.append(rus2lat_d.get(c, c))
- return ''.join(out)
+ c = rus2lat_d.get(c, c)
+ if isinstance(c, bytes):
+ c = c.decode('ascii')
+ elif isinstance(c, int):
+ c = chr(c)
+ out.append(c.encode('ascii'))
+ return b''.join(out)
koi2lat = rus2lat
Test = "Щербаков Игорь Григорьевич. АБВ xyz абв ЬЬЭЮЯ ъьэюя"
print("Test:", Test)
print("Тест:", koi2lat(Test))
- print("Тест:", win2lat(unicode(Test, "koi8-r").encode("cp1251")))
+ if isinstance(Test, bytes):
+ Test = Test.decode("cp1251")
+ print("Тест:", win2lat(Test.encode("cp1251")))