From 629fd8c7b016aa43719b7112b75f427f67f2123a Mon Sep 17 00:00:00 2001 From: Piet Delport Date: Fri, 22 Feb 2013 17:42:54 +0200 Subject: Limit explicit UTF-8 encoding to Python < 3. --- bin/sqlformat | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bin/sqlformat') diff --git a/bin/sqlformat b/bin/sqlformat index 6a2496a..fcee452 100755 --- a/bin/sqlformat +++ b/bin/sqlformat @@ -98,8 +98,10 @@ def main(): err = sys.exc_info()[1] # Python 2.5 compatibility _error('Invalid options: %s' % err, exit_=1) - stream.write(sqlparse.format(data, **formatter_opts).encode('utf-8', - 'replace')) + s = sqlparse.format(data, **formatter_opts) + if sys.version_info < (3,): + s = s.encode('utf-8', 'replace') + stream.write(s) stream.flush() -- cgit v1.2.1