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)
| 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*. |
no outgoing calls