Just inherit the class and set pattern for _re.
class ABPattern(_PatternBase):
- _re: Pattern[str] = r"ab*"
+ _re: Pattern[str] = re.compile(r"ab*")
"""
_re: Pattern[str]
else:
raise SchemaException(
f"Unexpected input type for string pattern - {type(source_value)}."
- "Cause might be invalid format or invalid type.",
+ " Cause might be invalid format or invalid type.",
object_path,
)
self._value: Path = Path(source_value)
else:
raise SchemaException(
- f"Expected file path in a string, got '{source_value}' with type '{type(source_value)}'", object_path
+ f"Expected file path in a string, got '{source_value}' with type '{type(source_value)}'.", object_path
)
def __str__(self) -> str:
self._value = source_value
else:
raise SchemaException(
- f"Unexpected value for '<interface>@<port>'. "
- f"Expected string, got '{source_value}' with type '{type(source_value)}'",
+ "Unexpected value for '<interface>@<port>'."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
self._value = source_value
else:
raise SchemaException(
- f"Unexpected value for '<interface>[@<port>]'. "
- f"Expected string, got '{source_value}' with type '{type(source_value)}'",
+ "Unexpected value for '<interface>[@<port>]'."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
self._value = source_value
else:
raise SchemaException(
- f"Unexpected value for '<ip-address>@<port>'. "
- f"Expected string, got '{source_value}' with type '{type(source_value)}'",
+ "Unexpected value for '<ip-address>@<port>'."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
self._value = source_value
else:
raise SchemaException(
- f"Unexpected value for a '<ip-address>[@<port>]'. "
- f"Expected string, got '{source_value}' with type '{type(source_value)}'",
+ "Unexpected value for a '<ip-address>[@<port>]'."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
class IPv4Address(CustomValueType):
+ _value: ipaddress.IPv4Address
+
def __init__(self, source_value: Any, object_path: str = "/") -> None:
super().__init__(source_value)
if isinstance(source_value, str):
raise SchemaException("Failed to parse IPv4 address.", object_path) from e
else:
raise SchemaException(
- f"Unexpected value for a IPv4 address. Expected string, got '{source_value}'"
- f" with type '{type(source_value)}'",
+ "Unexpected value for a IPv4 address."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
class IPv6Address(CustomValueType):
+ _value: ipaddress.IPv6Address
+
def __init__(self, source_value: Any, object_path: str = "/") -> None:
super().__init__(source_value)
if isinstance(source_value, str):
raise SchemaException("Failed to parse IPv6 address.", object_path) from e
else:
raise SchemaException(
- f"Unexpected value for a IPv6 address. Expected string, got '{source_value}'"
- f" with type '{type(source_value)}'",
+ "Unexpected value for a IPv6 address."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
class IPNetwork(CustomValueType):
+ _value: Union[ipaddress.IPv4Network, ipaddress.IPv6Network]
+
def __init__(self, source_value: Any, object_path: str = "/") -> None:
super().__init__(source_value)
if isinstance(source_value, str):
raise SchemaException("Failed to parse IP network.", object_path) from e
else:
raise SchemaException(
- f"Unexpected value for a network subnet. Expected string, got '{source_value}'"
- " with type '{type(source_value)}'",
+ "Unexpected value for a network subnet."
+ f" Expected string, got '{source_value}' with type '{type(source_value)}'",
object_path,
)
class IPv6Network96(CustomValueType):
+ _value: ipaddress.IPv6Network
+
def __init__(self, source_value: Any, object_path: str = "/") -> None:
super().__init__(source_value, object_path=object_path)
if isinstance(source_value, str):