]> git.phdru.name Git - m_lib.git/blobdiff - m_lib/rus/lat2rus.py
Fix encodings in m_lib/rus
[m_lib.git] / m_lib / rus / lat2rus.py
index abf8af3823708ec56a391b81488942a7dbd607e6..86d01070765f1e4f57bb90a8c71f7ca47e786e5d 100755 (executable)
@@ -1,9 +1,11 @@
 #! /usr/bin/env python
 # -*- coding: koi8-r -*-
 
+from __future__ import print_function
+from ..lazy.dict import LazyDictInitFunc
+
 #
 # Lat -> Rus translation
-# Written by Broytman. Copyright (C) 2002 PhiloSoft Design
 #
 
 lat2koi_d = {
@@ -80,26 +82,25 @@ lat2koi_d = {
    "%": ":",
    "^": ",",
    "&": ".",
-   "*": ";"
+   "*": ";",
 }
 
 
 def make_lat2xxx(encoding="cp1251"):
    d = {}
    for k, v in lat2koi_d.items():
-      v = unicode(v, "koi8-r").encode(encoding)
       d[k] = v
    return d
 
 
-from m_lib.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))
+      c = lat2rus_d.get(c, c)
+      out.append(c)
    return ''.join(out)
 
 
@@ -111,6 +112,7 @@ def lat2win(instr):
 
 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)
+   print("Тест:", test)