| 75 | |
| 76 | @contextlib.contextmanager |
| 77 | def restrict_to(self, size: int) -> Iterator: |
| 78 | assert size >= 0 |
| 79 | if size > self.remaining(): |
| 80 | raise dns.exception.FormError |
| 81 | saved_end = self.end |
| 82 | try: |
| 83 | self.end = self.current + size |
| 84 | yield |
| 85 | # We make this check here and not in the finally as we |
| 86 | # don't want to raise if we're already raising for some |
| 87 | # other reason. |
| 88 | if self.current != self.end: |
| 89 | raise dns.exception.FormError |
| 90 | finally: |
| 91 | self.end = saved_end |
| 92 | |
| 93 | @contextlib.contextmanager |
| 94 | def restore_furthest(self) -> Iterator: |