mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Remove pprints and add some comments/doc
This commit is contained in:
+14
-13
@@ -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,
|
||||
|
||||
@@ -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.', [])
|
||||
|
||||
Reference in New Issue
Block a user