Kaydet (Commit) 3d97c9d2 authored tarafından Laurent Godard's avatar Laurent Godard Kaydeden (comit) Thorsten Behrens

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/53453Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 225e28d7
...@@ -869,10 +869,8 @@ class PythonScript( unohelper.Base, XScript ): ...@@ -869,10 +869,8 @@ class PythonScript( unohelper.Base, XScript ):
def __init__( self, func, mod, args ): def __init__( self, func, mod, args ):
self.func = func self.func = func
self.mod = mod self.mod = mod
if (args != '' and args is not None): self.args = args
self.args = tuple([x.strip() for x in args.split(",")])
else:
self.args = None
def invoke(self, args, out, outindex ): def invoke(self, args, out, outindex ):
log.debug( "PythonScript.invoke " + str( args ) ) log.debug( "PythonScript.invoke " + str( args ) )
try: try:
...@@ -986,19 +984,23 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC ...@@ -986,19 +984,23 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
def getType( self ): def getType( self ):
return self.dirBrowseNode.getType() return self.dirBrowseNode.getType()
# retrieve function args in parenthesis # retreive function args in parenthesis
def getFunctionArguments(self, func_signature): def getFunctionArguments(self, func_signature):
nOpenParenthesis = func_signature.find( "(") nOpenParenthesis = func_signature.find( "(" )
if -1 == nOpenParenthesis: if -1 == nOpenParenthesis:
function_name = func_signature function_name = func_signature
arguments = '' arguments = None
else: else:
function_name = func_signature[0:nOpenParenthesis] function_name = func_signature[0:nOpenParenthesis]
leading = func_signature[nOpenParenthesis+1:len(func_signature)] arg_part = func_signature[nOpenParenthesis+1:len(func_signature)]
nCloseParenthesis = leading.find( ")") nCloseParenthesis = arg_part.find( ")" )
if -1 == nCloseParenthesis: if -1 == nCloseParenthesis:
raise IllegalArgumentException( "PythonLoader: mismatch parenthesis " + func_signature, self, 0 ) 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 return function_name, arguments
def getScript( self, scriptUri ): def getScript( self, scriptUri ):
...@@ -1011,7 +1013,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC ...@@ -1011,7 +1013,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
fileUri = storageUri[0:storageUri.find( "$" )] fileUri = storageUri[0:storageUri.find( "$" )]
funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)] funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)]
# retrieve arguments in parenthesis # retreive arguments in parenthesis
funcName, funcArgs = self.getFunctionArguments(funcName) funcName, funcArgs = self.getFunctionArguments(funcName)
log.debug( " getScript : parsed funcname " + str(funcName) ) log.debug( " getScript : parsed funcname " + str(funcName) )
log.debug( " getScript : func args " + str(funcArgs) ) log.debug( " getScript : func args " + str(funcArgs) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment