40 |
40 |
41 @param source source code of the context (list of string or string) |
41 @param source source code of the context (list of string or string) |
42 @param startLine line number the context starts in the source (integer) |
42 @param startLine line number the context starts in the source (integer) |
43 @param contextType type of the context object (string) |
43 @param contextType type of the context object (string) |
44 """ |
44 """ |
45 if isinstance(source, str): |
45 if sys.version_info[0] == 2: |
|
46 stringTypes = (str, unicode) # __IGNORE_WARNING__ |
|
47 else: |
|
48 stringTypes = str |
|
49 if isinstance(source, stringTypes): |
46 self.__source = source.splitlines(True) |
50 self.__source = source.splitlines(True) |
47 else: |
51 else: |
48 self.__source = source[:] |
52 self.__source = source[:] |
49 self.__start = startLine |
53 self.__start = startLine |
50 self.__indent = "" |
54 self.__indent = "" |
328 |
332 |
329 if not self.__checkers: |
333 if not self.__checkers: |
330 # don't do anything, if no codes were selected |
334 # don't do anything, if no codes were selected |
331 return |
335 return |
332 |
336 |
|
337 source = "".join(self.__source) |
|
338 # Check type for py2: if not str it's unicode |
|
339 if sys.version_info[0] == 2: |
|
340 try: |
|
341 source = source.encode('utf-8') |
|
342 except UnicodeError: |
|
343 pass |
333 try: |
344 try: |
334 compile(''.join(self.__source), self.__filename, 'exec', |
345 compile(source, self.__filename, 'exec', ast.PyCF_ONLY_AST) |
335 ast.PyCF_ONLY_AST) |
|
336 except (SyntaxError, TypeError): |
346 except (SyntaxError, TypeError): |
337 self.__reportInvalidSyntax() |
347 self.__reportInvalidSyntax() |
338 return |
348 return |
339 |
349 |
340 for keyword in self.__keywords: |
350 for keyword in self.__keywords: |