diff options
author | Andreas Albrecht <a.albrecht@Mac-PU08.prounix.local> | 2019-10-20 17:51:02 +0200 |
---|---|---|
committer | Andreas Albrecht <a.albrecht@Mac-PU08.prounix.local> | 2019-10-20 17:51:02 +0200 |
commit | b8b65c52db6e4ffda18dbce3d4752696b99149a0 (patch) | |
tree | 0f6de4b2e1f5e9a2885161034be9bbb753d3482a /sqlparse | |
parent | 9433666c8c3df8b23f17d7b46d91fd1b9d922b77 (diff) | |
download | sqlparse-b8b65c52db6e4ffda18dbce3d4752696b99149a0.tar.gz |
Code cleanup.
Diffstat (limited to 'sqlparse')
-rw-r--r-- | sqlparse/engine/grouping.py | 10 | ||||
-rw-r--r-- | sqlparse/engine/statement_splitter.py | 2 | ||||
-rw-r--r-- | sqlparse/filters/aligned_indent.py | 4 | ||||
-rw-r--r-- | sqlparse/keywords.py | 7 | ||||
-rw-r--r-- | sqlparse/sql.py | 22 |
5 files changed, 26 insertions, 19 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 3ae568d..4f07bc5 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -125,8 +125,10 @@ def group_typed_literal(tlist): def post(tlist, pidx, tidx, nidx): return tidx, nidx - _group(tlist, sql.TypedLiteral, match, valid_prev, valid_next, post, extend=False) - _group(tlist, sql.TypedLiteral, match_to_extend, valid_prev, valid_final, post, extend=True) + _group(tlist, sql.TypedLiteral, match, valid_prev, valid_next, + post, extend=False) + _group(tlist, sql.TypedLiteral, match_to_extend, valid_prev, valid_final, + post, extend=True) def group_period(tlist): @@ -252,7 +254,9 @@ def group_operator(tlist): def valid(token): return imt(token, i=sqlcls, t=ttypes) \ - or token.match(T.Keyword, ("CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP")) + or token.match( + T.Keyword, + ('CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP')) def post(tlist, pidx, tidx, nidx): tlist[tidx].ttype = T.Operator diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index 6c4be8e..1e9af3c 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -33,7 +33,7 @@ class StatementSplitter(object): return 1 elif ttype is T.Punctuation and value == ')': return -1 - elif ttype not in T.Keyword: # if normal token return + elif ttype not in T.Keyword: # if normal token return return 0 # Everything after here is ttype = T.Keyword diff --git a/sqlparse/filters/aligned_indent.py b/sqlparse/filters/aligned_indent.py index d3433c9..85b11e5 100644 --- a/sqlparse/filters/aligned_indent.py +++ b/sqlparse/filters/aligned_indent.py @@ -105,8 +105,8 @@ class AlignedIndentFilter(object): # joins, group/order by are special case. only consider the first # word as aligner if ( - token.match(T.Keyword, self.join_words, regex=True) or - token.match(T.Keyword, self.by_words, regex=True) + token.match(T.Keyword, self.join_words, regex=True) + or token.match(T.Keyword, self.by_words, regex=True) ): token_indent = token.value.split()[0] else: diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 3b57824..697024f 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -64,7 +64,8 @@ SQL_REGEX = { (r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name), # side effect: change kw to func (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal), (r'-?\d*(\.\d+)?E-?\d+', tokens.Number.Float), - (r'(?![_A-ZÀ-Ü])-?(\d+(\.\d*)|\.\d+)(?![_A-ZÀ-Ü])', tokens.Number.Float), + (r'(?![_A-ZÀ-Ü])-?(\d+(\.\d*)|\.\d+)(?![_A-ZÀ-Ü])', + tokens.Number.Float), (r'(?![_A-ZÀ-Ü])-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer), (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single), # not a real string literal in ANSI SQL: @@ -84,7 +85,9 @@ SQL_REGEX = { (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), (r'GROUP\s+BY\b', tokens.Keyword), (r'ORDER\s+BY\b', tokens.Keyword), - (r'(LATERAL\s+VIEW\s+)(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b', tokens.Keyword), + (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), (r'[0-9_A-ZÀ-Ü][_$#\w]*', is_keyword), diff --git a/sqlparse/sql.py b/sqlparse/sql.py index fbe1c18..15f905e 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -262,15 +262,14 @@ class TokenList(Token): ignored too. """ # this on is inconsistent, using Comment instead of T.Comment... - funcs = lambda tk: not ((skip_ws and tk.is_whitespace) - or (skip_cm and imt(tk, - t=T.Comment, i=Comment))) - return self._token_matching(funcs)[1] + def matcher(tk): + return not ((skip_ws and tk.is_whitespace) + or (skip_cm and imt(tk, t=T.Comment, i=Comment))) + return self._token_matching(matcher)[1] def token_next_by(self, i=None, m=None, t=None, idx=-1, end=None): - funcs = lambda tk: imt(tk, i, m, t) idx += 1 - return self._token_matching(funcs, idx, end) + return self._token_matching(lambda tk: imt(tk, i, m, t), idx, end) def token_not_matching(self, funcs, idx): funcs = (funcs,) if not isinstance(funcs, (list, tuple)) else funcs @@ -300,10 +299,11 @@ class TokenList(Token): if idx is None: return None, None idx += 1 # alot of code usage current pre-compensates for this - funcs = lambda tk: not ((skip_ws and tk.is_whitespace) - or (skip_cm and imt(tk, - t=T.Comment, i=Comment))) - return self._token_matching(funcs, idx, reverse=_reverse) + + def matcher(tk): + return not ((skip_ws and tk.is_whitespace) + or (skip_cm and imt(tk, t=T.Comment, i=Comment))) + return self._token_matching(matcher, idx, reverse=_reverse) def token_index(self, token, start=0): """Return list index of token.""" @@ -490,7 +490,7 @@ class IdentifierList(TokenList): class TypedLiteral(TokenList): - """A typed literal (?), such as "date '2001-09-28'" or "interval '2 hours'".""" + """A typed literal, such as "date '2001-09-28'" or "interval '2 hours'".""" M_OPEN = T.Name.Builtin, None M_CLOSE = T.String.Single, None M_EXTEND = T.Keyword, ("DAY", "MONTH", "YEAR", "HOUR", "MINUTE", "SECOND") |