Skip to content

url

This module contains functions and objects used internally to generate URLs.

URLGenerator

Generates URLs based on a chosen base URL.

Attributes:

Name Type Description
base_url str

The base URL.

Source code in luduvo/utilities/url.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class URLGenerator:
    """
    Generates URLs based on a chosen base URL.

    Attributes:
        base_url: The base URL.
    """

    def __init__(self, base_url: str):
        self.base_url: str = base_url

    def get_subdomain(self, subdomain: str, protocol: str = "https") -> str:
        """
        Returns the full URL of a subdomain, given the base subdomain name.

        Arguments:
            subdomain: The URL subdomain.
            protocol: The URL protocol.
        """
        full_url = f"{protocol}://{subdomain}.{self.base_url}"
        logger.debug("Generated subdomain URL: %s", full_url)
        return full_url

    def get_url(
        self,
        path: str,
        subdomain: str = "api",
        base_url: str = None,  # ty:ignore[invalid-parameter-default]
        protocol: str = "https",
    ) -> str:
        """
        Returns a full URL, given a subdomain name, protocol, and path.

        Arguments:
            path: The URL path.
            subdomain: The URL subdomain.
            base_url: The base URL.
            protocol: The URL protocol.
        """
        if base_url is None:
            base_url = self.base_url

        full_url = f"{protocol}://{subdomain}.{base_url}/{path}"
        logger.debug("Generated URL: %s", full_url)
        return full_url

get_subdomain(subdomain, protocol='https')

Returns the full URL of a subdomain, given the base subdomain name.

Parameters:

Name Type Description Default
subdomain str

The URL subdomain.

required
protocol str

The URL protocol.

'https'
Source code in luduvo/utilities/url.py
25
26
27
28
29
30
31
32
33
34
35
def get_subdomain(self, subdomain: str, protocol: str = "https") -> str:
    """
    Returns the full URL of a subdomain, given the base subdomain name.

    Arguments:
        subdomain: The URL subdomain.
        protocol: The URL protocol.
    """
    full_url = f"{protocol}://{subdomain}.{self.base_url}"
    logger.debug("Generated subdomain URL: %s", full_url)
    return full_url

get_url(path, subdomain='api', base_url=None, protocol='https')

Returns a full URL, given a subdomain name, protocol, and path.

Parameters:

Name Type Description Default
path str

The URL path.

required
subdomain str

The URL subdomain.

'api'
base_url str

The base URL.

None
protocol str

The URL protocol.

'https'
Source code in luduvo/utilities/url.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def get_url(
    self,
    path: str,
    subdomain: str = "api",
    base_url: str = None,  # ty:ignore[invalid-parameter-default]
    protocol: str = "https",
) -> str:
    """
    Returns a full URL, given a subdomain name, protocol, and path.

    Arguments:
        path: The URL path.
        subdomain: The URL subdomain.
        base_url: The base URL.
        protocol: The URL protocol.
    """
    if base_url is None:
        base_url = self.base_url

    full_url = f"{protocol}://{subdomain}.{base_url}/{path}"
    logger.debug("Generated URL: %s", full_url)
    return full_url