This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit b4375c204007c475db6255f030c4d5f60ed834dd
Author: Damjan Jovanovic <[email protected]>
AuthorDate: Sat Jan 18 09:52:51 2020 +0200

    scripting: add Python 3 support to the Python provider
    
    Patch by: me
    
    (cherry picked from commit 4f686187ecfc86b8d293f1b6c9a49fee4b0bf393)
---
 main/scripting/source/pyprov/pythonscript.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/main/scripting/source/pyprov/pythonscript.py 
b/main/scripting/source/pyprov/pythonscript.py
index 23e82b5..af01bb0 100644
--- a/main/scripting/source/pyprov/pythonscript.py
+++ b/main/scripting/source/pyprov/pythonscript.py
@@ -56,7 +56,10 @@ ENABLE_EDIT_DIALOG=False                    # offers a 
minimal editor for editin
 #-------------------------------------------------------------------
 
 def encfile(uni):
-    return uni.encode( sys.getfilesystemencoding())
+    if sys.version_info[0] > 2:
+        return uni
+    else:
+        return uni.encode( sys.getfilesystemencoding())
 
 def lastException2String():
     (excType,excInstance,excTraceback) = sys.exc_info()
@@ -81,7 +84,7 @@ def getLogTarget():
             userInstallation =  pathSubst.getSubstituteVariableValue( "user" )
             if len( userInstallation ) > 0:
                 systemPath = uno.fileUrlToSystemPath( userInstallation + 
"/Scripts/python/log.txt" )
-                ret = file( systemPath , "a" )
+                ret = open( systemPath , "a" )
         except Exception as e:
             print("Exception during creation of pythonscript logfile: "+ 
lastException2String() + "\n, delagating log to stdout\n")
     return ret
@@ -153,13 +156,16 @@ g_implName = 
"org.openoffice.pyuno.LanguageScriptProviderFor"+LANGUAGENAME
 BLOCK_SIZE = 65536
 def readTextFromStream( inputStream ):
     # read the file
-    code = uno.ByteSequence( "" )
+    code = uno.ByteSequence( b"" )
     while True:
         read,out = inputStream.readBytes( None , BLOCK_SIZE )
         code = code + out
         if read < BLOCK_SIZE:
             break
-    return code.value
+    if sys.version_info[0] > 2:
+        return str( code.value, 'utf-8' )
+    else:
+        return code.value
 
 def toIniName( str ):
     # TODO: what is the official way to get to know whether i am on the 
windows platform ?

Reply via email to