Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sqlparse/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
(r"HANDLER\s+FOR\b", tokens.Keyword),
(r"GO(\s\d+)\b", tokens.Keyword),
(
r"(LATERAL\s+VIEW\s+)" r"(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b",
r"(LATERAL\s+VIEW\s+)"
r"(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b",
tokens.Keyword,
),
(r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
Expand Down
7 changes: 5 additions & 2 deletions sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def clear(self):
def set_SQL_REGEX(self, SQL_REGEX):
"""Set the list of regex that will parse the SQL."""
FLAGS = re.IGNORECASE | re.UNICODE
self._SQL_REGEX = [(re.compile(rx, FLAGS).match, tt) for rx, tt in SQL_REGEX]
self._SQL_REGEX = [
(re.compile(rx, FLAGS).match, tt) for rx, tt in SQL_REGEX
]

def add_keywords(self, keywords):
"""Add keyword dictionaries. Keywords are looked up in the same order
Expand Down Expand Up @@ -129,7 +131,8 @@ def get_tokens(self, text, encoding=None):
text = text.decode("unicode-escape")
else:
raise TypeError(
"Expected text or file-like object, got {!r}".format(type(text))
"Expected text or file-like object, got {!r}".format(
type(text))
)

iterable = enumerate(text)
Expand Down
16 changes: 10 additions & 6 deletions sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def __repr__(self):
value = self._get_repr_value()

q = '"' if value.startswith("'") and value.endswith("'") else "'"
return "<{cls} {q}{value}{q} at 0x{id:2X}>".format(id=id(self), **locals())
return "<{cls} {q}{value}{q} at 0x{id:2X}>".format(
id=id(self), **locals())

def _get_repr_name(self):
return str(self.ttype).split(".")[-1]
Expand Down Expand Up @@ -331,7 +332,8 @@ def token_index(self, token, start=0):
start = start if isinstance(start, int) else self.token_index(start)
return start + self.tokens[start:].index(token)

def group_tokens(self, grp_cls, start, end, include_end=True, extend=False):
def group_tokens(self, grp_cls, start, end,
include_end=True, extend=False):
"""Replace tokens by an instance of *grp_cls*."""
start_idx = start
start = self.tokens[start_idx]
Expand All @@ -343,11 +345,11 @@ def group_tokens(self, grp_cls, start, end, include_end=True, extend=False):
# tokens = tokens[:-1]

if extend and isinstance(start, grp_cls):
subtokens = self.tokens[start_idx + 1 : end_idx]
subtokens = self.tokens[start_idx + 1:end_idx]

grp = start
grp.tokens.extend(subtokens)
del self.tokens[start_idx + 1 : end_idx]
del self.tokens[start_idx + 1:end_idx]
grp.value = str(start)
else:
subtokens = self.tokens[start_idx:end_idx]
Expand Down Expand Up @@ -408,7 +410,8 @@ def get_parent_name(self):
_, prev_ = self.token_prev(dot_idx)
return remove_quotes(prev_.value) if prev_ is not None else None

def _get_first_name(self, idx=None, reverse=False, keywords=False, real_name=False):
def _get_first_name(self, idx=None, reverse=False,
keywords=False, real_name=False):
"""Returns the name of the first token with a name"""

tokens = self.tokens[idx:] if idx else self.tokens
Expand Down Expand Up @@ -682,7 +685,8 @@ def get_parameters(self):
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier, TypedLiteral), t=T.Literal):
elif imt(token, i=(Function, Identifier, TypedLiteral),
t=T.Literal):
result.append(token)
return result

Expand Down
Loading