Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dns/_render_util.py: 22%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1import contextlib 

2 

3import dns.exception 

4 

5 

6@contextlib.contextmanager 

7def prefixed_length(output, length_length): 

8 output.write(b"\00" * length_length) 

9 start = output.tell() 

10 yield 

11 end = output.tell() 

12 length = end - start 

13 if length > 0: 

14 try: 

15 output.seek(start - length_length) 

16 try: 

17 output.write(length.to_bytes(length_length, "big")) 

18 except OverflowError: 

19 raise dns.exception.FormError 

20 finally: 

21 output.seek(end)