diff options
author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-08 09:04:57 -0700 |
---|---|---|
committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-11 04:37:34 -0700 |
commit | bd48c9bf10facf2769270ad8dfc20b6786c28ab1 (patch) | |
tree | da8e47735ba7710a97886e4e5b37f3ffac288df1 /sqlparse/utils.py | |
parent | ba417700f78b94b06afd6f199ea403b74436623d (diff) | |
download | sqlparse-bd48c9bf10facf2769270ad8dfc20b6786c28ab1.tar.gz |
Updating Utilities for clarity and fix tokentype behavior
Diffstat (limited to 'sqlparse/utils.py')
-rw-r--r-- | sqlparse/utils.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/sqlparse/utils.py b/sqlparse/utils.py index 4da44c6..8253e0b 100644 --- a/sqlparse/utils.py +++ b/sqlparse/utils.py @@ -78,36 +78,36 @@ def recurse(*cls): def imt(token, i=None, m=None, t=None): - """Aid function to refactor comparisons for Instance, Match and TokenType - Aid fun + """Helper function to simplify comparisons Instance, Match and TokenType :param token: :param i: Class or Tuple/List of Classes :param m: Tuple of TokenType & Value. Can be list of Tuple for multiple :param t: TokenType or Tuple/List of TokenTypes :return: bool """ - t = (t,) if t and not isinstance(t, (list, tuple)) else t - m = (m,) if m and not isinstance(m, (list,)) else m + clss = i + types = [t, ] if t and not isinstance(t, list) else t + mpatterns = [m, ] if m and not isinstance(m, list) else m if token is None: return False - elif i is not None and isinstance(token, i): + elif clss and isinstance(token, clss): return True - elif m is not None and any((token.match(*x) for x in m)): + elif mpatterns and any((token.match(*pattern) for pattern in mpatterns)): return True - elif t is not None and token.ttype in t: + elif types and any([token.ttype in ttype for ttype in types]): return True else: return False -def find_matching(tlist, token, M1, M2): +def find_matching(tlist, token, open_pattern, close_pattern): idx = tlist.token_index(token) depth = 0 for token in tlist.tokens[idx:]: - if token.match(*M1): + if token.match(*open_pattern): depth += 1 - elif token.match(*M2): + elif token.match(*close_pattern): depth -= 1 if depth == 0: return token |