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

Side by Side Diff: sitescripts/reports/bin/parseNewReports.py

Issue 29350318: Issue 4382 - Use new syntax to catch exceptions in sitescripts (Closed)
Patch Set: Created Aug. 30, 2016, 1:28 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 | « sitescripts/extensions/utils.py ('k') | sitescripts/reports/web/submitReport.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 source = open(xmlFile, 'rb') 81 source = open(xmlFile, 'rb')
82 reportData = {'status': '', 'usefulness': 0, 'warnings': {}, 'requests': [], 'filters': [], 'subscriptions': [], 'extensions': [], 'errors': [], 'time': tim e()} 82 reportData = {'status': '', 'usefulness': 0, 'warnings': {}, 'requests': [], 'filters': [], 'subscriptions': [], 'extensions': [], 'errors': [], 'time': tim e()}
83 tagStack = [] 83 tagStack = []
84 84
85 parser = ParserCreate() 85 parser = ParserCreate()
86 parser.StartElementHandler = processElementStart 86 parser.StartElementHandler = processElementStart
87 parser.EndElementHandler = processElementEnd 87 parser.EndElementHandler = processElementEnd
88 parser.CharacterDataHandler = processText 88 parser.CharacterDataHandler = processText
89 try: 89 try:
90 parser.ParseFile(source) 90 parser.ParseFile(source)
91 except ExpatError, error: 91 except ExpatError as error:
92 reportData['warnings']['!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (ErrorString(error.code), error.lineno, error.offset) 92 reportData['warnings']['!parsing'] = 'Parsing error in the report: %s at line %i column %i' % (ErrorString(error.code), error.lineno, error.offset)
93 93
94 source.seek(0) 94 source.seek(0)
95 reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US') 95 reportData['knownIssues'] = knownIssuesParser.findMatches(source, 'en-US')
96 source.close() 96 source.close()
97 97
98 if 'screenshot' in reportData and not reportData['screenshot'].startswith('d ata:image/'): 98 if 'screenshot' in reportData and not reportData['screenshot'].startswith('d ata:image/'):
99 del reportData['screenshot'] 99 del reportData['screenshot']
100 if 'email' in reportData and reportData['email'].find(' at ') < 0 and report Data['email'].find('@') < 0: 100 if 'email' in reportData and reportData['email'].find(' at ') < 0 and report Data['email'].find('@') < 0:
101 del reportData['email'] 101 del reportData['email']
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 reportData['warnings'][itemPath] = 'Field %s exceeded le ngth limit and was truncated' % itemPath 279 reportData['warnings'][itemPath] = 'Field %s exceeded le ngth limit and was truncated' % itemPath
280 elif isinstance(data[key], basestring): 280 elif isinstance(data[key], basestring):
281 limit = lengthRestrictions.get(keyPath, lengthRestrictions['default_ string']) 281 limit = lengthRestrictions.get(keyPath, lengthRestrictions['default_ string'])
282 if len(data[key]) > limit: 282 if len(data[key]) > limit:
283 data[key] = data[key][0:limit] + u'\u2026' 283 data[key] = data[key][0:limit] + u'\u2026'
284 reportData['warnings'][keyPath] = 'Field %s exceeded length limi t and was truncated' % keyPath 284 reportData['warnings'][keyPath] = 'Field %s exceeded length limi t and was truncated' % keyPath
285 285
286 if __name__ == '__main__': 286 if __name__ == '__main__':
287 setupStderr() 287 setupStderr()
288 scanReports(get_config().get('reports', 'dataPath')) 288 scanReports(get_config().get('reports', 'dataPath'))
OLDNEW
« no previous file with comments | « sitescripts/extensions/utils.py ('k') | sitescripts/reports/web/submitReport.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld