X-Git-Url: https://git.phdru.name/?p=m_lib.git;a=blobdiff_plain;f=m_lib%2Fopstring.py;h=cb83a8a92ee9d8222d8dede58e2f45847e9a6398;hp=8bd864acb0f3de2c07bf5b3047854c16cfb66b8e;hb=74e8ff73da3efcb4e78358825b0d6b610197f721;hpb=fb3af94919a9ee18ba1c35f927f19837f057fa1f diff --git a/m_lib/opstring.py b/m_lib/opstring.py index 8bd864a..cb83a8a 100755 --- a/m_lib/opstring.py +++ b/m_lib/opstring.py @@ -66,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 @@ -126,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"):