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

f-strings for octodns/source/*

This commit is contained in:
Ross McFarland
2021-09-02 16:49:52 -07:00
parent 6b052feaa4
commit b749d8cc32
3 changed files with 15 additions and 16 deletions

View File

@@ -151,7 +151,7 @@ class AxfrBaseSource(BaseSource):
before = len(zone.records)
for name, types in values.items():
for _type, records in types.items():
data_for = getattr(self, '_data_for_{}'.format(_type))
data_for = getattr(self, f'_data_for_{_type}')
record = Record.new(zone, name, data_for(_type, records),
source=self, lenient=lenient)
zone.add_record(record, lenient=lenient)
@@ -181,7 +181,7 @@ class AxfrSource(AxfrBaseSource):
master: ns1.example.com
'''
def __init__(self, id, master):
self.log = logging.getLogger('AxfrSource[{}]'.format(id))
self.log = logging.getLogger(f'AxfrSource[{id}]')
self.log.debug('__init__: id=%s, master=%s', id, master)
super(AxfrSource, self).__init__(id)
self.master = master
@@ -244,7 +244,7 @@ class ZoneFileSource(AxfrBaseSource):
check_origin: false
'''
def __init__(self, id, directory, file_extension='.', check_origin=True):
self.log = logging.getLogger('ZoneFileSource[{}]'.format(id))
self.log = logging.getLogger(f'ZoneFileSource[{id}]')
self.log.debug('__init__: id=%s, directory=%s, file_extension=%s, '
'check_origin=%s', id,
directory, file_extension, check_origin)
@@ -256,7 +256,7 @@ class ZoneFileSource(AxfrBaseSource):
self._zone_records = {}
def _load_zone_file(self, zone_name):
zone_filename = '{}{}'.format(zone_name[:-1], self.file_extension)
zone_filename = f'{zone_name[:-1]}{self.file_extension}'
zonefiles = listdir(self.directory)
if zone_filename in zonefiles:
try:

View File

@@ -13,7 +13,7 @@ class EnvVarSourceException(Exception):
class EnvironmentVariableNotFoundException(EnvVarSourceException):
def __init__(self, data):
super(EnvironmentVariableNotFoundException, self).__init__(
'Unknown environment variable {}'.format(data))
f'Unknown environment variable {data}')
class EnvVarSource(BaseSource):
@@ -63,8 +63,8 @@ class EnvVarSource(BaseSource):
DEFAULT_TTL = 60
def __init__(self, id, variable, name, ttl=DEFAULT_TTL):
self.log = logging.getLogger('{}[{}]'.format(
self.__class__.__name__, id))
klass = self.__class__.__name__
self.log = logging.getLogger(f'{klass}[{id}]')
self.log.debug('__init__: id=%s, variable=%s, name=%s, '
'ttl=%d', id, variable, name, ttl)
super(EnvVarSource, self).__init__(id)

View File

@@ -90,7 +90,7 @@ class TinyDnsBaseSource(BaseSource):
return {
'ttl': ttl,
'type': _type,
'value': '{}.'.format(first[0])
'value': f'{first[0]}.'
}
def _data_for_MX(self, _type, records):
@@ -103,7 +103,7 @@ class TinyDnsBaseSource(BaseSource):
'type': _type,
'values': [{
'preference': r[1],
'exchange': '{}.'.format(r[0])
'exchange': f'{r[0]}.'
} for r in records]
}
@@ -115,7 +115,7 @@ class TinyDnsBaseSource(BaseSource):
return {
'ttl': ttl,
'type': _type,
'values': ['{}.'.format(r[0]) for r in records]
'values': [f'{r[0]}.' for r in records]
}
def populate(self, zone, target=False, lenient=False):
@@ -168,7 +168,7 @@ class TinyDnsBaseSource(BaseSource):
for name, types in data.items():
for _type, d in types.items():
data_for = getattr(self, '_data_for_{}'.format(_type))
data_for = getattr(self, f'_data_for_{_type}')
data = data_for(_type, d)
if data:
record = Record.new(zone, name, data, source=self,
@@ -196,11 +196,11 @@ class TinyDnsBaseSource(BaseSource):
if line[0].endswith('in-addr.arpa'):
# since it's already in in-addr.arpa format
match = name_re.match(line[0])
value = '{}.'.format(line[1])
value = f'{line[1]}.'
else:
addr = ip_address(line[1])
match = name_re.match(addr.reverse_pointer)
value = '{}.'.format(line[0])
value = f'{line[0]}.'
if match:
try:
@@ -217,8 +217,7 @@ class TinyDnsBaseSource(BaseSource):
try:
zone.add_record(record, lenient=lenient)
except DuplicateRecordException:
self.log.warn('Duplicate PTR record for {}, '
'skipping'.format(addr))
self.log.warn(f'Duplicate PTR record for {addr}, skipping')
class TinyDnsFileSource(TinyDnsBaseSource):
@@ -236,7 +235,7 @@ class TinyDnsFileSource(TinyDnsBaseSource):
NOTE: timestamps & lo fields are ignored if present.
'''
def __init__(self, id, directory, default_ttl=3600):
self.log = logging.getLogger('TinyDnsFileSource[{}]'.format(id))
self.log = logging.getLogger(f'TinyDnsFileSource[{id}]')
self.log.debug('__init__: id=%s, directory=%s, default_ttl=%d', id,
directory, default_ttl)
super(TinyDnsFileSource, self).__init__(id, default_ttl)