diff options
author | David Beazley <dave@dabeaz.com> | 2016-08-30 15:41:28 -0500 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2016-08-30 15:41:28 -0500 |
commit | 1000526c6d5176ac0c6867d53160b33cb1e070b1 (patch) | |
tree | 7a0709ace0e367474db64a924b54330159aafc97 /ply | |
parent | 5ccbfc7e70392a18fb5defa57e3e18fa477c03e6 (diff) | |
download | ply-1000526c6d5176ac0c6867d53160b33cb1e070b1.tar.gz |
cleanup
Diffstat (limited to 'ply')
-rw-r--r-- | ply/cpp.py | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -9,6 +9,15 @@ # ----------------------------------------------------------------------------- from __future__ import generators +import sys + +# Some Python 3 compatibility shims +if sys.version_info.major < 3: + STRING_TYPES = (str, unicode) +else: + STRING_TYPES = str + xrange = range + # ----------------------------------------------------------------------------- # Default preprocessor lexer definitions. These tokens are enough to get # a basic preprocessor working. Other modules may import these if they want @@ -590,7 +599,7 @@ class Preprocessor(object): expr = expr.replace("!"," not ") try: result = eval(expr) - except StandardError: + except Exception: self.error(self.source,tokens[0].lineno,"Couldn't evaluate expression") result = 0 return result @@ -781,7 +790,7 @@ class Preprocessor(object): # ---------------------------------------------------------------------- def define(self,tokens): - if isinstance(tokens,(str,unicode)): + if isinstance(tokens,STRING_TYPES): tokens = self.tokenize(tokens) linetok = tokens |