|
7 | 7 | from ..core.dedupe import Dedupe |
8 | 8 |
|
9 | 9 |
|
| 10 | +def _encode_bool_query_value(value) -> str: |
| 11 | + """Encode typed bools while preserving legacy string query values.""" |
| 12 | + if isinstance(value, bool): |
| 13 | + return "true" if value else "false" |
| 14 | + return str(value) |
| 15 | + |
| 16 | + |
10 | 17 | class Purl: |
11 | 18 | def __init__(self, api): |
12 | 19 | self.api = api |
@@ -46,6 +53,8 @@ def post( |
46 | 53 | unresolved inputs, so callers can distinguish "no data yet" from "clean". |
47 | 54 | purl_errors: when ``True`` (``→ purlErrors``), the server includes per-purl |
48 | 55 | error rows for malformed/unresolvable inputs. ``None`` omits the param. |
| 56 | + For backward compatibility, legacy string values passed to the promoted |
| 57 | + Boolean parameters are forwarded unchanged. |
49 | 58 | strict: client-side guard. When ``True``, compares the exact ``purl`` string |
50 | 59 | of each requested component against the returned ``inputPurl`` (or the |
51 | 60 | ``purl`` fallback). The API defines ``inputPurl`` as the original, |
@@ -86,13 +95,13 @@ def post( |
86 | 95 | # Promote the typed params into query args only when explicitly set, so existing |
87 | 96 | # callers keep the server's fail-open default (None => omit the param entirely). |
88 | 97 | if poll is not None: |
89 | | - query_args["poll"] = "true" if poll else "false" |
| 98 | + query_args["poll"] = _encode_bool_query_value(poll) |
90 | 99 | if timeout_sec is not None: |
91 | 100 | query_args["timeoutSec"] = str(timeout_sec) |
92 | 101 | if alerts is not None: |
93 | | - query_args["alerts"] = "true" if alerts else "false" |
| 102 | + query_args["alerts"] = _encode_bool_query_value(alerts) |
94 | 103 | if purl_errors is not None: |
95 | | - query_args["purlErrors"] = "true" if purl_errors else "false" |
| 104 | + query_args["purlErrors"] = _encode_bool_query_value(purl_errors) |
96 | 105 | if kwargs: |
97 | 106 | query_args.update(kwargs) |
98 | 107 | params = urllib.parse.urlencode(query_args) |
|
0 commit comments