Similar to `Message.text`, but does not raise if `strict` is `False`. Instead, the message body is returned as surrogate-escaped UTF-8.
(self, strict: bool = True)
| 425 | self.content = text.encode(enc, "surrogateescape") |
| 426 | |
| 427 | def get_text(self, strict: bool = True) -> str | None: |
| 428 | """ |
| 429 | Similar to `Message.text`, but does not raise if `strict` is `False`. |
| 430 | Instead, the message body is returned as surrogate-escaped UTF-8. |
| 431 | """ |
| 432 | content = self.get_content(strict) |
| 433 | if content is None: |
| 434 | return None |
| 435 | enc = infer_content_encoding(self.headers.get("content-type", ""), content) |
| 436 | try: |
| 437 | return cast(str, encoding.decode(content, enc)) |
| 438 | except ValueError: |
| 439 | if strict: |
| 440 | raise |
| 441 | return content.decode("utf8", "surrogateescape") |
| 442 | |
| 443 | @property |
| 444 | def timestamp_start(self) -> float: |