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

Delta Between Two Patch Sets: sitescripts/stats/common.py

Issue 5843385483001856: Stats processing: don`t create file names that are too long (Closed)
Left Patch Set: Decreased length limit Created Dec. 27, 2013, 7:50 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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:])
Sebastian Noack 2013/12/27 13:49:58 You can pass the data directly to the md5() constr
Wladimir Palant 2013/12/28 16:58:14 CRC checksums aren't meant to be unique, they shou
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
44 basic_fields = [ 43 basic_fields = [
45 { 44 {
46 "name": "day", 45 "name": "day",
47 "title": "Days of month", 46 "title": "Days of month",
48 "coltitle": "Day", 47 "coltitle": "Day",
49 "showaverage": True, 48 "showaverage": True,
49 "defaultcount": 31,
50 "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)),
51 }, 51 },
52 { 52 {
53 "name": "weekday", 53 "name": "weekday",
54 "title": "Days of week", 54 "title": "Days of week",
55 "coltitle": "Weekday", 55 "coltitle": "Weekday",
56 "showaverage": True, 56 "showaverage": True,
57 "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)), 57 "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)),
58 "isspecial": lambda weekday: weekday == 5 or weekday == 6, 58 "isspecial": lambda weekday: weekday == 5 or weekday == 6,
59 }, 59 },
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 install_fields = [ 151 install_fields = [
152 { 152 {
153 "name": "installType", 153 "name": "installType",
154 "title": "Install types", 154 "title": "Install types",
155 "coltitle": "Install type", 155 "coltitle": "Install type",
156 }, 156 },
157 ] 157 ]
158 158
159 159
160 fields = basic_fields + downloader_fields + install_fields 160 fields = basic_fields + downloader_fields + install_fields
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld