From: Mark Wooding Date: Sat, 1 Jun 2024 03:28:54 +0000 (+0100) Subject: fshash.in: Add Python 3 versions of the compatibility veneers. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/rsync-backup/commitdiff_plain/07189ffb9feb04186af3527cb0ec10e8d69606fe?ds=inline fshash.in: Add Python 3 versions of the compatibility veneers. This completes the port to Python 3. --- diff --git a/fshash.in b/fshash.in index 75d004f..f19a81e 100644 --- a/fshash.in +++ b/fshash.in @@ -41,11 +41,23 @@ VERSION = '@VERSION@' ###-------------------------------------------------------------------------- ### Utilities. -from cStringIO import StringIO; BytesIO = StringIO -def bin(x): return x -def text(x): return x -def bytechr(x): return chr(x) -def byteord(x): return ord(x) +import sys as _SYS +_PYVER = _SYS.version_info +if _PYVER >= (3,): + _FSENC = _SYS.getfilesystemencoding() + if _PYVER >= (3, 1): _FSENCERR = "surrogateescape" + else: _FSENCERR = "strict" + from io import BytesIO, StringIO + def bin(x): return x.encode(_FSENC, _FSENCERR) + def text(x): return x.decode(_FSENC, _FSENCERR) + def bytechr(x): return bytes([x]) + def byteord(x): return x +else: + from cStringIO import StringIO; BytesIO = StringIO + def bin(x): return x + def text(x): return x + def bytechr(x): return chr(x) + def byteord(x): return ord(x) def excval(): return exc_info()[1] QUIS = OS.path.basename(argv[0])