| Server IP : 93.86.61.54 / Your IP : 216.73.216.206 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/ufoLib2/objects/ |
Upload File : |
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, Mapping, Tuple
if TYPE_CHECKING:
from typing import Type
from cattr import GenConverter
KerningPair = Tuple[str, str]
class Kerning(Dict[KerningPair, float]):
def as_nested_dicts(self) -> dict[str, dict[str, float]]:
result: dict[str, dict[str, float]] = {}
for (left, right), value in self.items():
result.setdefault(left, {})[right] = value
return result
@classmethod
def from_nested_dicts(self, kerning: Mapping[str, Mapping[str, float]]) -> Kerning:
return Kerning(
((left, right), kerning[left][right])
for left in kerning
for right in kerning[left]
)
def _unstructure(self, converter: GenConverter) -> dict[str, dict[str, float]]:
del converter # unused
return self.as_nested_dicts()
@staticmethod
def _structure(
data: Mapping[str, Mapping[str, float]],
cls: Type[Kerning],
converter: GenConverter,
) -> Kerning:
del converter # unused
return cls.from_nested_dicts(data)