227 @return dictionary with the keys 'error' and 'warnings' which |
215 @return dictionary with the keys 'error' and 'warnings' which |
228 hold a list containing details about the error/ warnings |
216 hold a list containing details about the error/ warnings |
229 (file name, line number, column, codestring (only at syntax |
217 (file name, line number, column, codestring (only at syntax |
230 errors), the message, a list with arguments for the message) |
218 errors), the message, a list with arguments for the message) |
231 """ |
219 """ |
|
220 import builtins |
|
221 |
232 try: |
222 try: |
233 import builtins |
|
234 except ImportError: |
|
235 import __builtin__ as builtins # __IGNORE_WARNING__ |
|
236 |
|
237 try: |
|
238 if sys.version_info[0] == 2: |
|
239 file_enc = filename.encode(sys.getfilesystemencoding()) |
|
240 else: |
|
241 file_enc = filename |
|
242 |
|
243 # It also encode the code back to avoid 'Encoding declaration in |
|
244 # unicode string' exception on Python2 |
|
245 codestring = normalizeCode(codestring) |
223 codestring = normalizeCode(codestring) |
246 |
224 |
247 # Check for VCS conflict markers |
225 # Check for VCS conflict markers |
248 for conflictMarkerRe in VcsConflictMarkerRegExpList: |
226 for conflictMarkerRe in VcsConflictMarkerRegExpList: |
249 conflict = conflictMarkerRe.search(codestring) |
227 conflict = conflictMarkerRe.search(codestring) |
250 if conflict is not None: |
228 if conflict is not None: |
251 start, i = conflict.span() |
229 start, i = conflict.span() |
252 lineindex = 1 + codestring.count("\n", 0, start) |
230 lineindex = 1 + codestring.count("\n", 0, start) |
253 return [{'error': |
231 return [{'error': |
254 (file_enc, lineindex, 0, "", |
232 (filename, lineindex, 0, "", |
255 "VCS conflict marker found") |
233 "VCS conflict marker found") |
256 }] |
234 }] |
257 |
235 |
258 if filename.endswith('.ptl'): |
236 if filename.endswith('.ptl'): |
259 try: |
237 try: |
260 import quixote.ptl_compile |
238 import quixote.ptl_compile |
261 except ImportError: |
239 except ImportError: |
262 return [{'error': (filename, 0, 0, '', |
240 return [{'error': (filename, 0, 0, '', |
263 'Quixote plugin not found.')}] |
241 'Quixote plugin not found.')}] |
264 template = quixote.ptl_compile.Template(codestring, file_enc) |
242 template = quixote.ptl_compile.Template(codestring, filename) |
265 template.compile() |
243 template.compile() |
266 else: |
244 else: |
267 module = builtins.compile( |
245 module = builtins.compile( |
268 codestring, file_enc, 'exec', ast.PyCF_ONLY_AST) |
246 codestring, filename, 'exec', ast.PyCF_ONLY_AST) |
269 except SyntaxError as detail: |
247 except SyntaxError as detail: |
270 index = 0 |
248 index = 0 |
271 code = "" |
249 code = "" |
272 error = "" |
250 error = "" |
273 lines = traceback.format_exception_only(SyntaxError, detail) |
251 lines = traceback.format_exception_only(SyntaxError, detail) |
274 if sys.version_info[0] == 2: |
|
275 lines = [x.decode(sys.getfilesystemencoding()) for x in lines] |
|
276 match = re.match(r'\s*File "(.+)", line (\d+)', |
252 match = re.match(r'\s*File "(.+)", line (\d+)', |
277 lines[0].replace('<string>', filename)) |
253 lines[0].replace('<string>', filename)) |
278 if match is not None: |
254 if match is not None: |
279 fn, line = match.group(1, 2) |
255 fn, line = match.group(1, 2) |
280 if lines[1].startswith('SyntaxError:'): |
256 if lines[1].startswith('SyntaxError:'): |