| 645 | |
| 646 | |
| 647 | def test_no_repr(): |
| 648 | class MyBytes(object): |
| 649 | def __init__(self, contents): |
| 650 | self.contents = contents |
| 651 | self.errored = None |
| 652 | |
| 653 | def __iter__(self): |
| 654 | return iter(self.contents) |
| 655 | |
| 656 | def decode(self, encoding): |
| 657 | self.errored = "decode called" |
| 658 | raise RuntimeError("Should not be called.") |
| 659 | |
| 660 | def __repr__(self): |
| 661 | self.errored = "__repr__ called" |
| 662 | raise RuntimeError("Should not be called.") |
| 663 | |
| 664 | def __getitem__(self, *args): |
| 665 | return self.contents.__getitem__(*args) |
| 666 | |
| 667 | def __len__(self): |
| 668 | return len(self.contents) |
| 669 | |
| 670 | safe_repr = SafeRepr() |
| 671 | safe_repr.string_types = (MyBytes,) |
| 672 | safe_repr.bytes = MyBytes |
| 673 | obj = b"f" * (safe_repr.maxstring_outer * 10) |
| 674 | my_bytes = MyBytes(obj) |
| 675 | raw_value_repr = safe_repr(my_bytes) |
| 676 | assert not my_bytes.errored |