From b05bc5ab586cb06d89c38e2eee7f77e1d3fc03c5 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 29 Aug 2016 21:36:15 +0300 Subject: Convert string literals to unicode for Py27 Working with non-ascii in Python require all-unicode approach, but str literals in Python 2.7 are bytes. The patch makes them unicode. Syntax u'' is supported in Python 2.7 and 3.3+. --- sqlparse/cli.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) mode change 100644 => 100755 sqlparse/cli.py (limited to 'sqlparse/cli.py') diff --git a/sqlparse/cli.py b/sqlparse/cli.py old mode 100644 new mode 100755 index 80d547d..c329fdb --- a/sqlparse/cli.py +++ b/sqlparse/cli.py @@ -123,7 +123,7 @@ def create_parser(): def _error(msg): """Print msg and optionally exit with return code exit_.""" - sys.stderr.write('[ERROR] {0}\n'.format(msg)) + sys.stderr.write(u'[ERROR] {0}\n'.format(msg)) return 1 @@ -138,13 +138,14 @@ def main(args=None): # TODO: Needs to deal with encoding data = ''.join(open(args.filename).readlines()) except IOError as e: - return _error('Failed to read {0}: {1}'.format(args.filename, e)) + return _error( + u'Failed to read {0}: {1}'.format(args.filename, e)) if args.outfile: try: stream = open(args.outfile, 'w') except IOError as e: - return _error('Failed to open {0}: {1}'.format(args.outfile, e)) + return _error(u'Failed to open {0}: {1}'.format(args.outfile, e)) else: stream = sys.stdout @@ -152,7 +153,7 @@ def main(args=None): try: formatter_opts = sqlparse.formatter.validate_options(formatter_opts) except SQLParseError as e: - return _error('Invalid options: {0}'.format(e)) + return _error(u'Invalid options: {0}'.format(e)) s = sqlparse.format(data, **formatter_opts) if PY2: -- cgit v1.2.1