diff options
author | Laurent Godard <laurent.godard@cncc.fr> | 2018-04-25 15:49:21 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-04-27 09:09:13 +0200 |
commit | 3d97c9d292d80cb82391bdb416a9c6217a8e16e4 (patch) | |
tree | ee59df17f6f24ab6d1ee93946f13129b75e449c8 /scripting | |
parent | 225e28d7ee8f31a49712c4e0f7d36b7cf7524246 (diff) |
tdf#117202 more pythonic and allow spaces as argument
space argument must be encapsulated in double-quotes
that will be stripped
Change-Id: I0387cc7f3fcb4cc48c5a94afcd481306bb4644e2
Reviewed-on: https://gerrit.libreoffice.org/53453
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/source/pyprov/pythonscript.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py index 5844ebe8912c..b1ef0aa7e324 100644 --- a/scripting/source/pyprov/pythonscript.py +++ b/scripting/source/pyprov/pythonscript.py @@ -869,10 +869,8 @@ class PythonScript( unohelper.Base, XScript ): 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 + self.args = args + def invoke(self, args, out, outindex ): log.debug( "PythonScript.invoke " + str( args ) ) try: @@ -986,19 +984,23 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC def getType( self ): return self.dirBrowseNode.getType() - # retrieve function args in parenthesis + # retreive function args in parenthesis def getFunctionArguments(self, func_signature): - nOpenParenthesis = func_signature.find( "(") + nOpenParenthesis = func_signature.find( "(" ) if -1 == nOpenParenthesis: function_name = func_signature - arguments = '' + arguments = None else: function_name = func_signature[0:nOpenParenthesis] - leading = func_signature[nOpenParenthesis+1:len(func_signature)] - nCloseParenthesis = leading.find( ")") + arg_part = func_signature[nOpenParenthesis+1:len(func_signature)] + nCloseParenthesis = arg_part.find( ")" ) if -1 == nCloseParenthesis: raise IllegalArgumentException( "PythonLoader: mismatch parenthesis " + func_signature, self, 0 ) - arguments = leading[0:nCloseParenthesis] + arguments = arg_part[0:nCloseParenthesis].strip() + if arguments == "": + arguments = None + else: + arguments = tuple([x.strip().strip('"') for x in arguments.split(",")]) return function_name, arguments def getScript( self, scriptUri ): @@ -1011,7 +1013,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC fileUri = storageUri[0:storageUri.find( "$" )] funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)] - # retrieve arguments in parenthesis + # retreive arguments in parenthesis funcName, funcArgs = self.getFunctionArguments(funcName) log.debug( " getScript : parsed funcname " + str(funcName) ) log.debug( " getScript : func args " + str(funcArgs) ) |