FileLocData#

class tollan.utils.fileloc.FileLocData(url: None | FileLocUrl = None, path: None | Path = None, netloc: str = '', local_parent_path: None | Path = None, remote_parent_path: None | Path = None)[source]#

Bases: object

A helper model for storing file loc data.

Attributes Summary

data_unresolved

The unresolved data.

local_parent_path

netloc

netloc_resolved

The resolved netloc.

path

path_resolved

The resolved path.

remote_parent_path

url

url_resolved

Ensure one of URL and path is given, and compute resolved URL.

Methods Summary

validate_arg(values, info)

Return file loc data from any compatible input.

validate_netloc(v, info)

Normalize netloc to string.

validate_path(v, info)

Ensure path is Path instance.

Attributes Documentation

data_unresolved#

The unresolved data.

Returns:

Original unresolved URL string or (netloc, path) tuple

Return type:

str | tuple[str, Path]

local_parent_path: None | Path = None#
netloc: str = ''#
netloc_resolved[source]#

The resolved netloc.

Returns:

Resolved network location (empty for localhost)

Return type:

str

path: None | Path = None#
path_resolved[source]#

The resolved path.

Returns:

Fully resolved file path

Return type:

Path

remote_parent_path: None | Path = None#
url: None | Annotated[AnyUrl, UrlConstraints(max_length=None, allowed_schemes=['file', 'http', 'https'], host_required=None, default_host=None, default_port=None, default_path=None, preserve_empty_path=None), BeforeValidator(func=_url_unquote, json_schema_input_type=PydanticUndefined)] = None#
url_resolved[source]#

Ensure one of URL and path is given, and compute resolved URL.

Returns:

Fully resolved file location URL

Return type:

FileLocUrl

Methods Documentation

classmethod validate_arg(values: ArgsKwargs | dict[str, Any], info: ValidationInfo) ArgsKwargs[source]#

Return file loc data from any compatible input.

Valid forms of inputs are: * dict contains keys url, path, netloc; * tuple consists of (netloc, path); * str or Path instance.

Parameters:
  • values (ArgsKwargs | dict[str, Any]) – Input values to validate (args/kwargs or dict)

  • info (ValidationInfo) – Pydantic validation context

Returns:

Validated file location data as ArgsKwargs

Return type:

ArgsKwargs

classmethod validate_netloc(v: str | None, info: ValidationInfo) str[source]#

Normalize netloc to string.

Parameters:
  • v (str | None) – Network location value

  • info (ValidationInfo) – Pydantic validation context

Returns:

Normalized netloc (empty string for localhost/None)

Return type:

str

classmethod validate_path(v: str | Path, info: ValidationInfo) Path[source]#

Ensure path is Path instance.

Parameters:
  • v (str | Path) – Path value to validate

  • info (ValidationInfo) – Pydantic validation context

Returns:

Validated Path instance

Return type:

Path