[maemo-commits] [maemo-commits] r8555 - in projects/haf/trunk/python-xml: . xml/utils xml/xpath

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Dec 1 22:07:37 EET 2006
Author: osantana
Date: 2006-12-01 22:07:19 +0200 (Fri, 01 Dec 2006)
New Revision: 8555

Added:
   projects/haf/trunk/python-xml/xml/utils/boolean.py
Modified:
   projects/haf/trunk/python-xml/setup.py
   projects/haf/trunk/python-xml/xml/xpath/BuiltInExtFunctions.py
   projects/haf/trunk/python-xml/xml/xpath/Conversions.py
   projects/haf/trunk/python-xml/xml/xpath/CoreFunctions.py
   projects/haf/trunk/python-xml/xml/xpath/ParsedExpr.py
Log:
replace boolean C extension to the Python native booleans

Modified: projects/haf/trunk/python-xml/setup.py
===================================================================
--- projects/haf/trunk/python-xml/setup.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/setup.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -147,11 +147,11 @@
               ))
 
 # Build boolean
-ext_modules.append(
-    Extension(xml('.utils.boolean'),
-              extra_link_args=LDFLAGS,
-              sources=['extensions/boolean.c'],
-              ))
+#ext_modules.append(
+#    Extension(xml('.utils.boolean'),
+#              extra_link_args=LDFLAGS,
+#              sources=['extensions/boolean.c'],
+#              ))
 
 
 # On Windows, install the documentation into a directory xmldoc, along

Added: projects/haf/trunk/python-xml/xml/utils/boolean.py
===================================================================
--- projects/haf/trunk/python-xml/xml/utils/boolean.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/xml/utils/boolean.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -0,0 +1,14 @@
+
+true = True
+false = False
+
+BooleanType = bool
+
+def BooleanValue(obj, func):
+    if isinstance(obj, bool):
+        return obj
+    if isinstance(obj, basestring):
+        return bool(func(obj))
+    return bool(obj)
+
+IsBooleanType = lambda obj: isinstance(obj, bool)

Modified: projects/haf/trunk/python-xml/xml/xpath/BuiltInExtFunctions.py
===================================================================
--- projects/haf/trunk/python-xml/xml/xpath/BuiltInExtFunctions.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/xml/xpath/BuiltInExtFunctions.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -14,7 +14,6 @@
 import sys, re, string, urllib
 from xml.dom import Node, EMPTY_NAMESPACE
 from xml.dom.Text import Text
-from xml.utils import boolean
 from xml.xpath import CoreFunctions, Conversions, FT_EXT_NAMESPACE, FT_OLD_EXT_NAMESPACE
 
 def Version(context):
@@ -41,7 +40,7 @@
     if not arg:
         arg = context.node
     arg = Conversions.StringValue(arg)
-    bool = re.match(pattern, arg) and boolean.true or boolean.false
+    bool = re.match(pattern, arg) and True or False
     return bool
 
 

Modified: projects/haf/trunk/python-xml/xml/xpath/Conversions.py
===================================================================
--- projects/haf/trunk/python-xml/xml/xpath/Conversions.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/xml/xpath/Conversions.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -19,7 +19,6 @@
 from xml.xpath import NaN, Inf
 from xml.xpath import Util
 from xml.xpath import NAMESPACE_NODE
-from xml.utils import boolean
 
 import types
 try:
@@ -91,7 +90,7 @@
     """Get the number value of any object"""
     if type(object) in [type(1), type(2.3), type(4L)]:
         return 1, object
-    elif boolean.IsBooleanType(object):
+    elif isinstance(object, bool):
         return 1, int(object)
     #FIXME: This can probably be optimized
     object = StringValue(object)
@@ -107,7 +106,7 @@
     return 1, object
 
 
-CoreBooleanValue = lambda obj: (1, boolean.BooleanValue(obj, StringValue))
+CoreBooleanValue = lambda obj: (1, bool(StringValue(obj)))
 
 g_stringConversions = [CoreStringValue]
 g_numberConversions = [CoreNumberValue]
@@ -153,7 +152,7 @@
     types.IntType : str,
     types.LongType : lambda l: repr(l)[:-1],
     types.FloatType : lambda f: f is NaN and 'NaN' or '%g' % f,
-    boolean.BooleanType : str,
+    bool : str,
     types.InstanceType : _strInstance,
     types.ListType : lambda x: x and _strConversions.get(type(x[0]), _strUnknown)(x[0]) or '',
 }

Modified: projects/haf/trunk/python-xml/xml/xpath/CoreFunctions.py
===================================================================
--- projects/haf/trunk/python-xml/xml/xpath/CoreFunctions.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/xml/xpath/CoreFunctions.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -20,7 +20,6 @@
 from xml.xpath import Util, Conversions
 from xml.xpath import NAMESPACE_NODE
 from xml.xpath import CompiletimeException, RuntimeException
-from xml.utils import boolean
 
 from xml.FtCore import get_translator
 
@@ -154,7 +153,7 @@
     """Function: <string> starts-with(<string>, <string>)"""
     outer = Conversions.StringValue(outer)
     inner = Conversions.StringValue(inner)
-    return outer[:len(inner)] == inner and boolean.true or boolean.false
+    return outer[:len(inner)] == inner and True or False
 
 
 def Contains(context, outer, inner):
@@ -162,9 +161,9 @@
     outer = Conversions.StringValue(outer)
     inner = Conversions.StringValue(inner)
     if len(inner) == 1:
-        return inner in outer and boolean.true or boolean.false
+        return inner in outer and True or False
     else:
-        return string.find(outer, inner) != -1 and boolean.true or boolean.false
+        return string.find(outer, inner) != -1 and True or False
 
 
 def SubstringBefore(context, outer, inner):
@@ -245,17 +244,17 @@
 
 def Not(context, object):
     """Function: <boolean> not(<boolean>)"""
-    return (not Conversions.BooleanValue(object) and boolean.true) or boolean.false
+    return (not Conversions.BooleanValue(object) and True) or False
 
 
-def True(context):
+def True_(context):
     """Function: <boolean> true()"""
-    return boolean.true
+    return True
 
 
-def False(context):
+def False_(context):
     """Function: <boolean> false()"""
-    return boolean.false
+    return False
 
 
 def Lang(context, lang):
@@ -271,9 +270,9 @@
             if index != -1:
                 value = value[:index]
             value = string.upper(value)
-            return value == lang and boolean.true or boolean.false
+            return value == lang and True or False
         node = node.nodeType == Node.ATTRIBUTE_NODE and node.ownerElement or node.parentNode
-    return boolean.false
+    return False
 
 ### Number Functions ###
 
@@ -352,8 +351,8 @@
     (EMPTY_NAMESPACE, 'translate'): Translate,
     (EMPTY_NAMESPACE, 'boolean'): _Boolean,
     (EMPTY_NAMESPACE, 'not'): Not,
-    (EMPTY_NAMESPACE, 'true'): True,
-    (EMPTY_NAMESPACE, 'false'): False,
+    (EMPTY_NAMESPACE, 'true'): True_,
+    (EMPTY_NAMESPACE, 'false'): False_,
     (EMPTY_NAMESPACE, 'lang'): Lang,
     (EMPTY_NAMESPACE, 'number'): Number,
     (EMPTY_NAMESPACE, 'sum'): Sum,

Modified: projects/haf/trunk/python-xml/xml/xpath/ParsedExpr.py
===================================================================
--- projects/haf/trunk/python-xml/xml/xpath/ParsedExpr.py	2006-12-01 16:59:27 UTC (rev 8554)
+++ projects/haf/trunk/python-xml/xml/xpath/ParsedExpr.py	2006-12-01 20:07:19 UTC (rev 8555)
@@ -22,7 +22,6 @@
 from xml.xpath import Util
 from xml.xpath import ParsedStep
 from xml.xpath import ParsedAxisSpecifier
-from xml.utils import boolean
 import Set
 
 class NodeSet(UserList.UserList):
@@ -437,11 +436,11 @@
 
     def evaluate(self, context):
         if self._op == '=':
-            true = boolean.true
-            false = boolean.false
+            true = True
+            false = False
         else:
-            true = boolean.false
-            false = boolean.true
+            true = False
+            false = True
 
         lrt = self._left.evaluate(context)
         rrt = self._right.evaluate(context)
@@ -465,7 +464,7 @@
                 val = lrt
             if type(val) in NumberTypes:
                 func = Conversions.NumberValue
-            elif boolean.IsBooleanType(val):
+            elif isinstance(val,bool):
                 func = Conversions.BooleanValue
             elif type(val) == types.StringType:
                 func = Conversions.StringValue
@@ -478,7 +477,7 @@
                     return true
             return false
 
-        if boolean.IsBooleanType(lrt) or boolean.IsBooleanType(rrt):
+        if isinstance(lrt, bool) or isinstance(rrt, bool):
             rt = Conversions.BooleanValue(lrt) == Conversions.BooleanValue(rrt)
         elif lType in NumberTypes or rType in NumberTypes:
             rt = Conversions.NumberValue(lrt) == Conversions.NumberValue(rrt)
@@ -543,7 +542,7 @@
             rt = (lrt > rrt)
         elif self._op == 3:
             rt = (lrt >= rrt)
-        return rt and boolean.true or boolean.false
+        return rt and True or False
 
     def pprint(self, indent=''):
         print indent + str(self)


More information about the maemo-commits mailing list