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

jimjag pushed a commit to branch python3-dev
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 7bdfda376b9056879d4be0b88a37366213c3a243
Author: Jim Jagielski <[email protected]>
AuthorDate: Fri Jun 5 08:13:02 2026 -0400

    Python 3 migration: baseline 3.10, fix shipped .py for Py3
    
    Begin migrating bundled Python from 2.7.18 to 3.10 (Unix/macOS first;
    Windows build deferred). This commit covers the version baseline and the
    mechanical, API-dictated Python source fixes that can be validated
    without a build host.
    
    - python/pyversion.mk, pyversion_dmake.mk: PYMAJOR/PYMINOR/PYMICRO ->
      3/10/18. The PY_FULL_DLL_NAME/PYTHONLIB derivations then yield the
      correct Py3 names (libpython3.10.dylib, libpython3.10.so.1.0,
      -lpython3.10). Version remains a single knob for future bumps.
    - pyuno/source/loader/pythonloader.py: imp -> types.ModuleType (imp is
      removed in 3.12); file() -> open() (removed in Py3).
    - scripting/source/pyprov/pythonscript.py: imp -> types.ModuleType at
      the three live sites (and the commented reference).
    - scripting/source/pyprov/mailmerge.py: Py3 email module layout
      (email.mime.base, email.message, email.header, email.mime.multipart,
      email.utils) and email.Encoders -> email.encoders.
    
    All three .py files pass py_compile. These changes are dictated by the
    CPython API (license-safe; not copied from LibreOffice).
    
    NOTE: Python 3.10 reaches EOL 2026-10-31; chosen per project decision
    for a low-friction first migration. Bump the version knob later.
---
 main/python/pyversion.mk                     |  4 ++--
 main/python/pyversion_dmake.mk               |  4 ++--
 main/pyuno/source/loader/pythonloader.py     |  6 +++---
 main/scripting/source/pyprov/mailmerge.py    | 16 ++++++++--------
 main/scripting/source/pyprov/pythonscript.py | 10 +++++-----
 5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/main/python/pyversion.mk b/main/python/pyversion.mk
index 353925e92e..95f7b299da 100644
--- a/main/python/pyversion.mk
+++ b/main/python/pyversion.mk
@@ -20,8 +20,8 @@
 # *************************************************************
 # when you want to change the python version, you must update the d.lst
 # in the python project accordingly !!!
-PYMAJOR=2
-PYMINOR=7
+PYMAJOR=3
+PYMINOR=10
 PYMICRO=18
 PYVERSION=$(PYMAJOR).$(PYMINOR).$(PYMICRO)
 
diff --git a/main/python/pyversion_dmake.mk b/main/python/pyversion_dmake.mk
index 37aa099277..b8252a9767 100644
--- a/main/python/pyversion_dmake.mk
+++ b/main/python/pyversion_dmake.mk
@@ -20,8 +20,8 @@
 # *************************************************************
 # when you want to change the python version, you must update the d.lst
 # in the python project accordingly !!!
-PYMAJOR=2
-PYMINOR=7
+PYMAJOR=3
+PYMINOR=10
 PYMICRO=18
 PYVERSION=$(PYMAJOR).$(PYMINOR).$(PYMICRO)
 
diff --git a/main/pyuno/source/loader/pythonloader.py 
b/main/pyuno/source/loader/pythonloader.py
index 46e051da98..34ff1c532b 100644
--- a/main/pyuno/source/loader/pythonloader.py
+++ b/main/pyuno/source/loader/pythonloader.py
@@ -21,7 +21,7 @@
 import uno
 import unohelper
 import sys
-import imp
+import types
 import os
 from com.sun.star.uno import Exception,RuntimeException
 from com.sun.star.loader import XImplementationLoader
@@ -84,14 +84,14 @@ class Loader( XImplementationLoader, XServiceInfo, 
unohelper.Base ):
                 # did we load the module already ?
                 mod = g_loadedComponents.get( url )
                 if not mod:
-                    mod = imp.new_module("uno_component")
+                    mod = types.ModuleType("uno_component")
 
                     # check for pythonpath.zip beside .py files
                     checkForPythonPathBesideComponent( url[0:url.rfind('/')] )
 
                     # read the file
                     filename = unohelper.fileUrlToSystemPath( url )
-                    fileHandle = file( filename )
+                    fileHandle = open( filename )
                     src = fileHandle.read().replace("\r","")
                     if not src.endswith( "\n" ):
                         src = src + "\n"
diff --git a/main/scripting/source/pyprov/mailmerge.py 
b/main/scripting/source/pyprov/mailmerge.py
index 4a4c430c28..c11ddd8c7a 100644
--- a/main/scripting/source/pyprov/mailmerge.py
+++ b/main/scripting/source/pyprov/mailmerge.py
@@ -54,13 +54,13 @@ from com.sun.star.lang import IllegalArgumentException
 from com.sun.star.lang import EventObject
 from com.sun.star.mail import SendMailMessageFailedException
 
-from email.MIMEBase import MIMEBase
-from email.Message import Message
-from email import Encoders
-from email.Header import Header
-from email.MIMEMultipart import MIMEMultipart
-from email.Utils import formatdate
-from email.Utils import parseaddr
+from email.mime.base import MIMEBase
+from email.message import Message
+from email import encoders
+from email.header import Header
+from email.mime.multipart import MIMEMultipart
+from email.utils import formatdate
+from email.utils import parseaddr
 from socket import _GLOBAL_DEFAULT_TIMEOUT
 
 import sys, smtplib, imaplib, poplib
@@ -245,7 +245,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
             msgattachment = MIMEBase(maintype, subtype)
             data = content.getTransferData(flavor)
             msgattachment.set_payload(data)
-            Encoders.encode_base64(msgattachment)
+            encoders.encode_base64(msgattachment)
             fname = attachment.ReadableName
             try:
                 fname.encode('ascii')
diff --git a/main/scripting/source/pyprov/pythonscript.py 
b/main/scripting/source/pyprov/pythonscript.py
index 4e7fc4667e..03f52b897a 100644
--- a/main/scripting/source/pyprov/pythonscript.py
+++ b/main/scripting/source/pyprov/pythonscript.py
@@ -24,7 +24,7 @@ import uno
 import unohelper
 import sys
 import os
-import imp
+import types
 import time
 import ast
 
@@ -356,7 +356,7 @@ class ScriptContext(unohelper.Base):
 #        code = readTextFromStream( sfa.openFileRead( url ) )
 
         # execute the module
-#        entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") 
)
+#        entry = ModuleEntry( lastRead, 
types.ModuleType("ooo_script_framework") )
 #        entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = g_scriptContext
 #        entry.module.__file__ = url
 #        exec code in entry.module.__dict__
@@ -489,7 +489,7 @@ class ProviderContext:
             src = ensureSourceState( src )
 
             # execute the module
-            entry = ModuleEntry( lastRead, 
imp.new_module("ooo_script_framework") )
+            entry = ModuleEntry( lastRead, 
types.ModuleType("ooo_script_framework") )
             entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = 
self.scriptContext
 
             code = None
@@ -666,7 +666,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode, 
XPropertySet, XInvocation,
             if event.ActionCommand == "Run":
                 code = self.editor.getControl("EditorTextField").getText()
                 code = ensureSourceState( code )
-                mod = imp.new_module("ooo_script_framework")
+                mod = types.ModuleType("ooo_script_framework")
                 mod.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = 
self.provCtx.scriptContext
                 exec(code, mod.__dict__)
                 values = mod.__dict__.get( CALLABLE_CONTAINER_NAME , None )
@@ -827,7 +827,7 @@ class FileBrowseNode( unohelper.Base, XBrowseNode, 
XPropertySet, XInvocation, XA
             if event.ActionCommand == "Run":
                 code = self.editor.getControl("EditorTextField").getText()
                 code = ensureSourceState( code )
-                mod = imp.new_module("ooo_script_framework")
+                mod = types.ModuleType("ooo_script_framework")
                 mod.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = 
self.provCtx.scriptContext
                 exec(code, mod.__dict__)
                 values = mod.__dict__.get( CALLABLE_CONTAINER_NAME , None )

Reply via email to