format an unmarshalling error.
(hstore_str: str, pos: int)
| 339 | |
| 340 | |
| 341 | def _parse_error(hstore_str: str, pos: int) -> str: |
| 342 | """format an unmarshalling error.""" |
| 343 | |
| 344 | ctx = 20 |
| 345 | hslen = len(hstore_str) |
| 346 | |
| 347 | parsed_tail = hstore_str[max(pos - ctx - 1, 0) : min(pos, hslen)] |
| 348 | residual = hstore_str[min(pos, hslen) : min(pos + ctx + 1, hslen)] |
| 349 | |
| 350 | if len(parsed_tail) > ctx: |
| 351 | parsed_tail = "[...]" + parsed_tail[1:] |
| 352 | if len(residual) > ctx: |
| 353 | residual = residual[:-1] + "[...]" |
| 354 | |
| 355 | return "After %r, could not parse residual at position %d: %r" % ( |
| 356 | parsed_tail, |
| 357 | pos, |
| 358 | residual, |
| 359 | ) |
| 360 | |
| 361 | |
| 362 | def _parse_hstore(hstore_str: str) -> _HSTORE_VAL: |
no test coverage detected