Return the first non-trivial leaf token of a parsed statement. Whitespace, comments, and punctuation are skipped so that a leading open-parenthesis (e.g. ``(SELECT 1) UNION (SELECT 2)``) or a leading comment block does not mask the real leading keyword. The result is upper-case
(statement)
| 146 | |
| 147 | |
| 148 | def _first_real_keyword(statement) -> str: |
| 149 | """ |
| 150 | Return the first non-trivial leaf token of a parsed statement. |
| 151 | |
| 152 | Whitespace, comments, and punctuation are skipped so that a leading |
| 153 | open-parenthesis (e.g. ``(SELECT 1) UNION (SELECT 2)``) or a leading |
| 154 | comment block does not mask the real leading keyword. The result is |
| 155 | upper-cased; an empty string is returned for an empty statement. |
| 156 | """ |
| 157 | for tok in statement.flatten(): |
| 158 | if tok.is_whitespace: |
| 159 | continue |
| 160 | ttype = str(tok.ttype) if tok.ttype is not None else '' |
| 161 | if 'Comment' in ttype or 'Punctuation' in ttype: |
| 162 | continue |
| 163 | return (tok.normalized or '').upper() |
| 164 | return '' |
| 165 | |
| 166 | |
| 167 | def _validate_readonly_query(query: str) -> None: |
no outgoing calls
no test coverage detected