| OLD | NEW |
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present 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 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce', | 41 ESSENTIAL_BUILTINS = set(dir(builtins)) - {'apply', 'buffer', 'coerce', |
| 42 'intern', 'file'} | 42 'intern', 'file'} |
| 43 | 43 |
| 44 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break) | 44 LEAVE_BLOCK = (ast.Return, ast.Raise, ast.Continue, ast.Break) |
| 45 VOLATILE = object() | 45 VOLATILE = object() |
| 46 | 46 |
| 47 | 47 |
| 48 def evaluate(node): | 48 def evaluate(node): |
| 49 names = {'__builtins__': {'True': True, 'False': False, 'None': None}} |
| 49 try: | 50 try: |
| 50 return eval(compile(ast.Expression(node), '', 'eval'), {}) | 51 return eval(compile(ast.Expression(node), '', 'eval'), names) |
| 51 except Exception: | 52 except Exception: |
| 52 return VOLATILE | 53 return VOLATILE |
| 53 | 54 |
| 54 | 55 |
| 55 def is_const(node): | 56 def is_const(node): |
| 56 return evaluate(node) is not VOLATILE | 57 return evaluate(node) is not VOLATILE |
| 57 | 58 |
| 58 | 59 |
| 59 def get_identifier(node): | 60 def get_identifier(node): |
| 60 if isinstance(node, ast.Name): | 61 if isinstance(node, ast.Name): |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return [(pos, 'A111 redundant parenthesis for {} ' | 465 return [(pos, 'A111 redundant parenthesis for {} ' |
| 465 'statement'.format(statement))] | 466 'statement'.format(statement))] |
| 466 | 467 |
| 467 return [] | 468 return [] |
| 468 | 469 |
| 469 | 470 |
| 470 for checker in [check_ast, check_non_default_encoding, | 471 for checker in [check_ast, check_non_default_encoding, |
| 471 check_quotes, check_redundant_parenthesis]: | 472 check_quotes, check_redundant_parenthesis]: |
| 472 checker.name = 'eyeo' | 473 checker.name = 'eyeo' |
| 473 checker.version = __version__ | 474 checker.version = __version__ |
| OLD | NEW |