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