mirror of
				https://github.com/github/octodns.git
				synced 2024-05-11 05:55:00 +00:00 
			
		
		
		
	Change str() to unicode() to avoid encoding problems
This commit is contained in:
		@@ -169,6 +169,7 @@ The above command pulled the existing data out of Route53 and placed the results
 | 
			
		||||
* ALIAS support varies a lot from provider to provider care should be taken to verify that your needs are met in detail.
 | 
			
		||||
   * Dyn's UI doesn't allow editing or view of TTL, but the API accepts and stores the value provided, this value does not appear to be used when served
 | 
			
		||||
   * Dnsimple's uses the configured TTL when serving things through the ALIAS, there's also a secondary TXT record created alongside the ALIAS that octoDNS ignores
 | 
			
		||||
* octoDNS itself supports non-ASCII character sets, but in testing Cloudflare is the only provider where that is currently functional end-to-end. Others have failures either in the client libraries or API calls
 | 
			
		||||
 | 
			
		||||
## Custom Sources and Providers
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@ def main():
 | 
			
		||||
        resolver = AsyncResolver(configure=False,
 | 
			
		||||
                                 num_workers=int(args.num_workers))
 | 
			
		||||
        if not ip_addr_re.match(server):
 | 
			
		||||
            server = str(query(server, 'A')[0])
 | 
			
		||||
            server = unicode(query(server, 'A')[0])
 | 
			
		||||
        log.info('server=%s', server)
 | 
			
		||||
        resolver.nameservers = [server]
 | 
			
		||||
        resolver.lifetime = int(args.timeout)
 | 
			
		||||
@@ -81,12 +81,12 @@ def main():
 | 
			
		||||
        stdout.write(',')
 | 
			
		||||
        stdout.write(record._type)
 | 
			
		||||
        stdout.write(',')
 | 
			
		||||
        stdout.write(str(record.ttl))
 | 
			
		||||
        stdout.write(unicode(record.ttl))
 | 
			
		||||
        compare = {}
 | 
			
		||||
        for future in futures:
 | 
			
		||||
            stdout.write(',')
 | 
			
		||||
            try:
 | 
			
		||||
                answers = [str(r) for r in future.result()]
 | 
			
		||||
                answers = [unicode(r) for r in future.result()]
 | 
			
		||||
            except (NoAnswer, NoNameservers):
 | 
			
		||||
                answers = ['*no answer*']
 | 
			
		||||
            except NXDOMAIN:
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ class BaseProvider(BaseSource):
 | 
			
		||||
        extra = self._extra_changes(existing, changes)
 | 
			
		||||
        if extra:
 | 
			
		||||
            self.log.info('plan:   extra changes\n  %s', '\n  '
 | 
			
		||||
                          .join([str(c) for c in extra]))
 | 
			
		||||
                          .join([unicode(c) for c in extra]))
 | 
			
		||||
            changes += extra
 | 
			
		||||
 | 
			
		||||
        if changes:
 | 
			
		||||
 
 | 
			
		||||
@@ -75,9 +75,9 @@ class Ns1Provider(BaseProvider):
 | 
			
		||||
            else:
 | 
			
		||||
                values.extend(answer['answer'])
 | 
			
		||||
                codes.append([])
 | 
			
		||||
        values = [str(x) for x in values]
 | 
			
		||||
        values = [unicode(x) for x in values]
 | 
			
		||||
        geo = OrderedDict(
 | 
			
		||||
            {str(k): [str(x) for x in v] for k, v in geo.items()}
 | 
			
		||||
            {unicode(k): [unicode(x) for x in v] for k, v in geo.items()}
 | 
			
		||||
        )
 | 
			
		||||
        data['values'] = values
 | 
			
		||||
        data['geo'] = geo
 | 
			
		||||
 
 | 
			
		||||
@@ -140,11 +140,11 @@ class PlanLogger(_PlanOutput):
 | 
			
		||||
 | 
			
		||||
def _value_stringifier(record, sep):
 | 
			
		||||
    try:
 | 
			
		||||
        values = [str(v) for v in record.values]
 | 
			
		||||
        values = [unicode(v) for v in record.values]
 | 
			
		||||
    except AttributeError:
 | 
			
		||||
        values = [record.value]
 | 
			
		||||
    for code, gv in sorted(getattr(record, 'geo', {}).items()):
 | 
			
		||||
        vs = ', '.join([str(v) for v in gv.values])
 | 
			
		||||
        vs = ', '.join([unicode(v) for v in gv.values])
 | 
			
		||||
        values.append('{}: {}'.format(code, vs))
 | 
			
		||||
    return sep.join(values)
 | 
			
		||||
 | 
			
		||||
@@ -181,7 +181,7 @@ class PlanMarkdown(_PlanOutput):
 | 
			
		||||
                    fh.write(' | ')
 | 
			
		||||
                    # TTL
 | 
			
		||||
                    if existing:
 | 
			
		||||
                        fh.write(str(existing.ttl))
 | 
			
		||||
                        fh.write(unicode(existing.ttl))
 | 
			
		||||
                        fh.write(' | ')
 | 
			
		||||
                        fh.write(_value_stringifier(existing, '; '))
 | 
			
		||||
                        fh.write(' | |\n')
 | 
			
		||||
@@ -189,7 +189,7 @@ class PlanMarkdown(_PlanOutput):
 | 
			
		||||
                            fh.write('| | | | ')
 | 
			
		||||
 | 
			
		||||
                    if new:
 | 
			
		||||
                        fh.write(str(new.ttl))
 | 
			
		||||
                        fh.write(unicode(new.ttl))
 | 
			
		||||
                        fh.write(' | ')
 | 
			
		||||
                        fh.write(_value_stringifier(new, '; '))
 | 
			
		||||
                        fh.write(' | ')
 | 
			
		||||
@@ -197,7 +197,7 @@ class PlanMarkdown(_PlanOutput):
 | 
			
		||||
                        fh.write(' |\n')
 | 
			
		||||
 | 
			
		||||
                fh.write('\nSummary: ')
 | 
			
		||||
                fh.write(str(plan))
 | 
			
		||||
                fh.write(unicode(plan))
 | 
			
		||||
                fh.write('\n\n')
 | 
			
		||||
        else:
 | 
			
		||||
            fh.write('## No changes were planned\n')
 | 
			
		||||
@@ -243,7 +243,7 @@ class PlanHtml(_PlanOutput):
 | 
			
		||||
                    # TTL
 | 
			
		||||
                    if existing:
 | 
			
		||||
                        fh.write('    <td>')
 | 
			
		||||
                        fh.write(str(existing.ttl))
 | 
			
		||||
                        fh.write(unicode(existing.ttl))
 | 
			
		||||
                        fh.write('</td>\n    <td>')
 | 
			
		||||
                        fh.write(_value_stringifier(existing, '<br/>'))
 | 
			
		||||
                        fh.write('</td>\n    <td></td>\n  </tr>\n')
 | 
			
		||||
@@ -252,7 +252,7 @@ class PlanHtml(_PlanOutput):
 | 
			
		||||
 | 
			
		||||
                    if new:
 | 
			
		||||
                        fh.write('    <td>')
 | 
			
		||||
                        fh.write(str(new.ttl))
 | 
			
		||||
                        fh.write(unicode(new.ttl))
 | 
			
		||||
                        fh.write('</td>\n    <td>')
 | 
			
		||||
                        fh.write(_value_stringifier(new, '<br/>'))
 | 
			
		||||
                        fh.write('</td>\n    <td>')
 | 
			
		||||
@@ -260,7 +260,7 @@ class PlanHtml(_PlanOutput):
 | 
			
		||||
                        fh.write('</td>\n  </tr>\n')
 | 
			
		||||
 | 
			
		||||
                fh.write('  <tr>\n    <td colspan=6>Summary: ')
 | 
			
		||||
                fh.write(str(plan))
 | 
			
		||||
                fh.write(unicode(plan))
 | 
			
		||||
                fh.write('</td>\n  </tr>\n</table>\n')
 | 
			
		||||
        else:
 | 
			
		||||
            fh.write('<b>No changes were planned</b>')
 | 
			
		||||
 
 | 
			
		||||
@@ -122,7 +122,7 @@ class Record(object):
 | 
			
		||||
                       self.__class__.__name__, name)
 | 
			
		||||
        self.zone = zone
 | 
			
		||||
        # force everything lower-case just to be safe
 | 
			
		||||
        self.name = str(name).lower() if name else name
 | 
			
		||||
        self.name = unicode(name).lower() if name else name
 | 
			
		||||
        self.source = source
 | 
			
		||||
        self.ttl = int(data['ttl'])
 | 
			
		||||
 | 
			
		||||
@@ -274,7 +274,8 @@ class _ValuesMixin(object):
 | 
			
		||||
        return ret
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        values = "['{}']".format("', '".join([str(v) for v in self.values]))
 | 
			
		||||
        values = "['{}']".format("', '".join([unicode(v)
 | 
			
		||||
                                              for v in self.values]))
 | 
			
		||||
        return '<{} {} {}, {}, {}>'.format(self.__class__.__name__,
 | 
			
		||||
                                           self._type, self.ttl,
 | 
			
		||||
                                           self.fqdn, values)
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ class Zone(object):
 | 
			
		||||
            raise Exception('Invalid zone name {}, missing ending dot'
 | 
			
		||||
                            .format(name))
 | 
			
		||||
        # Force everyting to lowercase just to be safe
 | 
			
		||||
        self.name = str(name).lower() if name else name
 | 
			
		||||
        self.name = unicode(name).lower() if name else name
 | 
			
		||||
        self.sub_zones = sub_zones
 | 
			
		||||
        # We're grouping by node, it allows us to efficently search for
 | 
			
		||||
        # duplicates and detect when CNAMEs co-exist with other records
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -208,7 +208,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -234,7 +234,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -256,7 +256,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -282,7 +282,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -305,7 +305,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
@@ -333,7 +333,7 @@ class TestBaseProvider(TestCase):
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        for i in range(int(Plan.MIN_EXISTING_RECORDS)):
 | 
			
		||||
            zone.add_record(Record.new(zone, str(i), {
 | 
			
		||||
            zone.add_record(Record.new(zone, unicode(i), {
 | 
			
		||||
                            'ttl': 60,
 | 
			
		||||
                            'type': 'A',
 | 
			
		||||
                            'value': '2.3.4.5'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user