1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

MX RFC1035 - priority -> preference & value -> exchange

This commit is contained in:
Ross McFarland
2017-06-23 13:04:38 -07:00
parent 3ca64c4e08
commit 1340aee8a9
14 changed files with 118 additions and 88 deletions

View File

@@ -424,32 +424,45 @@ class MxValue(object):
@classmethod
def _validate_value(cls, value):
reasons = []
if 'priority' not in value:
reasons.append('missing priority')
if 'value' not in value:
reasons.append('missing value')
if 'preference' not in value and 'priority' not in value:
reasons.append('missing preference')
exchange = None
try:
exchange = value.get('exchange', None) or value['value']
if not exchange.endswith('.'):
reasons.append('missing trailing .')
except KeyError:
reasons.append('missing exchange')
return reasons
def __init__(self, value):
# TODO: rename preference
self.priority = int(value['priority'])
# TODO: rename to exchange?
self.value = value['value'].lower()
# RFC1035 says preference, half the providers use priority
try:
preference = value['preference']
except KeyError:
preference = value['priority']
self.preference = int(preference)
# UNTIL 1.0 remove value fallback
try:
exchange = value['exchange']
except KeyError:
exchange = value['value']
self.exchange = exchange
@property
def data(self):
return {
'priority': self.priority,
'value': self.value,
'preference': self.preference,
'exchange': self.exchange,
}
def __cmp__(self, other):
if self.priority == other.priority:
return cmp(self.value, other.value)
return cmp(self.priority, other.priority)
if self.preference == other.preference:
return cmp(self.exchange, other.exchange)
return cmp(self.preference, other.preference)
def __repr__(self):
return "'{} {}'".format(self.priority, self.value)
return "'{} {}'".format(self.preference, self.exchange)
class MxRecord(_ValuesMixin, Record):