Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/graphviz/encoding.py: 91%
22 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:43 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:43 +0000
1"""Encoding parameter handling and default."""
3import typing
5import codecs
6import locale
8from . import copying
10__all__ = ['DEFAULT_ENCODING', 'Encoding']
12DEFAULT_ENCODING = 'utf-8'
15class Encoding(copying.CopyBase):
16 """Encoding used for input and output with ``'utf-8'`` default."""
18 _encoding = DEFAULT_ENCODING
20 def __init__(self, *, encoding: typing.Optional[str] = DEFAULT_ENCODING,
21 **kwargs) -> None:
22 super().__init__(**kwargs)
24 self.encoding = encoding
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)
30 @property
31 def encoding(self) -> str:
32 """The encoding for the saved source file."""
33 return self._encoding
35 @encoding.setter
36 def encoding(self, encoding: typing.Optional[str]) -> None:
37 if encoding is None:
38 encoding = locale.getpreferredencoding()
40 codecs.lookup(encoding) # raise early
41 self._encoding = encoding