| OLD | NEW | 
|    1 # This file is part of the Adblock Plus web scripts, |    1 # This file is part of the Adblock Plus web scripts, | 
|    2 # Copyright (C) 2006-2016 Eyeo GmbH |    2 # Copyright (C) 2006-2016 Eyeo GmbH | 
|    3 # |    3 # | 
|    4 # Adblock Plus is free software: you can redistribute it and/or modify |    4 # Adblock Plus is free software: you can redistribute it and/or modify | 
|    5 # it under the terms of the GNU General Public License version 3 as |    5 # it under the terms of the GNU General Public License version 3 as | 
|    6 # published by the Free Software Foundation. |    6 # published by the Free Software Foundation. | 
|    7 # |    7 # | 
|    8 # Adblock Plus is distributed in the hope that it will be useful, |    8 # Adblock Plus is distributed in the hope that it will be useful, | 
|    9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |    9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|   10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |   10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|   11 # GNU General Public License for more details. |   11 # GNU General Public License for more details. | 
|   12 # |   12 # | 
|   13 # You should have received a copy of the GNU General Public License |   13 # You should have received a copy of the GNU General Public License | 
|   14 # along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. |   14 # along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
|   15  |   15  | 
|   16 import re |   16 import re | 
|   17 import hashlib |   17 import hashlib | 
|   18  |   18  | 
|   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 t
     he |   24       the period and underscore are encoded as "-12cd" where "12cd" stands for t
     he | 
|   25       hexadecimal representation of the character's ordinal. File names longer |   25       hexadecimal representation of the character's ordinal. File names longer | 
|   26       than 150 characters will be still be unique but no longer reversible due t
     o |   26       than 150 characters will be still be unique but no longer reversible due t
     o | 
|   27       file system limitations. |   27       file system limitations. | 
|   28     """ |   28     """ | 
|   29     result = re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), nam
     e) |   29     result = re.sub(r'[^\w\.]', lambda match: '-%04x' % ord(match.group(0)), nam
     e) | 
|   30     if len(result) > 150: |   30     if len(result) > 150: | 
|   31         result = result[:150] + "--%s" % hashlib.md5(result[150:]).hexdigest() |   31         result = result[:150] + '--%s' % hashlib.md5(result[150:]).hexdigest() | 
|   32     return result |   32     return result | 
|   33  |   33  | 
|   34  |   34  | 
|   35 def filename_decode(path): |   35 def filename_decode(path): | 
|   36     """ |   36     """ | 
|   37       This reconstructs a string encoded with filename_encode(). |   37       This reconstructs a string encoded with filename_encode(). | 
|   38     """ |   38     """ | 
|   39     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) | 
|   40     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) | 
|   41     return path |   41     return path | 
|   42  |   42  | 
|   43 basic_fields = [ |   43 basic_fields = [ | 
|   44     { |   44     { | 
|   45         "name": "day", |   45         'name': 'day', | 
|   46         "title": "Days of month", |   46         'title': 'Days of month', | 
|   47         "coltitle": "Day", |   47         'coltitle': 'Day', | 
|   48         "showaverage": True, |   48         'showaverage': True, | 
|   49         "defaultcount": 31, |   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     }, | 
|   60     { |   60     { | 
|   61         "name": "hour", |   61         'name': 'hour', | 
|   62         "title": "Hours of day", |   62         'title': 'Hours of day', | 
|   63         "coltitle": "Hour", |   63         'coltitle': 'Hour', | 
|   64         "showaverage": True, |   64         'showaverage': True, | 
|   65         "sort": lambda obj: sorted(obj.items(), key=lambda (k, v): int(k)), |   65         'sort': lambda obj: sorted(obj.items(), key=lambda (k, v): int(k)), | 
|   66     }, |   66     }, | 
|   67     { |   67     { | 
|   68         "name": "country", |   68         'name': 'country', | 
|   69         "title": "Countries", |   69         'title': 'Countries', | 
|   70         "coltitle": "Country", |   70         'coltitle': 'Country', | 
|   71     }, |   71     }, | 
|   72     { |   72     { | 
|   73         "name": "ua", |   73         'name': 'ua', | 
|   74         "title": "Browsers", |   74         'title': 'Browsers', | 
|   75         "coltitle": "Browser", |   75         'coltitle': 'Browser', | 
|   76     }, |   76     }, | 
|   77     { |   77     { | 
|   78         "name": "fullua", |   78         'name': 'fullua', | 
|   79         "title": "Browser versions", |   79         'title': 'Browser versions', | 
|   80         "coltitle": "Browser version", |   80         'coltitle': 'Browser version', | 
|   81     }, |   81     }, | 
|   82     { |   82     { | 
|   83         "name": "referrer", |   83         'name': 'referrer', | 
|   84         "title": "Referrers", |   84         'title': 'Referrers', | 
|   85         "coltitle": "Referrer", |   85         'coltitle': 'Referrer', | 
|   86     }, |   86     }, | 
|   87     { |   87     { | 
|   88         "name": "status", |   88         'name': 'status', | 
|   89         "title": "Status codes", |   89         'title': 'Status codes', | 
|   90         "coltitle": "Status code", |   90         'coltitle': 'Status code', | 
|   91     }, |   91     }, | 
|   92     { |   92     { | 
|   93         "name": "mirror", |   93         'name': 'mirror', | 
|   94         "title": "Download mirrors", |   94         'title': 'Download mirrors', | 
|   95         "coltitle": "Download mirror", |   95         'coltitle': 'Download mirror', | 
|   96     }, |   96     }, | 
|   97 ] |   97 ] | 
|   98  |   98  | 
|   99 downloader_fields = [ |   99 downloader_fields = [ | 
|  100     { |  100     { | 
|  101         "name": "addonName", |  101         'name': 'addonName', | 
|  102         "title": "Extensions", |  102         'title': 'Extensions', | 
|  103         "coltitle": "Extension", |  103         'coltitle': 'Extension', | 
|  104     }, |  104     }, | 
|  105     { |  105     { | 
|  106         "name": "fullAddon", |  106         'name': 'fullAddon', | 
|  107         "title": "Extension versions", |  107         'title': 'Extension versions', | 
|  108         "coltitle": "Extension version", |  108         'coltitle': 'Extension version', | 
|  109     }, |  109     }, | 
|  110     { |  110     { | 
|  111         "name": "application", |  111         'name': 'application', | 
|  112         "title": "Host applications", |  112         'title': 'Host applications', | 
|  113         "coltitle": "Host application", |  113         'coltitle': 'Host application', | 
|  114     }, |  114     }, | 
|  115     { |  115     { | 
|  116         "name": "fullApplication", |  116         'name': 'fullApplication', | 
|  117         "title": "Host application versions", |  117         'title': 'Host application versions', | 
|  118         "coltitle": "Host application version", |  118         'coltitle': 'Host application version', | 
|  119     }, |  119     }, | 
|  120     { |  120     { | 
|  121         "name": "platform", |  121         'name': 'platform', | 
|  122         "title": "Platforms", |  122         'title': 'Platforms', | 
|  123         "coltitle": "Platform", |  123         'coltitle': 'Platform', | 
|  124     }, |  124     }, | 
|  125     { |  125     { | 
|  126         "name": "fullPlatform", |  126         'name': 'fullPlatform', | 
|  127         "title": "Platform versions", |  127         'title': 'Platform versions', | 
|  128         "coltitle": "Platform version", |  128         'coltitle': 'Platform version', | 
|  129     }, |  129     }, | 
|  130     { |  130     { | 
|  131         "name": "downloadInterval", |  131         'name': 'downloadInterval', | 
|  132         "title": "Download intervals", |  132         'title': 'Download intervals', | 
|  133         "coltitle": "Download interval", |  133         'coltitle': 'Download interval', | 
|  134     }, |  134     }, | 
|  135     { |  135     { | 
|  136         "name": "previousDownload", |  136         'name': 'previousDownload', | 
|  137         "hidden": True, |  137         'hidden': True, | 
|  138     }, |  138     }, | 
|  139     { |  139     { | 
|  140         "name": "firstDownload", |  140         'name': 'firstDownload', | 
|  141         "title": "Initial download", |  141         'title': 'Initial download', | 
|  142         "filter": True, |  142         'filter': True, | 
|  143     }, |  143     }, | 
|  144     { |  144     { | 
|  145         "name": "firstInDay", |  145         'name': 'firstInDay', | 
|  146         "title": "First download this day", |  146         'title': 'First download this day', | 
|  147         "filter": True, |  147         'filter': True, | 
|  148     }, |  148     }, | 
|  149     { |  149     { | 
|  150         "name": "firstInWeek", |  150         'name': 'firstInWeek', | 
|  151         "title": "First download this week", |  151         'title': 'First download this week', | 
|  152         "filter": True, |  152         'filter': True, | 
|  153     }, |  153     }, | 
|  154     { |  154     { | 
|  155         "name": "firstInMonth", |  155         'name': 'firstInMonth', | 
|  156         "title": "First download this month", |  156         'title': 'First download this month', | 
|  157         "filter": True, |  157         'filter': True, | 
|  158     }, |  158     }, | 
|  159 ] |  159 ] | 
|  160  |  160  | 
|  161 install_fields = [ |  161 install_fields = [ | 
|  162     { |  162     { | 
|  163         "name": "installType", |  163         'name': 'installType', | 
|  164         "title": "Install types", |  164         'title': 'Install types', | 
|  165         "coltitle": "Install type", |  165         'coltitle': 'Install type', | 
|  166     }, |  166     }, | 
|  167 ] |  167 ] | 
|  168  |  168  | 
|  169  |  169  | 
|  170 fields = basic_fields + downloader_fields + install_fields |  170 fields = basic_fields + downloader_fields + install_fields | 
| OLD | NEW |