LEFT | RIGHT |
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, |
(...skipping 11 matching lines...) Expand all Loading... |
22 """ | 22 """ |
23 This encodes any string to a valid file name while ensuring that the | 23 This encodes any string to a valid file name while ensuring that the |
24 original string can still be reconstructed. All characters except 0-9, A-Z, | 24 original string can still be reconstructed. All characters except 0-9, A-Z, |
25 the period and underscore are encoded as "-12cd" where "12cd" stands for the | 25 the period and underscore are encoded as "-12cd" where "12cd" stands for the |
26 hexadecimal representation of the character's ordinal. File names longer | 26 hexadecimal representation of the character's ordinal. File names longer |
27 than 150 characters will be still be unique but no longer reversible due to | 27 than 150 characters will be still be unique but no longer reversible due to |
28 file system limitations. | 28 file system limitations. |
29 """ | 29 """ |
30 result = re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name) | 30 result = re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name) |
31 if len(result) > 150: | 31 if len(result) > 150: |
32 hash = hashlib.md5() | 32 result = result[:150] + "--%s" % hashlib.md5(result[150:]).hexdigest() |
33 hash.update(result[150:]) | |
34 result = result[:150] + "--%s" % hash.hexdigest() | |
35 return result | 33 return result |
36 | 34 |
37 def filename_decode(path): | 35 def filename_decode(path): |
38 """ | 36 """ |
39 This reconstructs a string encoded with filename_encode(). | 37 This reconstructs a string encoded with filename_encode(). |
40 """ | 38 """ |
41 path = re.sub(r"--[0-9A-Fa-f]{32}", u"\u2026", path) | 39 path = re.sub(r"--[0-9A-Fa-f]{32}", u"\u2026", path) |
42 path = re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16))
, path) | 40 path = re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16))
, path) |
43 return path | 41 return path |
44 | 42 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 install_fields = [ | 151 install_fields = [ |
154 { | 152 { |
155 "name": "installType", | 153 "name": "installType", |
156 "title": "Install types", | 154 "title": "Install types", |
157 "coltitle": "Install type", | 155 "coltitle": "Install type", |
158 }, | 156 }, |
159 ] | 157 ] |
160 | 158 |
161 | 159 |
162 fields = basic_fields + downloader_fields + install_fields | 160 fields = basic_fields + downloader_fields + install_fields |
LEFT | RIGHT |