X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Fopstring.py;h=cb83a8a92ee9d8222d8dede58e2f45847e9a6398;hb=ee5ae8bff7bd4b242788e3ba7807a49a59f79ebb;hp=e01a043786186c3b0ea9c9fcf033871be5b6a679;hpb=8d79317cdc8220ff3c2192e68fc1dfc749c3ea1c;p=m_lib.git diff --git a/m_lib/opstring.py b/m_lib/opstring.py index e01a043..cb83a8a 100755 --- a/m_lib/opstring.py +++ b/m_lib/opstring.py @@ -7,6 +7,7 @@ # +from __future__ import print_function from string import * @@ -65,7 +66,7 @@ def CenterCh(S, Ch, Width): if len(S) >= Width: return S else: - l = (Width - len(S)) / 2 + l = (Width - len(S)) // 2 r = Width - len(S) - l return Ch*l + S + Ch*r @@ -125,10 +126,10 @@ def translate_a(val, id): return transl_adict[id][val] -# Encodings, especially cyrillic. Requires Unicode, hence Python 2.0+ - def recode(s, from_encoding, to_encoding, errors = "strict"): - return unicode(s, from_encoding, errors).encode(to_encoding, errors) + if isinstance(s, bytes): + s = s.decode(from_encoding, errors) + return s.encode(to_encoding, errors) def win2koi(s, errors = "strict"): @@ -143,14 +144,14 @@ def koi2win(s, errors = "strict"): # def test(): - print "bin(0x6) =", bin(0x6) - print "bin(0xC) =", bin(0xC) + print("bin(0x6) =", bin(0x6)) + print("bin(0xC) =", bin(0xC)) - print "'Test' left-padded :", LeftPad("Test", 20) - print "'Test' right-padded:", PadCh("Test", '*', 20) - print "'Test' centered :", CenterCh("Test", '=', 20) + print("'Test' left-padded :", LeftPad("Test", 20)) + print("'Test' right-padded:", PadCh("Test", '*', 20)) + print("'Test' centered :", CenterCh("Test", '=', 20)) - print "'ïÌÅÇ':", koi2win(win2koi("ïÌÅÇ")) + print("'ïÌÅÇ':", koi2win(win2koi("ïÌÅÇ"))) if __name__ == "__main__": test()