瀏覽代碼

Python <=2.5 compatibility: float('inf')

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@43167 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 14 年之前
父節點
當前提交
6845bcfc28
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      lib/python/ctypes/ctypesgencore/expressions.py

+ 10 - 3
lib/python/ctypes/ctypesgencore/expressions.py

@@ -68,10 +68,17 @@ class ConstantExpressionNode(ExpressionNode):
     def evaluate(self, context):
         return self.value
 
+    try:
+        pos_inf = float('inf')
+        neg_inf = float('-inf')
+    except ValueError:
+        pos_inf = ()
+        neg_inf = ()
+
     def py_string(self, can_be_ctype):
-        if self.value == float('inf'):
+        if self.value == ConstantExpressionNode.pos_inf:
             return "float('inf')"
-        elif self.value == float('-inf'):
+        elif self.value == ConstantExpressionNode.neg_inf:
             return "float('-inf')"
         return repr(self.value)
 
@@ -302,4 +309,4 @@ class UnsupportedExpressionNode(ExpressionNode):
     
     def py_string(self, can_be_ctype):
         raise ValueError, "Called py_string() an unsupported expression " \
-            "node: %s" % self.message
+            "node: %s" % self.message