# opString - string/pathnames manipulation routines
# Some ideas came from Turbo Professional/Object Professional (t/o)pString.PAS
#
-# Written by Broytman, Nov 1997. Copyright (C) 1997 PhiloSoft Design
-#
+from __future__ import print_function
from string import *
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
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"):
#
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()