X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/2aa7d3a9238bfb3d117ca23191ea402c5c5d6f40..3317491a2bc28732f805c8521777aafa52038793:/pwsafe diff --git a/pwsafe b/pwsafe index e622e53..40a64ce 100644 --- a/pwsafe +++ b/pwsafe @@ -24,13 +24,13 @@ ### along with Catacomb/Python; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -###--------------------------------------------------------------------------- +###-------------------------------------------------------------------------- ### Imported modules. from __future__ import with_statement from os import environ -from sys import argv, exit, stdin, stdout, stderr +import sys as SYS; from sys import argv, exit, stdin, stdout, stderr from getopt import getopt, GetoptError from fnmatch import fnmatch import re @@ -41,8 +41,23 @@ from catacomb.pwsafe import * ###-------------------------------------------------------------------------- ### Python version portability. -def _text(bin): return bin -def _bin(text): return text +if SYS.version_info >= (3,): + import io as IO + def hack_stream(stream): + _enc = stream.encoding + _lbuf = stream.line_buffering + _nl = stream.newlines + return IO.TextIOWrapper(stream.detach(), + encoding = _enc, + line_buffering = _lbuf, + newline = _nl, + errors = "surrogateescape") + SYS.stdout = stdout = hack_stream(stdout) + def _text(bin): return bin.decode(errors = "surrogateescape") + def _bin(text): return text.encode(errors = "surrogateescape") +else: + def _text(bin): return bin + def _bin(text): return text def _excval(): return SYS.exc_info()[1]