From cea1c65305cdec4cec1d762c35af198dea61e063 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Thu, 22 Sep 2022 18:58:16 -0700 Subject: [PATCH] Remove pprints and add some comments/doc --- octodns/record/__init__.py | 27 ++++++++++++++------------- tests/test_octodns_record.py | 5 +++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 6bd1810..d3214c2 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -86,6 +86,12 @@ class ValidationError(RecordException): class Rr(object): + ''' + Simple object intended to be used with Record.from_rrs to allow providers + that work with RFC formatted rdata to share centralized parsing/encoding + code + ''' + def __init__(self, name, _type, ttl, rdata): self.name = name self._type = _type @@ -185,28 +191,23 @@ class Record(EqualityTupleMixin): @classmethod def from_rrs(cls, zone, rrs, lenient=False): - from pprint import pprint - - pprint({'zone': zone, 'rrs': rrs, 'lenient': lenient}) - + # group records by name & type so that multiple rdatas can be combined + # into a single record when needed grouped = defaultdict(list) for rr in rrs: grouped[(rr.name, rr._type)].append(rr) - pprint({'grouped': grouped}) - records = [] + # walk the grouped rrs converting each one to data and then create a + # record with that data for _, rrs in sorted(grouped.items()): rr = rrs[0] name = zone.hostname_from_fqdn(rr.name) _class = cls._CLASSES[rr._type] - pprint({'rr': rr, 'name': name, 'class': _class}) data = _class.data_from_rrs(rrs) - pprint({'data': data}) record = Record.new(zone, name, data, lenient=lenient) records.append(record) - pprint({'records': records}) return records def __init__(self, zone, name, data, source=None): @@ -382,11 +383,10 @@ class ValuesMixin(object): @classmethod def data_from_rrs(cls, rrs): - values = [cls._value_type.parse_rdata_text(rr.rdata) for rr in rrs] - from pprint import pprint - - pprint({'values': values}) + # type and TTL come from the first rr rr = rrs[0] + # values come from parsing the rdata portion of all rrs + values = [cls._value_type.parse_rdata_text(rr.rdata) for rr in rrs] return {'ttl': rr.ttl, 'type': rr._type, 'values': values} def __init__(self, zone, name, data, source=None): @@ -487,6 +487,7 @@ class ValueMixin(object): @classmethod def data_from_rrs(cls, rrs): + # single value, so single rr only... rr = rrs[0] return { 'ttl': rr.ttl, diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index c80b7c5..19a0f00 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -27,6 +27,7 @@ from octodns.record import ( PtrRecord, Record, RecordException, + Rr, RrParseError, SshfpRecord, SshfpValue, @@ -2503,6 +2504,10 @@ class TestRecord(TestCase): values.add(b) self.assertTrue(b in values) + def test_rr(self): + # nothing much to test, just make sure that things don't blow up + Rr('name', 'type', 42, 'Hello World!').__repr__() + class TestRecordValidation(TestCase): zone = Zone('unit.tests.', [])