MCPcopy Create free account
hub / github.com/cdgriffith/Box / normalize

Function normalize

box/comments.py:55–70  ·  view source on GitHub ↗

Validate a comment set through the API and turn it into its stored form.

(position: Any, text: Any, document: bool = False)

Source from the content-addressed store, hash-verified

53
54
55def 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
73def public(entry: dict | None) -> dict | None:

Callers 1

set_commentFunction · 0.85

Calls 2

BoxValueErrorClass · 0.90
_text_to_linesFunction · 0.85

Tested by

no test coverage detected