| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 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.rstrip() |
| 40 if line.startswith("//") or "." not in line: | 40 if line.startswith('//') or '.' not in line: |
| 41 continue | 41 continue |
| 42 if line.startswith('*.'): | 42 if line.startswith('*.'): |
| 43 suffixes[line[2:]] = 2 | 43 suffixes[line[2:]] = 2 |
| 44 elif line.startswith('!'): | 44 elif line.startswith('!'): |
| 45 suffixes[line[1:]] = 0 | 45 suffixes[line[1:]] = 0 |
| 46 else: | 46 else: |
| 47 suffixes[line] = 1 | 47 suffixes[line] = 1 |
| 48 | 48 |
| 49 return suffixes | 49 return suffixes |
| 50 | 50 |
| 51 | 51 |
| 52 def updatePSL(baseDir): | 52 def updatePSL(baseDir): |
| 53 """ | 53 """ |
| 54 writes the current public suffix list to js file in json format | 54 writes the current public suffix list to js file in json format |
| 55 """ | 55 """ |
| 56 | 56 |
| 57 psl = getPublicSuffixList() | 57 psl = getPublicSuffixList() |
| 58 file = open(os.path.join(baseDir, 'lib', 'publicSuffixList.js'), 'w') | 58 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=(',', ': ')) + ';' | 59 print >>file, 'var publicSuffixes = ' + json.dumps(psl, sort_keys=True, inde
nt=4, separators=(',', ': ')) + ';' |
| 60 file.close() | 60 file.close() |
| OLD | NEW |