Spot the invalid syntax
MRAB
python at mrabarnett.plus.com
Thu Mar 8 19:04:50 EST 2018
On 2018-03-08 23:23, Ian Pilcher wrote:
> (Because I certainly can't.)
>
>> def _san_dnsname_ips(dnsname, dnsname_is_cname=False):
>> """
>> Returns a set of IP addresses, managed by this IPa instance,
>> that correspond to the DNS name (from the subjectAltName).
>>
>> """
>> fqdn = dnsutil.DNSName(dnsname).make_absolute()
>> if fqdn.__len__() < 4:
>> logger.debug("Skipping IPs for %s: hostname too short" % dnsname)
>> return ()
>> zone = dnsutil.DNSName(resolver.zone_for_name(fqdn))
>> name = fqdn.relativize(zone)
>> try:
>> result = api.Command['dnsrecord_show'](zone, name)['result']
>> except errors.NotFound as nf:
>> logger.debug("Skipping IPs for %s: %s" % (dnsname, nf))
>> return ()
>> ips = set()
>> for ip in itertools.chain(result.get('arecord', ()),
>> result.get('aaaarecord', ())):
>> if _ip_rdns_ok(ip, fqdn):
>> ips.add(ip)
>> cnames = result.get('cnamerecord', ())
>> if cnames:
>> if dnsname_is_cname:
>> logger.debug("Skipping IPs for %s: chained CNAME" % dnsname)
>> else:
>> for cname in cnames:
>> if not cname.endswith('.'):
>> cname = u'%s.%s' % (cname, zone)
>> ips.update(_san_dnsname_ips(cname, True)
>> return ips
>
> 2.7 and 3.6 are both giving me:
>
> File "/tmp/test.py", line 32
> return ips
> ^
> SyntaxError: invalid syntax
>
> I've checked for tabs and mismatched parentheses.
>
> Aargh!
>
Look closely at the preceding line. Count the parentheses.
More information about the Python-list
mailing list