Skip to content

Locator

sereto.models.locator

BaseLocatorModel

Bases: SeretoBaseModel

Common base model for all locator types.

You should typically use LocatorModel instead of this class directly.

Attributes:

Name Type Description
type str

The type of locator (discriminator field).

description str | None

An optional description of the locator.

Source code in sereto/models/locator.py
 9
10
11
12
13
14
15
16
17
18
19
20
class BaseLocatorModel(SeretoBaseModel):
    """Common base model for all locator types.

    You should typically use `LocatorModel` instead of this class directly.

    Attributes:
        type: The type of locator (discriminator field).
        description: An optional description of the locator.
    """

    type: str
    description: str | None = None

DomainLocatorModel

Bases: BaseLocatorModel

Model representing a domain locator.

Attributes:

Name Type Description
type Literal['domain']

The discriminator for the locator type, which is always "domain".

value str

The domain of the locator.

description str | None

Optional description of the domain locator.

Source code in sereto/models/locator.py
53
54
55
56
57
58
59
60
61
62
63
class DomainLocatorModel(BaseLocatorModel):
    """Model representing a domain locator.

    Attributes:
        type: The discriminator for the locator type, which is always "domain".
        value: The domain of the locator.
        description: Optional description of the domain locator.
    """

    type: Literal["domain"] = "domain"
    value: str  # Domain as a string

FileLocatorModel

Bases: BaseLocatorModel

Model representing a file locator.

Attributes:

Name Type Description
type Literal['file']

The discriminator for the locator type, which is always "file".

value str

The path to the file, may contain specific line.

description str | None

Optional description of the file locator.

Source code in sereto/models/locator.py
83
84
85
86
87
88
89
90
91
92
93
class FileLocatorModel(BaseLocatorModel):
    """Model representing a file locator.

    Attributes:
        type: The discriminator for the locator type, which is always "file".
        value: The path to the file, may contain specific line.
        description: Optional description of the file locator.
    """

    type: Literal["file"] = "file"
    value: str  # Path to the file

HostnameLocatorModel

Bases: BaseLocatorModel

Model representing a hostname locator.

Attributes:

Name Type Description
type Literal['hostname']

The discriminator for the locator type, which is always "hostname".

value str

The hostname of the locator.

description str | None

Optional description of the hostname locator.

Source code in sereto/models/locator.py
40
41
42
43
44
45
46
47
48
49
50
class HostnameLocatorModel(BaseLocatorModel):
    """Model representing a hostname locator.

    Attributes:
        type: The discriminator for the locator type, which is always "hostname".
        value: The hostname of the locator.
        description: Optional description of the hostname locator.
    """

    type: Literal["hostname"] = "hostname"
    value: str  # Hostname as a string

IpLocatorModel

Bases: BaseLocatorModel

Model representing an IP locator.

Attributes:

Name Type Description
type Literal['ip']

The discriminator for the locator type, which is always "ip".

value IPvAnyAddress | IPvAnyNetwork

The IP address or network of the locator.

description str | None

Optional description of the IP locator.

Source code in sereto/models/locator.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class IpLocatorModel(BaseLocatorModel):
    """Model representing an IP locator.

    Attributes:
        type: The discriminator for the locator type, which is always "ip".
        value: The IP address or network of the locator.
        description: Optional description of the IP locator.
    """

    type: Literal["ip"] = "ip"
    value: IPvAnyAddress | IPvAnyNetwork

    @field_serializer("value")
    def serialize_value(self, value: IPvAnyAddress | IPvAnyNetwork) -> str:
        return str(value)

UrlLocatorModel

Bases: BaseLocatorModel

Model representing a URL locator.

Attributes:

Name Type Description
type Literal['url']

The discriminator for the locator type, which is always "url".

value AnyUrl

The URL of the locator.

description str | None

Optional description of the URL locator.

Source code in sereto/models/locator.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class UrlLocatorModel(BaseLocatorModel):
    """Model representing a URL locator.

    Attributes:
        type: The discriminator for the locator type, which is always "url".
        value: The URL of the locator.
        description: Optional description of the URL locator.
    """

    type: Literal["url"] = "url"
    value: AnyUrl

    @field_serializer("value")
    def serialize_value(self, value: AnyUrl) -> str:
        return str(value)

dump_locators_to_toml(locators)

Dump locators to a TOML string.

Parameters:

Name Type Description Default
locators Iterable[LocatorModel]

An iterable of LocatorModel instances.

required

Returns:

Type Description
str

A TOML formatted string representing the locators.

Source code in sereto/models/locator.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@validate_call
def dump_locators_to_toml(locators: Iterable[LocatorModel]) -> str:
    """Dump locators to a TOML string.

    Args:
        locators: An iterable of LocatorModel instances.

    Returns:
        A TOML formatted string representing the locators.
    """
    if len(loc_list := list(locators)) == 0:
        return "[]"

    lines: list[str] = []
    for loc in loc_list:
        desc = f', description="{loc.description}"' if loc.description else ""
        lines.append(f'{{type="{loc.type}", value="{loc.value}"{desc}}},')
    return "[\n    " + "\n    ".join(lines) + "\n]"

get_locator_types()

Get all locator types defined in LocatorModel.

Source code in sereto/models/locator.py
123
124
125
126
127
def get_locator_types() -> list[str]:
    """Get all locator types defined in LocatorModel."""
    union_type, *_ = get_args(LocatorModel)  # first arg is `UrlLocatorModel | HostnameLocatorModel | ...`
    locator_classes = get_args(union_type)  # the individual model classes
    return [cls.model_fields["type"].default for cls in locator_classes]