forked from openid/python-openid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[project @ admin/gettlds.py: added script to get TLDs from IANA]
- Loading branch information
Kevin Turner
committed
Jun 25, 2008
1 parent
d0531d7
commit d054c5f
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. | ||
""" | ||
|
||
import urllib2 | ||
|
||
import sys | ||
|
||
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 |