summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/pyprov/pythonscript.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
index ef131b3c1dab..5844ebe8912c 100644
--- a/scripting/source/pyprov/pythonscript.py
+++ b/scripting/source/pyprov/pythonscript.py
@@ -743,7 +743,7 @@ class DummyProgressHandler( unohelper.Base, XProgressHandler ):
def push( self,status ):
log.debug( "pythonscript: DummyProgressHandler.push " + str( status ) )
- def update( self,status ):
+ def update( self,status ):
log.debug( "pythonscript: DummyProgressHandler.update " + str( status ) )
def pop( self, event ):
log.debug( "pythonscript: DummyProgressHandler.push " + str( event ) )
@@ -866,12 +866,18 @@ class PackageBrowseNode( unohelper.Base, XBrowseNode ):
class PythonScript( unohelper.Base, XScript ):
- def __init__( self, func, mod ):
+ def __init__( self, func, mod, args ):
self.func = func
self.mod = mod
+ if (args != '' and args is not None):
+ self.args = tuple([x.strip() for x in args.split(",")])
+ else:
+ self.args = None
def invoke(self, args, out, outindex ):
log.debug( "PythonScript.invoke " + str( args ) )
try:
+ if (self.args):
+ args += self.args
ret = self.func( *args )
except UnoException as e:
# UNO Exception continue to fly ...
@@ -883,7 +889,7 @@ class PythonScript( unohelper.Base, XScript ):
# some people may beat me up for modifying the exception text,
# but otherwise office just shows
# the type name and message text with no more information,
- # this is really bad for most users.
+ # this is really bad for most users.
e.Message = e.Message + " (" + complete + ")"
raise
except Exception as e:
@@ -980,6 +986,21 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
def getType( self ):
return self.dirBrowseNode.getType()
+ # retrieve function args in parenthesis
+ def getFunctionArguments(self, func_signature):
+ nOpenParenthesis = func_signature.find( "(")
+ if -1 == nOpenParenthesis:
+ function_name = func_signature
+ arguments = ''
+ else:
+ function_name = func_signature[0:nOpenParenthesis]
+ leading = func_signature[nOpenParenthesis+1:len(func_signature)]
+ nCloseParenthesis = leading.find( ")")
+ if -1 == nCloseParenthesis:
+ raise IllegalArgumentException( "PythonLoader: mismatch parenthesis " + func_signature, self, 0 )
+ arguments = leading[0:nCloseParenthesis]
+ return function_name, arguments
+
def getScript( self, scriptUri ):
try:
log.debug( "getScript " + scriptUri + " invoked")
@@ -990,13 +1011,18 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
fileUri = storageUri[0:storageUri.find( "$" )]
funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)]
+ # retrieve arguments in parenthesis
+ funcName, funcArgs = self.getFunctionArguments(funcName)
+ log.debug( " getScript : parsed funcname " + str(funcName) )
+ log.debug( " getScript : func args " + str(funcArgs) )
+
mod = self.provCtx.getModuleByUrl( fileUri )
log.debug( " got mod " + str(mod) )
func = mod.__dict__[ funcName ]
log.debug( "got func " + str( func ) )
- return PythonScript( func, mod )
+ return PythonScript( func, mod, funcArgs )
except:
text = lastException2String()
log.error( text )