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
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
1"""Encoding parameter handling and default."""
3import codecs
4import locale
5from typing import Final
7from . import copying
9__all__ = ['DEFAULT_ENCODING', 'Encoding']
11DEFAULT_ENCODING: Final = 'utf-8'
14class Encoding(copying.CopyBase):
15 """Encoding used for input and output with ``'utf-8'`` default."""
17 _encoding = DEFAULT_ENCODING
19 def __init__(self, *, encoding: str | None = DEFAULT_ENCODING,
20 **kwargs) -> None:
21 super().__init__(**kwargs)
23 self.encoding = encoding
25 def _copy_kwargs(self, **kwargs):
26 """Return the kwargs to create a copy of the instance."""
27 return super()._copy_kwargs(encoding=self._encoding, **kwargs)
29 @property
30 def encoding(self) -> str:
31 """The encoding for the saved source file."""
32 return self._encoding
34 @encoding.setter
35 def encoding(self, encoding: str | None) -> None:
36 if encoding is None:
37 encoding = locale.getpreferredencoding()
39 codecs.lookup(encoding) # raise early
40 self._encoding = encoding