summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVik <vmuriart@gmail.com>2016-08-05 17:28:49 -0700
committerGitHub <noreply@github.com>2016-08-05 17:28:49 -0700
commitd999cde37af2353595b6e103f04eecc65aff280a (patch)
tree811a84532a0914d28a428e5026366d5c288944b7
parentdcd7cff503fdf420455a2c1806ff31f9b40695c4 (diff)
parent44e66710fb2222b0aa60c21a834c46831166f44c (diff)
downloadsqlparse-d999cde37af2353595b6e103f04eecc65aff280a.tar.gz
Merge pull request #279 from phdru/issue-190
closes #190
-rw-r--r--.gitignore2
-rw-r--r--sqlparse/lexer.py8
-rw-r--r--tests/test_regressions.py7
3 files changed, 15 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 438de5f..a3cb24d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
# PyCharm
.idea/
-*.pyc
+*.py[co]
docs/build
dist
MANIFEST
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)
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 5d04131..b0d66e1 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -235,6 +235,13 @@ def test_null_with_as():
assert formatted == tformatted
+def test_issue190_open_file(filepath):
+ path = filepath('stream.sql')
+ stream = open(path)
+ p = sqlparse.parse(stream)[0]
+ assert p.get_type() == 'INSERT'
+
+
def test_issue193_splitting_function():
sql = """ CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20)
BEGIN