Mercurial > dnsbl
view make-tld-conf.py @ 284:896b9393d3f0 stable-6-0-39
Fix segfault caused by freeing unallocated memory
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 31 Dec 2013 10:44:15 -0800 |
parents | 19ff60eaab74 |
children | 6497944a9bd9 |
line wrap: on
line source
#!/usr/bin/python import os, sys, time def cmd(c): return os.popen(c).read().rstrip('\n') c = 'curl http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1 2>/dev/null' content = cmd(c) f=open('tld.conf','w') f.write(time.strftime("// generated by make-tld-conf.py on %Y-%m-%d %H:%M:%S\n\n")) for x in content.split('\n'): if (x == '') or (x[:2] == '//'): f.write('%s\n' % x) else: if x[:1] == '!': x = x[1:] prefix = '!' else: prefix = '' yy = [] for xx in x.split('.'): y = unicode(xx, 'utf8') z = y.encode('punycode') if z[-1:] == '-': yy.append(xx) else: yy.append('xn--%s' % z) y = '.'.join(yy) if y == x: f.write('%s%s\n' % (prefix, x)) else: f.write('// %s%s\n' % (prefix, x)) f.write('%s%s\n' % (prefix, y)) f.close()