src/r53/r53.py
def normalize_rrs(rrsets):
  """Lexically sort the order of every ResourceRecord in a ResourceRecords
  element so we don't generate spurious changes: ordering of e.g. NS records
  is irrelevant to the DNS line protocol, but XML sees it differently.

  Also rewrite any wildcard records to use the ascii hex code: somewhere deep
  inside route53 is something that used to look like tinydns, and amazon's
  API will always display wildcard records as "\052.example.com".

  Args: rrsest: lxml.etree.Element (<ResourceRecordSets>) """
  for rrset in rrsets:
    if rrset.tag == '{%s}ResourceRecordSet' % R53_XMLNS:
      for rrs in rrset:
        # preformat wildcard records
        if rrs.tag == '{%s}Name' % R53_XMLNS:
          if rrs.text.startswith('*.'):
            old_text = rrs.text
            new_text = '\\052.%s' % old_text[2:]
            print 'Found wildcard record, rewriting to %s' % new_text
            rrs.text = rrs.text.replace(old_text, new_text)
        # sort ResourceRecord elements by Value
        if rrs.tag == '{%s}ResourceRecords' % R53_XMLNS:
          # 0th value of ResourceRecord is always the Value element
          sorted_rrs = sorted(rrs, key=lambda x: x[0].text)
          rrs[:] = sorted_rrs
  return rrsets
def normalize_rrs(rrsets):
  """Lexically sort the order of every ResourceRecord in a ResourceRecords
  element so we don't generate spurious changes: ordering of e.g. NS records
  is irrelevant to the DNS line protocol, but XML sees it differently.

  Also rewrite any wildcard records to use the ascii hex code: somewhere deep
  inside route53 is something that used to look like tinydns, and amazon's
  API will always display wildcard records as "\052.example.com".

  Args: rrsest: lxml.etree.Element (<ResourceRecordSets>) """
  for rrset in rrsets:
    if rrset.tag == '{%s}ResourceRecordSet' % R53_XMLNS:
      for rrs in rrset:
        # preformat wildcard records
        if rrs.tag == '{%s}Name' % R53_XMLNS:
          if rrs.text.startswith('*.'):
            old_text = rrs.text
            new_text = '\\052.%s' % old_text[2:]
            print 'Found wildcard record, rewriting to %s' % new_text
            rrs.text = rrs.text.replace(old_text, new_text)
        # sort ResourceRecord elements by Value
        if rrs.tag == '{%s}ResourceRecords' % R53_XMLNS:
          # 0th value of ResourceRecord is always the Value element
          sorted_rrs = sorted(rrs, key=lambda x: x[0].text)
          rrs[:] = sorted_rrs
  return rrsets
Lexically sort the order of every ResourceRecord in a ResourceRecords
  element so we don't generate spurious changes: ordering of e.g. NS records
  is irrelevant to the DNS line protocol, but XML sees it differently.

  Also rewrite any wildcard records to use the ascii hex code: somewhere deep
  inside route53 is something that used to look like tinydns, and amazon's
  API will always display wildcard records as "\052.example.com".

  Args: rrsest: lxml.etree.Element (<ResourceRecordSets>)