MCPcopy
hub / github.com/andialbrecht/sqlparse / match

Method match

sqlparse/sql.py:89–121  ·  view source on GitHub ↗

Checks whether the token matches the given arguments. *ttype* is a token type as defined in `sqlparse.tokens`. If it does not match, ``False`` is returned. *values* is a list of possible values for this token. For match to be considered valid, the token value needs t

(self, ttype, values, regex=False)

Source from the content-addressed store, hash-verified

87 yield self
88
89 def match(self, ttype, values, regex=False):
90 """Checks whether the token matches the given arguments.
91
92 *ttype* is a token type as defined in `sqlparse.tokens`. If it does
93 not match, ``False`` is returned.
94 *values* is a list of possible values for this token. For match to be
95 considered valid, the token value needs to be in this list. For tokens
96 of type ``Keyword`` the comparison is case-insensitive. For
97 convenience, a single value can be given passed as a string.
98 If *regex* is ``True``, the given values are treated as regular
99 expressions. Partial matches are allowed. Defaults to ``False``.
100 """
101 type_matched = self.ttype is ttype
102 if not type_matched or values is None:
103 return type_matched
104
105 if isinstance(values, str):
106 values = (values,)
107
108 if regex:
109 # TODO: Add test for regex with is_keyword = false
110 flag = re.IGNORECASE if self.is_keyword else 0
111 values = (re.compile(v, flag) for v in values)
112
113 for pattern in values:
114 if pattern.search(self.normalized):
115 return True
116 return False
117
118 if self.is_keyword:
119 values = (v.upper() for v in values)
120
121 return self.normalized in values
122
123 def within(self, group_cls):
124 """Returns ``True`` if this token is within *group_cls*.

Callers 15

validate_where_clauseFunction · 0.80
test_issue34Function · 0.80
test_issue39Function · 0.80
extract_definitionsFunction · 0.80
split_unquoted_newlinesFunction · 0.80
imtFunction · 0.80
get_identifiersMethod · 0.80
get_casesMethod · 0.80
_group_matchingFunction · 0.80
matchFunction · 0.80
valid_nextFunction · 0.80
valid_finalFunction · 0.80

Calls

no outgoing calls

Tested by 3

validate_where_clauseFunction · 0.64
test_issue34Function · 0.64
test_issue39Function · 0.64