MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / inject_param_text

Function inject_param_text

lib/sqlalchemy/util/langhelpers.py:2223–2263  ·  view source on GitHub ↗
(doctext: str, inject_params: Dict[str, str])

Source from the content-addressed store, hash-verified

2221
2222
2223def inject_param_text(doctext: str, inject_params: Dict[str, str]) -> str:
2224 doclines = collections.deque(doctext.splitlines())
2225 lines = []
2226
2227 # TODO: this is not working for params like ":param case_sensitive=True:"
2228
2229 to_inject = None
2230 while doclines:
2231 line = doclines.popleft()
2232
2233 m = _param_reg.match(line)
2234
2235 if to_inject is None:
2236 if m:
2237 param = m.group(2).lstrip("*")
2238 if param in inject_params:
2239 # default indent to that of :param: plus one
2240 indent = " " * len(m.group(1)) + " "
2241
2242 # but if the next line has text, use that line's
2243 # indentation
2244 if doclines:
2245 m2 = re.match(r"(\s+)\S", doclines[0])
2246 if m2:
2247 indent = " " * len(m2.group(1))
2248
2249 to_inject = indent + inject_params[param]
2250 elif m:
2251 lines.extend(["\n", to_inject, "\n"])
2252 to_inject = None
2253 elif not line.rstrip():
2254 lines.extend([line, to_inject, "\n"])
2255 to_inject = None
2256 elif line.endswith("::"):
2257 # TODO: this still won't cover if the code example itself has
2258 # blank lines in it, need to detect those via indentation.
2259 lines.extend([line, doclines.popleft()])
2260 continue
2261 lines.append(line)
2262
2263 return "\n".join(lines)
2264
2265
2266def repr_tuple_names(names: List[str]) -> Optional[str]:

Callers 2

decorateFunction · 0.85
decorateFunction · 0.85

Calls 7

lstripMethod · 0.80
rstripMethod · 0.80
matchMethod · 0.45
extendMethod · 0.45
endswithMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected