Validate a comment set through the API and turn it into its stored form.
(position: Any, text: Any, document: bool = False)
| 53 | |
| 54 | |
| 55 | def normalize(position: Any, text: Any, document: bool = False) -> Any: |
| 56 | """Validate a comment set through the API and turn it into its stored form.""" |
| 57 | allowed = DOCUMENT_POSITIONS if document else POSITIONS |
| 58 | if position not in allowed: |
| 59 | raise BoxValueError(f"position must be one of {', '.join(repr(p) for p in allowed)}, not {position!r}") |
| 60 | if text is None or text == "": |
| 61 | return None |
| 62 | if not isinstance(text, str): |
| 63 | raise BoxValueError(f"comment must be a string, not {type(text).__name__}") |
| 64 | if _CONTROL.search(text): |
| 65 | raise BoxValueError("comments can't contain control characters") |
| 66 | if position == "eol": |
| 67 | if _LINE_BREAKS.search(text): |
| 68 | raise BoxValueError("an end of line comment must be a single line") |
| 69 | return _text_to_lines(text)[0] |
| 70 | return _text_to_lines(text) |
| 71 | |
| 72 | |
| 73 | def public(entry: dict | None) -> dict | None: |
no test coverage detected