Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello,

Here is a patch for fixing warning/error pychecker in the .py files of libs-core/scripting/source/pyprov
Could anybody tell me if this is ok (and i can push it myself) or not ?
I already fixed a simple bug (commit 60b368fa19ced4595bfba8068b1e5769a1be187d) but this time I would like to be advised since I don't know Python at all.

There are still warning/errors with pychecker :
"
Processing module mailmerge (mailmerge.py)...
Processing module officehelper (officehelper.py)...
Processing module pythonscript (pythonscript.py)...

Warnings...

mailmerge.py:377: Function return types are inconsistent
mailmerge.py:379: Function return types are inconsistent

pythonscript.py:11: Should not assign to NONE, it is similar to builtin None
pythonscript.py:659: Instantiating an object with arguments, but no constructor
pythonscript.py:890: Redefining attribute (getScript) original line (885)
"

Julien.
commit 2b065784e0b8f4790e43ba9ce1460da46c5baa4b
Author: Julien Nabet <serval2412@yahoo.fr>
Date:   Sat Mar 12 11:21:45 2011 +0100

    Fix pychecker warning/error

diff --git a/scripting/source/pyprov/mailmerge.py b/scripting/source/pyprov/mailmerge.py
index 8fd697f..1d76e6d 100644
--- a/scripting/source/pyprov/mailmerge.py
+++ b/scripting/source/pyprov/mailmerge.py
@@ -232,6 +232,7 @@ class PyMailIMAPService(unohelper.Base, XMailService):
                self.supportedtypes = ('Insecure', 'Ssl')
                self.server = None
                self.connectioncontext = None
+                self.notify = EventObject()
                if dbg:
                        print >> sys.stderr, "PyMailIMAPService init"
        def addConnectionListener(self, xListener):
@@ -300,6 +301,7 @@ class PyMailPOP3Service(unohelper.Base, XMailService):
                self.supportedtypes = ('Insecure', 'Ssl')
                self.server = None
                self.connectioncontext = None
+                self.notify = EventObject()
                if dbg:
                        print >> sys.stderr, "PyMailPOP3Service init"
        def addConnectionListener(self, xListener):
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
index 0d2faaa..2cc9544 100644
--- a/scripting/source/pyprov/pythonscript.py
+++ b/scripting/source/pyprov/pythonscript.py
@@ -48,7 +48,7 @@ def getLogTarget():
             if len( userInstallation ) > 0:
                 systemPath = uno.fileUrlToSystemPath( userInstallation + "/Scripts/python/log.txt" 
)
                 ret = file( systemPath , "a" )
-        except Exception,e:
+        except:
             print "Exception during creation of pythonscript logfile: "+ lastException2String() + 
"\n, delagating log to stdout\n"
     return ret
   
@@ -81,7 +81,7 @@ class Logger(LogLevel):
                     encfile(msg) +
                     "\n" )
                 self.target.flush()
-            except Exception,e:
+            except:
                 print "Error during writing to stdout: " +lastException2String() + "\n"
 
 log = Logger( getLogTarget() )
@@ -90,6 +90,8 @@ log.debug( "pythonscript loading" )
 
 #from com.sun.star.lang import typeOfXServiceInfo, typeOfXTypeProvider
 from com.sun.star.uno import RuntimeException
+from com.sun.star.lang import IllegalArgumentException
+from com.sun.star.container import NoSuchElementException
 from com.sun.star.lang import XServiceInfo
 from com.sun.star.io import IOException
 from com.sun.star.ucb import CommandAbortedException, XCommandEnvironment, XProgressHandler
@@ -437,7 +439,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
                 ret = not self.provCtx.sfa.isReadOnly( self.uri )
         
             log.isDebugLevel() and log.debug( "ScriptBrowseNode.getPropertyValue called for " + 
name + ", returning " + str(ret) )
-        except Exception,e:
+        except:
             log.error( "ScriptBrowseNode.getPropertyValue error " + lastException2String())
             raise
                                               
@@ -451,7 +453,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
     def getIntrospection( self ):
         return None
 
-    def invoke( self, name, params, outparamindex, outparams ):
+    def invoke( self, name ):
         if name == "Editable":
             servicename = "com.sun.star.awt.DialogProvider"
             ctx = self.provCtx.scriptContext.getComponentContext()
@@ -506,7 +508,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
 #                log.isDebugLevel() and log.debug("Save is not implemented yet")
 #                text = self.editor.getControl("EditorTextField").getText()
 #                log.isDebugLevel() and log.debug("Would save: " + text)
-        except Exception,e:
+        except:
             # TODO: add an error box here !
             log.error( lastException2String() )
             
@@ -547,7 +549,7 @@ class FileBrowseNode( unohelper.Base, XBrowseNode ):
                     self.provCtx, self.uri, self.name, i ))
             ret = tuple( scriptNodeList )
             log.isDebugLevel() and log.debug( "returning " +str(len(ret)) + " ScriptChildNodes on 
" + self.uri )
-        except Exception, e:
+        except:
             text = lastException2String()
             log.error( "Error while evaluating " + self.uri + ":" + text )
             raise
@@ -556,7 +558,7 @@ class FileBrowseNode( unohelper.Base, XBrowseNode ):
     def hasChildNodes(self):
         try:
             return len(self.getChildNodes()) > 0
-        except Exception, e:
+        except:
             return False
     
     def getType( self):
@@ -659,7 +661,7 @@ def getPathesFromPackage( rootUrl, sfa ):
             if not isPyFileInPath( sfa, i ):
                 handler.urlList.remove(i)
         ret = tuple( handler.urlList )
-    except UnoException, e:
+    except UnoException:
         text = lastException2String()
         log.debug( "getPathesFromPackage " + fileUrl + " Exception: " +text )
         pass
@@ -685,7 +687,7 @@ class DummyProgressHandler( unohelper.Base, XProgressHandler ):
         log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.push " + str( status 
) )
     def update( self,status ): 
         log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.update " + str( 
status ) )
-    def pop( self ): 
+    def pop( self, event ):
         log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.push " + str( event 
) )
 
 class CommandEnvironment(unohelper.Base, XCommandEnvironment):
@@ -784,7 +786,7 @@ class PythonScript( unohelper.Base, XScript ):
     def __init__( self, func, mod ):
         self.func = func
         self.mod = mod
-    def invoke(self, args, out, outindex ):
+    def invoke(self, args ):
         log.isDebugLevel() and log.debug( "PythonScript.invoke " + str( args ) )
         try:
             ret = self.func( *args )
@@ -902,7 +904,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
 
             log.isDebugLevel() and log.debug( "got func " + str( func ) )
             return PythonScript( func, mod )
-        except Exception, e:
+        except:
             text = lastException2String()
             log.error( text )
             raise ScriptFrameworkErrorException( text, self, scriptUri, LANGUAGENAME, 0 )
@@ -934,7 +936,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
             ret = self.provCtx.isUrlInPackage( uri )
             log.debug( "hasByName " + uri + " " +str( ret ) )
             return ret
-        except Exception, e:
+        except:
             text = lastException2String()
             log.debug( "Error in hasByName:" +  text )
             return False
@@ -962,8 +964,9 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
 
     def replaceByName( self, name, value ):
         log.debug( "replaceByName called " + str( name ) + " " + str( value ))
-        removeByName( name )
-        insertByName( name )
+       uri = expandUri( name )
+        self.removeByName( name )
+        self.insertByName( name, value )
         log.debug( "replaceByName called" + str( uri ) + " successful" )
 
     def getElementType( self ):

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.