MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / _param_first

Function _param_first

openlibrary/plugins/worksearch/code.py:141–149  ·  view source on GitHub ↗

web.input can give back either a string or list depending on the field's default. The availability params come in as scalar strings, but we defensively unwrap lists too so a future change to the input declaration doesn't silently break this comparison.

(param: dict, key: str)

Source from the content-addressed store, hash-verified

139
140
141def _param_first(param: dict, key: str) -> str:
142 """web.input can give back either a string or list depending on the field's
143 default. The availability params come in as scalar strings, but we
144 defensively unwrap lists too so a future change to the input declaration
145 doesn't silently break this comparison."""
146 val = param.get(key)
147 if isinstance(val, list):
148 return val[0] if val else ""
149 return "" if val is None else str(val)
150
151
152@public

Callers 1

matchesFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected