Skip to content

base

Class info

Classes

Name Children Inherits
FontProvider
pycons.font_providers.base
Base class for font providers.

🛈 DocStrings

Base class for font providers.

FontProvider

Bases: ABC

Base class for font providers.

Source code in src/pycons/font_providers/base.py
class FontProvider(ABC):
    """Base class for font providers."""

    # Override in subclasses
    NAME: ClassVar[str]
    PREFIX: ClassVar[str]
    DISPLAY_NAME: ClassVar[str]

    def __init__(self, use_cache: bool = True) -> None:
        super().__init__()
        self.use_cache = use_cache

    @abstractmethod
    async def get_latest_version(self) -> str:
        """Get the latest version from the source."""
        ...

    @abstractmethod
    def get_download_urls(self, version: str) -> tuple[str, str]:
        """Get URLs for the font file and mapping.

        Returns:
            Tuple of (ttf_url, mapping_url)
        """
        ...

    @abstractmethod
    def process_mapping(self, mapping_data: bytes) -> dict[str, str]:
        """Process the raw mapping data into a name->unicode dict.

        Different fonts provide their mappings in different formats (JSON, CSS, etc).
        This method handles the font-specific processing.

        Args:
            mapping_data: Raw bytes of the mapping file

        Returns:
            Dict mapping icon names to unicode points
        """
        ...

get_download_urls abstractmethod

get_download_urls(version: str) -> tuple[str, str]

Get URLs for the font file and mapping.

Returns:

Type Description
tuple[str, str]

Tuple of (ttf_url, mapping_url)

Source code in src/pycons/font_providers/base.py
@abstractmethod
def get_download_urls(self, version: str) -> tuple[str, str]:
    """Get URLs for the font file and mapping.

    Returns:
        Tuple of (ttf_url, mapping_url)
    """
    ...

get_latest_version abstractmethod async

get_latest_version() -> str

Get the latest version from the source.

Source code in src/pycons/font_providers/base.py
@abstractmethod
async def get_latest_version(self) -> str:
    """Get the latest version from the source."""
    ...

process_mapping abstractmethod

process_mapping(mapping_data: bytes) -> dict[str, str]

Process the raw mapping data into a name->unicode dict.

Different fonts provide their mappings in different formats (JSON, CSS, etc). This method handles the font-specific processing.

Parameters:

Name Type Description Default
mapping_data bytes

Raw bytes of the mapping file

required

Returns:

Type Description
dict[str, str]

Dict mapping icon names to unicode points

Source code in src/pycons/font_providers/base.py
@abstractmethod
def process_mapping(self, mapping_data: bytes) -> dict[str, str]:
    """Process the raw mapping data into a name->unicode dict.

    Different fonts provide their mappings in different formats (JSON, CSS, etc).
    This method handles the font-specific processing.

    Args:
        mapping_data: Raw bytes of the mapping file

    Returns:
        Dict mapping icon names to unicode points
    """
    ...