Skip to content

base

pokelance.ext._base ⚓︎

BaseExtension(client) ⚓︎

The base extension class.

Parameters:

Name Type Description Default
client HttpClient

The client to use for requests.

required

Attributes:

Name Type Description
_client HttpClient

The client to use for requests.

_cache Cache

The cache to use for requests.

Initializes the extension.

Parameters:

Name Type Description Default
client HttpClient

The client to use for requests.

required
Source code in pokelance/ext/_base.py
Python
def __init__(self, client: "HttpClient") -> None:
    """Initializes the extension.

    Parameters
    ----------
    client: pokelance.http.HttpClient
        The client to use for requests.
    """
    self._client = client
    self._cache = self._client.cache
    self.cache = getattr(self._cache, self.__class__.__name__.lower())

get_message(case, data) staticmethod ⚓︎

Gets the error message for a resource not found error.

Parameters:

Name Type Description Default
case str

The case to use for the error message.

required
data Set[str]

The data to use for the error message.

required

Returns:

Type Description
str

The error message.

Source code in pokelance/ext/_base.py
Python
@staticmethod
def get_message(case: str, data: t.Set[str]) -> str:
    """Gets the error message for a resource not found error.

    Parameters
    ----------
    case: str
        The case to use for the error message.
    data: typing.Set[str]
        The data to use for the error message.

    Returns
    -------
    str
        The error message.
    """
    matches = get_close_matches(case, data, n=10, cutoff=0.5)
    if matches:
        return f"Resource not found. Did you mean {', '.join(matches)}?"
    return "Resource not found."

setup() async ⚓︎

Sets up the extension.

Source code in pokelance/ext/_base.py
Python
async def setup(self) -> None:
    """Sets up the extension."""
    for item in dir(self):
        if item.startswith("fetch_"):
            data = await self._client.request(
                t.cast(t.Callable[[], "Route"], getattr(Endpoint, f"get_{item[6:]}_endpoints"))()
            )
            self._cache.load_documents(str(self.__class__.__name__), item[6:], data["results"])