Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[project @ Added a script that helps to update the valid TLD list for…

… trust root matching]
  • Loading branch information...
commit 287cb7d61fb582e8db24bf9b94368fe7683d5113 1 parent 609ac9e
authored June 25, 2008

Showing 1 changed file with 47 additions and 0 deletions. Show diff stats Hide diff stats

  1. 47  admin/gettlds.py
47  admin/gettlds.py
... ...
@@ -0,0 +1,47 @@
  1
+"""
  2
+Fetch the current TLD list from the IANA Web site, parse it, and print
  3
+an expression suitable for direct insertion into each library's trust
  4
+root validation module
  5
+
  6
+Usage:
  7
+  python gettlds.py (php|python|ruby)
  8
+
  9
+Then cut-n-paste.
  10
+"""
  11
+
  12
+import urllib2
  13
+
  14
+import sys
  15
+
  16
+langs = {
  17
+    'php': (r"'/\.(",
  18
+            "'", "|", "|' .",
  19
+            r")\.?$/'"),
  20
+    'python': ("['",
  21
+               "'", "', '", "',",
  22
+               "']"),
  23
+    'ruby': ("%w'",
  24
+             "", " ", "",
  25
+             "'"),
  26
+    }
  27
+
  28
+lang = sys.argv[1]
  29
+prefix, line_prefix, separator, line_suffix, suffix = langs[lang]
  30
+
  31
+f = urllib2.urlopen('http://data.iana.org/TLD/tlds-alpha-by-domain.txt')
  32
+tlds = []
  33
+output_line = ""
  34
+for input_line in f:
  35
+    if input_line.startswith('#'):
  36
+        continue
  37
+
  38
+    tld = input_line.strip().lower()
  39
+    new_output_line = output_line + prefix + tld
  40
+    if len(new_output_line) > 60:
  41
+        print output_line + line_suffix
  42
+        output_line = line_prefix + tld
  43
+    else:
  44
+        output_line = new_output_line
  45
+    prefix = separator
  46
+
  47
+print output_line + suffix

0 notes on commit 287cb7d

Please sign in to comment.
Something went wrong with that request. Please try again.