]> git.phdru.name Git - m_lib.git/blobdiff - m_lib/rus/rus2lat.py
Build(setup.py): Fix trove classifiers
[m_lib.git] / m_lib / rus / rus2lat.py
index dda03dab0a52de89add34af7948a407a01e05ea9..fff0bfd4db2fd0eccd0f605165bb4258e059fde8 100755 (executable)
@@ -1,9 +1,11 @@
 #! /usr/bin/env python
 # -*- coding: koi8-r -*-
 
+from __future__ import print_function
+from ..lazy.dict import LazyDictInitFunc
+
 #
 # Rus -> Lat transliteration (koi2lat and win2lat)
-# Written by Broytman. Copyright (C) 1997-2002 PhiloSoft Design
 #
 
 koi2lat_d = {
@@ -13,6 +15,7 @@ koi2lat_d = {
    "Г": "G",
    "Д": "D",
    "Е": "E",
+   "Ё": "Yo",
    "Ж": "Zh",
    "З": "Z",
    "И": "I",
@@ -45,6 +48,7 @@ koi2lat_d = {
    "г": "g",
    "д": "d",
    "е": "e",
+   "ё": "yo",
    "ж": "zh",
    "з": "z",
    "и": "i",
@@ -70,25 +74,26 @@ koi2lat_d = {
    "ы": "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)
       d[k] = v
    return d
 
 
-from m_lib.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))
+      c = rus2lat_d.get(c, c)
+      if isinstance(c, int):
+         c = chr(c)
+      out.append(c)
    return ''.join(out)
 
 
@@ -100,6 +105,6 @@ def win2lat(instr):
 
 if __name__ == "__main__":
    Test = "Щербаков Игорь Григорьевич. АБВ xyz абв ЬЬЭЮЯ ъьэюя"
-   print "Test:", Test
-   print "Тест:", koi2lat(Test)
-   print "Тест:", win2lat(unicode(Test, "koi8-r").encode("cp1251"))
+   print("Test:", Test)
+   print("Тест:", koi2lat(Test))
+   print("Тест:", win2lat(Test))