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

Side by Side Diff: sitescripts/stats/common.py

Issue 5843385483001856: Stats processing: don`t create file names that are too long (Closed)
Patch Set: Addressed remaining nit Created Jan. 30, 2014, 1:15 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 # 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, hashlib 18 import re
19 import hashlib
19 20
20 def filename_encode(name): 21 def filename_encode(name):
21 """ 22 """
22 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
23 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,
24 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
25 hexadecimal representation of the character's ordinal. File names longer 26 hexadecimal representation of the character's ordinal. File names longer
26 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
27 file system limitations. 28 file system limitations.
28 """ 29 """
29 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)
30 if len(result) > 150: 31 if len(result) > 150:
31 hash = hashlib.md5() 32 result = result[:150] + "--%s" % hashlib.md5(result[150:]).hexdigest()
32 hash.update(result[150:])
33 result = result[:150] + "--%s" % hash.hexdigest()
34 return result 33 return result
35 34
36 def filename_decode(path): 35 def filename_decode(path):
37 """ 36 """
38 This reconstructs a string encoded with filename_encode(). 37 This reconstructs a string encoded with filename_encode().
39 """ 38 """
40 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)
41 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)
42 return path 41 return path
43 42
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 install_fields = [ 151 install_fields = [
153 { 152 {
154 "name": "installType", 153 "name": "installType",
155 "title": "Install types", 154 "title": "Install types",
156 "coltitle": "Install type", 155 "coltitle": "Install type",
157 }, 156 },
158 ] 157 ]
159 158
160 159
161 fields = basic_fields + downloader_fields + install_fields 160 fields = basic_fields + downloader_fields + install_fields
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