diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | sqlparse/lexer.py | 8 | ||||
| -rw-r--r-- | tests/test_regressions.py | 7 |
3 files changed, 15 insertions, 2 deletions
@@ -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 |
