betty.url module

Provide a URL generation API.

final class betty.url.LocalizedPathUrlGenerator[source]

Bases: LocalizedUrlGenerator

Generate URLs for localizable file paths.

Parameters:

project (betty.project.Project)

__init__(project: betty.project.Project)[source]
Parameters:

project (betty.project.Project)

generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) str[source]

Generate a URL for a resource.

Parameters:
Return type:

str

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

Parameters:

resource (typing.Any)

Return type:

bool

class betty.url.LocalizedUrlGenerator[source]

Bases: _UrlGenerator

Generate URLs for localizable resources.

abstract generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) str[source]

Generate a URL for a resource.

Parameters:
Return type:

str

final class betty.url.ProjectUrlGenerator[source]

Bases: LocalizedUrlGenerator

Generate URLs for all resources provided by a Betty project.

Parameters:

project (betty.project.Project)

__init__(project: betty.project.Project)[source]
Parameters:

project (betty.project.Project)

generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) str[source]

Generate a URL for a resource.

Parameters:
Return type:

str

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

Parameters:

resource (typing.Any)

Return type:

bool

final class betty.url.StaticPathUrlGenerator[source]

Bases: StaticUrlGenerator

Generate URLs for static (non-localized) file paths.

Parameters:

configuration (betty.project.ProjectConfiguration)

__init__(configuration: betty.project.ProjectConfiguration)[source]
Parameters:

configuration (betty.project.ProjectConfiguration)

generate(resource: Any, absolute: bool = False) str[source]

Generate a URL for a resource.

Parameters:
Return type:

str

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

Parameters:

resource (typing.Any)

Return type:

bool

class betty.url.StaticUrlGenerator[source]

Bases: _UrlGenerator

Generate URLs for static (non-localizable) resources.

abstract generate(resource: Any, absolute: bool = False) str[source]

Generate a URL for a resource.

Parameters:
Return type:

str