mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-03 23:51:48 +00:00
##### SUMMARY All `module_utils` are now marked as **private**. None of the modules were intended for public use. Similar to https://togithub.com/ansible-collections/community.general/issues/11312
40 lines
981 B
Python
40 lines
981 B
Python
"""
|
|
The `exp.zone` module is a namespace that holds experimental features for the `hcloud-python`
|
|
library, breaking changes may occur within minor releases.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
__all__ = [
|
|
"is_txt_record_quoted",
|
|
"format_txt_record",
|
|
]
|
|
|
|
|
|
def is_txt_record_quoted(value: str) -> bool:
|
|
"""
|
|
Check whether a TXT record is already quoted.
|
|
|
|
- hello world => false
|
|
- "hello world" => true
|
|
"""
|
|
return value.startswith('"') and value.endswith('"')
|
|
|
|
|
|
def format_txt_record(value: str) -> str:
|
|
"""
|
|
Format a TXT record by splitting it in quoted strings of 255 characters.
|
|
Existing quotes will be escaped.
|
|
|
|
- hello world => "hello world"
|
|
- hello "world" => "hello \"world\""
|
|
"""
|
|
value = value.replace('"', '\\"')
|
|
|
|
parts = []
|
|
for start in range(0, len(value), 255):
|
|
end = min(start + 255, len(value))
|
|
parts.append('"' + value[start:end] + '"')
|
|
value = " ".join(parts)
|
|
|
|
return value
|