From a6d372d52469304860902a3eba1bafa412d420f0 Mon Sep 17 00:00:00 2001 From: Tao Wang Date: Wed, 11 Jan 2017 11:44:40 +1100 Subject: Fix #315 support utf-8 by default Signed-off-by: Tao Wang --- sqlparse/lexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 914b520..82d4380 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -44,7 +44,7 @@ class Lexer(object): pass elif isinstance(text, bytes_type): try: - text = text.decode() + text = text.decode('utf-8') except UnicodeDecodeError: if not encoding: encoding = 'unicode-escape' -- cgit v1.2.1 From 66b36af84fbe6d546b73a207e687234f28bb00a0 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Tue, 10 Jan 2017 18:52:12 -0700 Subject: Fix encoding logic/order - If user provides an encoding value, use it instead of trying to _guess_ first. - If no value is provided, then decode with default of utf-8, otherwise try with unicode-escape --- sqlparse/lexer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 82d4380..60e43da 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -43,12 +43,13 @@ class Lexer(object): if isinstance(text, text_type): pass elif isinstance(text, bytes_type): - try: - text = text.decode('utf-8') - except UnicodeDecodeError: - if not encoding: - encoding = 'unicode-escape' + if encoding: text = text.decode(encoding) + else: + try: + text = text.decode('utf-8') + except UnicodeDecodeError: + text = text.decode('unicode-escape') else: raise TypeError(u"Expected text or file-like object, got {!r}". format(type(text))) -- cgit v1.2.1