diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-12-23 02:01:01 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-12-23 02:01:01 +0000 |
commit | d0047c43d955174d79a2df623dbb4007965252b5 (patch) | |
tree | 43b2b4dbffe90e2ca7b00da247c6a631484d0bde /python/google/protobuf/text_format.py | |
parent | eef5f8396dd527c17ab7e419ca8781052031d05d (diff) |
In Python, avoid relying on float('inf') and float('nan') as these don't work on Windows with Python pre-2.6.
Diffstat (limited to 'python/google/protobuf/text_format.py')
-rwxr-xr-x | python/google/protobuf/text_format.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index c5713b63..2def19c2 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -43,6 +43,12 @@ __all__ = [ 'MessageToString', 'PrintMessage', 'PrintField', 'PrintFieldValue', 'Merge' ] +# Infinity and NaN are not explicitly supported by Python pre-2.6, and +# float('inf') does not work on Windows (pre-2.6). +_INFINITY = float('1e10000') +_NAN = _INFINITY * 0 + + class ParseError(Exception): """Thrown in case of ASCII parsing error.""" @@ -478,12 +484,12 @@ class _Tokenizer(object): if re.match(self._FLOAT_INFINITY, text): self.NextToken() if text.startswith('-'): - return float('-inf') - return float('inf') + return -_INFINITY + return _INFINITY if re.match(self._FLOAT_NAN, text): self.NextToken() - return float('nan') + return _NAN try: result = float(text) |