summaryrefslogtreecommitdiffstats
path: root/admin/gettlds.py
diff options
context:
space:
mode:
authorKevin Turner <kevin@janrain.com>2008-06-25 20:26:47 +0000
committerKevin Turner <kevin@janrain.com>2008-06-25 20:26:47 +0000
commit287cb7d61fb582e8db24bf9b94368fe7683d5113 (patch)
treeb19ba9ed45d84a58375d5300ad24a743f3dcdfc5 /admin/gettlds.py
parent609ac9e6feaabbe6ea84d0082cd9291ee18acb71 (diff)
downloadphp-openid-287cb7d61fb582e8db24bf9b94368fe7683d5113.zip
php-openid-287cb7d61fb582e8db24bf9b94368fe7683d5113.tar.gz
php-openid-287cb7d61fb582e8db24bf9b94368fe7683d5113.tar.bz2
[project @ Added a script that helps to update the valid TLD list for trust root matching]
Diffstat (limited to 'admin/gettlds.py')
-rw-r--r--admin/gettlds.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/admin/gettlds.py b/admin/gettlds.py
new file mode 100644
index 0000000..4300638
--- /dev/null
+++ b/admin/gettlds.py
@@ -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