diff options
author | Victor Uriarte <victor.m.uriarte@intel.com> | 2017-01-10 18:52:12 -0700 |
---|---|---|
committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2017-01-10 19:13:32 -0700 |
commit | 66b36af84fbe6d546b73a207e687234f28bb00a0 (patch) | |
tree | 595e8a0949a7b65cf041b4d72cdf4752222c4d74 /sqlparse/lexer.py | |
parent | a6d372d52469304860902a3eba1bafa412d420f0 (diff) | |
download | sqlparse-66b36af84fbe6d546b73a207e687234f28bb00a0.tar.gz |
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
Diffstat (limited to 'sqlparse/lexer.py')
-rw-r--r-- | sqlparse/lexer.py | 11 |
1 files changed, 6 insertions, 5 deletions
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))) |