Skip to content

Commit b04b5d3

Browse files
committed
Refactor raw conversion on split_unquoted_newlines
1 parent c4954af commit b04b5d3

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

sqlparse/filters/others.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77

88
from sqlparse import sql, tokens as T
9-
from sqlparse.compat import text_type
109
from sqlparse.utils import split_unquoted_newlines
1110

1211

@@ -114,6 +113,5 @@ def process(self, stmt):
114113
class SerializerUnicode(object):
115114
@staticmethod
116115
def process(stmt):
117-
raw = text_type(stmt)
118-
lines = split_unquoted_newlines(raw)
116+
lines = split_unquoted_newlines(stmt)
119117
return '\n'.join(line.rstrip() for line in lines)

sqlparse/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
from collections import deque
1111
from contextlib import contextmanager
12+
from sqlparse.compat import text_type
1213

1314
# This regular expression replaces the home-cooked parser that was here before.
1415
# It is much faster, but requires an extra post-processing step to get the
@@ -33,11 +34,12 @@
3334
LINE_MATCH = re.compile(r'(\r\n|\r|\n)')
3435

3536

36-
def split_unquoted_newlines(text):
37+
def split_unquoted_newlines(stmt):
3738
"""Split a string on all unquoted newlines.
3839
3940
Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
4041
character is inside of a string."""
42+
text = text_type(stmt)
4143
lines = SPLIT_REGEX.split(text)
4244
outputlines = ['']
4345
for line in lines:

tests/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import unittest
99

1010
from sqlparse.utils import split_unquoted_newlines
11-
from sqlparse.compat import u, StringIO
11+
from sqlparse.compat import StringIO
1212

1313
DIR_PATH = os.path.dirname(__file__)
1414
FILES_DIR = os.path.join(DIR_PATH, 'files')
@@ -30,8 +30,8 @@ def ndiffAssertEqual(self, first, second):
3030
# Using the built-in .splitlines() method here will cause incorrect
3131
# results when splitting statements that have quoted CR/CR+LF
3232
# characters.
33-
sfirst = split_unquoted_newlines(u(first))
34-
ssecond = split_unquoted_newlines(u(second))
33+
sfirst = split_unquoted_newlines(first)
34+
ssecond = split_unquoted_newlines(second)
3535
diff = difflib.ndiff(sfirst, ssecond)
3636

3737
fp = StringIO()

0 commit comments

Comments
 (0)