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

Function extract_definitions

examples/column_defs_lowlevel.py:15–39  ·  view source on GitHub ↗
(token_list)

Source from the content-addressed store, hash-verified

13
14
15def extract_definitions(token_list):
16 # assumes that token_list is a parenthesis
17 definitions = []
18 tmp = []
19 par_level = 0
20 for token in token_list.flatten():
21 if token.is_whitespace:
22 continue
23 elif token.match(sqlparse.tokens.Punctuation, '('):
24 par_level += 1
25 continue
26 if token.match(sqlparse.tokens.Punctuation, ')'):
27 if par_level == 0:
28 break
29 else:
30 par_level -= 1
31 elif token.match(sqlparse.tokens.Punctuation, ','):
32 if tmp:
33 definitions.append(tmp)
34 tmp = []
35 else:
36 tmp.append(token)
37 if tmp:
38 definitions.append(tmp)
39 return definitions
40
41
42if __name__ == '__main__':

Callers 1

Calls 2

matchMethod · 0.80
flattenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…