-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathzone.py
More file actions
35 lines (26 loc) · 913 Bytes
/
zone.py
File metadata and controls
35 lines (26 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
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
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