summaryrefslogtreecommitdiff
path: root/admin/gettlds.py
blob: 4b0c40339ce475127a429861ebd5ca977a59ad03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Fetch the current TLD list from the IANA Web site, parse it, and print
an expression suitable for direct insertion into each library's trust
root validation module

Usage:
  python gettlds.py (php|python|ruby)

Then cut-n-paste.
"""
from __future__ import unicode_literals

import sys
import urllib2

langs = {
    'php': (r"'/\.(",
            "'", "|", "|' .",
            r")\.?$/'"),
    'python': ("['",
               "'", "', '", "',",
               "']"),
    'ruby': ("%w'",
             "", " ", "",
             "'"),
}

lang = sys.argv[1]
prefix, line_prefix, separator, line_suffix, suffix = langs[lang]

f = urllib2.urlopen('http://data.iana.org/TLD/tlds-alpha-by-domain.txt')
tlds = []
output_line = ""
for input_line in f:
    if input_line.startswith('#'):
        continue

    tld = input_line.strip().lower()
    new_output_line = output_line + prefix + tld
    if len(new_output_line) > 60:
        print(output_line + line_suffix)
        output_line = line_prefix + tld
    else:
        output_line = new_output_line
    prefix = separator

print(output_line + suffix)