(self, text: str | None)
| 405 | return self.raw_content |
| 406 | |
| 407 | def set_text(self, text: str | None) -> None: |
| 408 | if text is None: |
| 409 | self.content = None |
| 410 | return |
| 411 | enc = infer_content_encoding(self.headers.get("content-type", "")) |
| 412 | |
| 413 | try: |
| 414 | self.content = cast(bytes, encoding.encode(text, enc)) |
| 415 | except ValueError: |
| 416 | # Fall back to UTF-8 and update the content-type header. |
| 417 | ct = parse_content_type(self.headers.get("content-type", "")) or ( |
| 418 | "text", |
| 419 | "plain", |
| 420 | {}, |
| 421 | ) |
| 422 | ct[2]["charset"] = "utf-8" |
| 423 | self.headers["content-type"] = assemble_content_type(*ct) |
| 424 | enc = "utf8" |
| 425 | self.content = text.encode(enc, "surrogateescape") |
| 426 | |
| 427 | def get_text(self, strict: bool = True) -> str | None: |
| 428 | """ |
no test coverage detected