Ensure wrappers function name are set with a non-unicode string.
authorFrederic Jolliton <frederic@jolliton.com>
Wed, 7 Sep 2005 23:25:14 +0000 (23:25 +0000)
committerFrederic Jolliton <frederic@jolliton.com>
Wed, 7 Sep 2005 23:25:14 +0000 (23:25 +0000)
git-archimport-id: frederic@jolliton.com--2005-main/tx--main--0.1--patch-12

xpath.py

index 04a32d6..8a53b79 100644 (file)
--- a/xpath.py
+++ b/xpath.py
@@ -162,6 +162,15 @@ def unionOfSequences( sequences ) :
 
 #----------------------------------------------------------------------------
 
+def ensureString( s ) :
+
+       if isinstance( s , str ) :
+               return s
+       elif isinstance( s , unicode ) :
+               return s.encode( 'ascii' , 'ignore' )
+       else :
+               return str( s )
+
 def ensureCallable( e ) :
 
        if not callable( e ) :
@@ -378,7 +387,7 @@ def makeVariableReference( name ) :
        '''
        def fun( context ) :
                return Sequence( context.getVariable( name ) )
-       fun.__name__ = '_var_%s_' % name
+       fun.__name__ = '_var_%s_' % ensureString( name )
 
        return fun
 
@@ -411,7 +420,7 @@ def makeFunctionCall( expr ) :
                def fun( context ) :
                        args = map( lambda f : f( context ) , fargs )
                        return fn( context , *args )
-               fun.__name__ = '_fn_%s_' % functionName
+               fun.__name__ = '_fn_%s_' % ensureString( functionName )
        else :
                #
                # Unknown function. Resolution at run-time
@@ -423,7 +432,7 @@ def makeFunctionCall( expr ) :
                        assertFunctionArity( fn , functionName , len( fargs ) , 1 )
                        args = map( lambda f : f( context ) , fargs )
                        return fn( context , *args )
-               fun.__name__ = '_fn[rt]_%s_' % functionName
+               fun.__name__ = '_fn[rt]_%s_' % ensureString( functionName )
        return fun
 
 def makeFilter( exprlist , predicates ) :
@@ -682,7 +691,7 @@ def makeUnary( opName , arg ) :
                arg = ensureCallable( arg )
                def fun( context ) :
                        return op( context , arg( context ) )
-               fun.__name__ = '_op1_%s_' % opName
+               fun.__name__ = '_op1_%s_' % ensureString( opName )
                return fun
 
 def makeBinary( opName , arg1 , arg2 ) :
@@ -706,7 +715,7 @@ def makeBinary( opName , arg1 , arg2 ) :
                else :
                        def fun( context ) :
                                return op( context , arg1( context ) , arg2( context ) )
-               fun.__name__ = '_op2_%s_' % opName
+               fun.__name__ = '_op2_%s_' % ensureString( opName )
                return fun
 
 def makeFor( clauses , returnExpr ) :