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 | """ |
---|
4 | Use to update official_top_level_domains in gluon/validators.py |
---|
5 | """ |
---|
6 | |
---|
7 | import itertools |
---|
8 | import operator |
---|
9 | import urllib2 |
---|
10 | |
---|
11 | LIMIT = 70 |
---|
12 | PREFIX = ' ' |
---|
13 | TLDS_URL = 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt' |
---|
14 | |
---|
15 | resp = urllib2.urlopen(TLDS_URL) |
---|
16 | content = resp.read() |
---|
17 | |
---|
18 | valid_lines = [a.strip().lower() for a in content.split('\n') if a.strip() and a.strip()[0] != '#'] |
---|
19 | valid_lines += ['localhost'] |
---|
20 | |
---|
21 | print 'Fetched TLDs are %s' % len(valid_lines) |
---|
22 | |
---|
23 | results = [list(g) for k, g in itertools.groupby(sorted(valid_lines), key=operator.itemgetter(0))] |
---|
24 | |
---|
25 | output = [] |
---|
26 | line = "'%s', " |
---|
27 | |
---|
28 | for 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 | |
---|
41 | print '[\n' + '\n'.join(output)[:-1] + '\n]' |
---|
Note: See
TracBrowser
for help on using the repository browser.