Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/graphviz/encoding.py: 91%

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

23 statements  

1"""Encoding parameter handling and default.""" 

2 

3import typing 

4 

5import codecs 

6import locale 

7 

8from . import copying 

9 

10__all__ = ['DEFAULT_ENCODING', 'Encoding'] 

11 

12DEFAULT_ENCODING = 'utf-8' 

13 

14 

15class Encoding(copying.CopyBase): 

16 """Encoding used for input and output with ``'utf-8'`` default.""" 

17 

18 _encoding = DEFAULT_ENCODING 

19 

20 def __init__(self, *, encoding: typing.Optional[str] = DEFAULT_ENCODING, 

21 **kwargs) -> None: 

22 super().__init__(**kwargs) 

23 

24 self.encoding = encoding 

25 

26 def _copy_kwargs(self, **kwargs): 

27 """Return the kwargs to create a copy of the instance.""" 

28 return super()._copy_kwargs(encoding=self._encoding, **kwargs) 

29 

30 @property 

31 def encoding(self) -> str: 

32 """The encoding for the saved source file.""" 

33 return self._encoding 

34 

35 @encoding.setter 

36 def encoding(self, encoding: typing.Optional[str]) -> None: 

37 if encoding is None: 

38 encoding = locale.getpreferredencoding() 

39 

40 codecs.lookup(encoding) # raise early 

41 self._encoding = encoding