Browse Source

Remove pprints and add some comments/doc

pull/930/head
Ross McFarland 3 years ago
parent
commit
cea1c65305
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 19 additions and 13 deletions
  1. +14
    -13
      octodns/record/__init__.py
  2. +5
    -0
      tests/test_octodns_record.py

+ 14
- 13
octodns/record/__init__.py View File

@ -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,


+ 5
- 0
tests/test_octodns_record.py View File

@ -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.', [])


Loading…
Cancel
Save