source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/scripts/parse_top_level_domains.py @ 42095c5

mainqndtest v1.1.1
Last change on this file since 42095c5 was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 1020 bytes
Line 
1#!/bin/env python
2# -*- coding: utf-8 -*-
3"""
4Use to update official_top_level_domains in gluon/validators.py
5"""
6
7import itertools
8import operator
9import urllib2
10
11LIMIT = 70
12PREFIX = '    '
13TLDS_URL = 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt'
14
15resp = urllib2.urlopen(TLDS_URL)
16content = resp.read()
17
18valid_lines = [a.strip().lower() for a in content.split('\n') if a.strip() and a.strip()[0] != '#']
19valid_lines += ['localhost']
20
21print 'Fetched TLDs are %s' % len(valid_lines)
22
23results = [list(g) for k, g in itertools.groupby(sorted(valid_lines), key=operator.itemgetter(0))]
24
25output = []
26line = "'%s', "
27
28for a in results:
29    output.append('%s# %s' % (PREFIX, a[-1][0]))
30    thisline = PREFIX
31    for c in a:
32        newline = thisline + line % c
33        if len(newline) > 70:
34            output.append(thisline[:-1])
35            thisline = PREFIX + line % c
36        else:
37            thisline += line % c
38    if thisline:
39        output.append(thisline[:-1])
40
41print '[\n' + '\n'.join(output)[:-1] + '\n]'
Note: See TracBrowser for help on using the repository browser.