Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: publicSuffixListUpdater.py

Issue 29793567: Issue 6706 - Make "build.py updatepsl" encode domains as Punycode (Closed)
Patch Set: Created May 29, 2018, 3:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 """ 5 """
6 Update the public suffix list 6 Update the public suffix list
7 ============================== 7 ==============================
8 8
9 This script generates a js array of public suffixes (http://publicsuffix.org/) 9 This script generates a js array of public suffixes (http://publicsuffix.org/)
10 """ 10 """
(...skipping 18 matching lines...) Expand all
29 29
30 def getPublicSuffixList(): 30 def getPublicSuffixList():
31 """ 31 """
32 gets download link for a Gecko add-on from the Mozilla Addons site 32 gets download link for a Gecko add-on from the Mozilla Addons site
33 """ 33 """
34 suffixes = {} 34 suffixes = {}
35 url = 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_t ld_names.dat?raw=1' 35 url = 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_t ld_names.dat?raw=1'
36 resource = urlopen(url) 36 resource = urlopen(url)
37 37
38 for line in resource: 38 for line in resource:
39 line = line.rstrip() 39 line = line.decode('utf-8').rstrip()
40 if line.startswith('//') or '.' not in line: 40 if line.startswith('//') or '.' not in line:
41 continue 41 continue
42
42 if line.startswith('*.'): 43 if line.startswith('*.'):
43 suffixes[line[2:]] = 2 44 offset = 2
45 val = 2
44 elif line.startswith('!'): 46 elif line.startswith('!'):
45 suffixes[line[1:]] = 0 47 offset = 1
48 val = 0
46 else: 49 else:
47 suffixes[line] = 1 50 offset = 0
51 val = 1
52
53 suffixes[line[offset:].encode('idna').decode('ascii')] = val
48 54
49 return suffixes 55 return suffixes
50 56
51 57
52 def updatePSL(baseDir): 58 def updatePSL(baseDir):
53 """ 59 """
54 writes the current public suffix list to js file in json format 60 writes the current public suffix list to js file in json format
55 """ 61 """
56 62
57 psl = getPublicSuffixList() 63 psl = getPublicSuffixList()
58 file = open(os.path.join(baseDir, 'lib', 'publicSuffixList.js'), 'w') 64 file = open(os.path.join(baseDir, 'lib', 'publicSuffixList.js'), 'w')
59 print >>file, 'var publicSuffixes = ' + json.dumps(psl, sort_keys=True, inde nt=4, separators=(',', ': ')) + ';' 65 print >>file, 'var publicSuffixes = ' + json.dumps(psl, sort_keys=True, inde nt=4, separators=(',', ': ')) + ';'
60 file.close() 66 file.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld