summaryrefslogtreecommitdiff
path: root/sqlparse/lexer.py
diff options
context:
space:
mode:
authorOleg Broytman <phd@phdru.name>2016-08-05 19:58:48 +0300
committerOleg Broytman <phd@phdru.name>2016-08-06 01:30:45 +0300
commit44e66710fb2222b0aa60c21a834c46831166f44c (patch)
treef81aef8580c8b97aed80622c53d8e9293d32f7c6 /sqlparse/lexer.py
parente2eca17927462f7893dbe5eb440eefb1e7419a59 (diff)
downloadsqlparse-44e66710fb2222b0aa60c21a834c46831166f44c.tar.gz
Fix a bug: recognize file (Python 2) as a stream
Diffstat (limited to 'sqlparse/lexer.py')
-rw-r--r--sqlparse/lexer.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index 3cf2be4..06318c6 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -20,6 +20,12 @@ from sqlparse.compat import StringIO, string_types, u
from sqlparse.utils import consume
+try:
+ file_types = (file, StringIO, TextIOBase)
+except NameError: # Python 3
+ file_types = (StringIO, TextIOBase)
+
+
class Lexer(object):
"""Lexer
Empty class. Leaving for backwards-compatibility
@@ -41,7 +47,7 @@ class Lexer(object):
"""
if isinstance(text, string_types):
text = u(text, encoding)
- elif isinstance(text, (StringIO, TextIOBase)):
+ elif isinstance(text, file_types):
text = u(text.read(), encoding)
iterable = enumerate(text)