File tree Expand file tree Collapse file tree 4 files changed +55
-0
lines changed
Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ The `exp` module is a namespace that holds experimental features for the `hcloud-python`
3+ library, breaking changes may occur within minor releases.
4+ """
Original file line number Diff line number Diff line change 1+ """
2+ The `exp.zone` module is a namespace that holds experimental features for the `hcloud-python`
3+ library, breaking changes may occur within minor releases.
4+ """
5+
6+ from __future__ import annotations
7+
8+
9+ def format_txt_record (value : str ) -> str :
10+ """
11+ Format a TXT record by splitting it in quoted strings of 255 characters.
12+ Existing quotes will be escaped.
13+
14+ - hello world => "hello world"
15+ - hello "world" => "hello \" world\" "
16+ """
17+ value = value .replace ('"' , '\\ "' )
18+
19+ parts = []
20+ for start in range (0 , len (value ), 255 ):
21+ end = min (start + 255 , len (value ))
22+ parts .append ('"' + value [start :end ] + '"' )
23+ value = " " .join (parts )
24+
25+ return value
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from datetime import timedelta
4+
5+ import pytest
6+
7+ from hcloud .exp .zone import format_txt_record
8+
9+ manyA = "a" * 255
10+ someB = "b" * 10
11+
12+
13+ @pytest .mark .parametrize (
14+ ("value" , "expected" ),
15+ [
16+ ("" , "" ),
17+ ('""' , '"\\ "\\ ""' ),
18+ ("hello world" , '"hello world"' ),
19+ ("hello\n world" , '"hello\n world"' ),
20+ ('hello "world"' , '"hello \\ "world\\ ""' ),
21+ ('hello "world' , '"hello \\ "world"' ),
22+ (manyA + someB , f'"{ manyA } " "{ someB } "' ),
23+ ],
24+ )
25+ def test_parse_duration (value : str , expected : timedelta ):
26+ assert format_txt_record (value ) == expected
You can’t perform that action at this time.
0 commit comments