OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import re | 18 import re, hashlib |
19 | 19 |
20 def filename_encode(name): | 20 def filename_encode(name): |
21 """ | 21 """ |
22 This encodes any string to a valid file name while ensuring that the | 22 This encodes any string to a valid file name while ensuring that the |
23 original string can still be reconstructed. All characters except 0-9, A-Z, | 23 original string can still be reconstructed. All characters except 0-9, A-Z, |
24 the period and underscore are encoded as "-12cd" where "12cd" stands for the | 24 the period and underscore are encoded as "-12cd" where "12cd" stands for the |
25 hexadecimal representation of the character's ordinal. | 25 hexadecimal representation of the character's ordinal. File names longer |
| 26 than 200 characters will be still be unique but no longer reversible due to |
| 27 file system limitations. |
26 """ | 28 """ |
27 return re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name) | 29 result = re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name) |
| 30 if len(result) > 200: |
| 31 hash = hashlib.md5() |
| 32 hash.update(result[200:]) |
| 33 result = result[:200] + "--%s" % hash.hexdigest() |
| 34 return result |
28 | 35 |
29 def filename_decode(path): | 36 def filename_decode(path): |
30 """ | 37 """ |
31 This reconstructs a string encoded with filename_encode(). | 38 This reconstructs a string encoded with filename_encode(). |
32 """ | 39 """ |
33 return re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16))
, path) | 40 path = re.sub(r"--[0-9A-Fa-f]{32}", u"\u2026", path) |
| 41 path = re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16))
, path) |
| 42 return path |
34 | 43 |
35 basic_fields = [ | 44 basic_fields = [ |
36 { | 45 { |
37 "name": "day", | 46 "name": "day", |
38 "title": "Days of month", | 47 "title": "Days of month", |
39 "coltitle": "Day", | 48 "coltitle": "Day", |
40 "showaverage": True, | 49 "showaverage": True, |
41 "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)), | 50 "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)), |
42 }, | 51 }, |
43 { | 52 { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 install_fields = [ | 151 install_fields = [ |
143 { | 152 { |
144 "name": "installType", | 153 "name": "installType", |
145 "title": "Install types", | 154 "title": "Install types", |
146 "coltitle": "Install type", | 155 "coltitle": "Install type", |
147 }, | 156 }, |
148 ] | 157 ] |
149 | 158 |
150 | 159 |
151 fields = basic_fields + downloader_fields + install_fields | 160 fields = basic_fields + downloader_fields + install_fields |
OLD | NEW |