From: Ralf Jung Date: Thu, 1 Jan 2015 21:49:10 +0000 (+0100) Subject: add support for TXT records X-Git-Url: https://git.ralfj.de/zonemaker.git/commitdiff_plain/474e851faa5a89800dfbf7b6a839cff697ae3a87?ds=inline;hp=1e841a56ac7677489d027903ef434c5998486c70 add support for TXT records --- diff --git a/zone.py b/zone.py index d7c23ff..473b79f 100644 --- a/zone.py +++ b/zone.py @@ -134,6 +134,21 @@ class MX: return zone.RR(owner, 'MX', '{0} {1}'.format(self._priority, zone.abs_hostname(self._name))) +class TXT: + def __init__(self, name: str, text: str) -> None: + # test for bad characters + for c in ('\n', '\r', '\t'): + if c in text: + raise Exception("TXT record {0} containts invalid character") + # escape text + for c in ('\\', '\"'): + text = text.replace(c, '\\'+c) + self._text = text + + def generate_rr(self, owner:str, zone: 'Zone') -> 'Any': + return zone.RR(owner, 'TXT', '"{0}"'.format(self._text)) + + class SRV: def __init__(self, protocol: str, service: str, name: str, port: int, prio: int, weight: int) -> None: self._service = check_label(service)