MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / _first_real_keyword

Function _first_real_keyword

web/pgadmin/llm/tools/database.py:148–164  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

146
147
148def _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
167def _validate_readonly_query(query: str) -> None:

Callers 1

_validate_readonly_queryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected