wizards/com/sun/star/wizards/agenda/AgendaWizardDialogResources.py |   26 
+++++++--
 wizards/com/sun/star/wizards/common/NoValidPathException.py        |   26 
+++++++--
 wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py       |   27 
+++++++---
 wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py |   25 
+++++++--
 wizards/com/sun/star/wizards/ui/WizardDialog.py                    |   27 
+++++++---
 5 files changed, 105 insertions(+), 26 deletions(-)

New commits:
commit e55e3e1362910a9ea38b8283f5bb2b886e803cf3
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Jun 6 12:21:16 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jun 7 13:37:02 2022 +0200

    use more complex scheme on newer Python (>=3.7) to avoid DeprecationWarning
    
    similiar to commit 069f0eb13f7d26ce4b854160bbb9592c25609b38
    
    Change-Id: I08577ced705df620d99781da53b6085398f52821
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135450
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogResources.py 
b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogResources.py
index 15631123fbcb..9d42e6317f95 100644
--- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogResources.py
+++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogResources.py
@@ -26,15 +26,31 @@ class AgendaWizardDialogResources(object):
     def __init__(self):
         import sys, os
 
-        # imp is deprecated since Python v.3.4
-        if sys.version_info >= (3,3):
+        if sys.version_info < (3,4):
+            import imp
+            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+            import strings
+        elif sys.version_info < (3,7):
+            # imp is deprecated since Python v.3.4
             from importlib.machinery import SourceFileLoader
             SourceFileLoader('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
+            import strings
         else:
-            import imp
-            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+            # have to jump through hoops since 3.7, partly because python does 
not like loading modules that do have a .py extension
+            import importlib
+            import importlib.util
+            import importlib.machinery
+            module_name = 'strings'
+            path = os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc')
+            spec = importlib.util.spec_from_loader(
+                module_name,
+                importlib.machinery.SourceFileLoader(module_name, path)
+            )
+            module = importlib.util.module_from_spec(spec)
+            spec.loader.exec_module(module)
+            sys.modules[module_name] = module
+            strings = module
 
-        import strings
 
         self.resAgendaWizardDialog_title = 
strings.RID_AGENDAWIZARDDIALOG_START_1
         self.resoptMakeChanges_value = strings.RID_AGENDAWIZARDDIALOG_START_2
diff --git a/wizards/com/sun/star/wizards/common/NoValidPathException.py 
b/wizards/com/sun/star/wizards/common/NoValidPathException.py
index 54fb58613c09..565f67fefcee 100644
--- a/wizards/com/sun/star/wizards/common/NoValidPathException.py
+++ b/wizards/com/sun/star/wizards/common/NoValidPathException.py
@@ -24,14 +24,30 @@ class NoValidPathException(Exception):
         if xMSF:
             import sys, os
 
-            # imp is deprecated since Python v.3.4
-            if sys.version_info >= (3,3):
+            if sys.version_info < (3,4):
+                import imp
+                imp.load_source('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc'))
+                import strings
+            elif sys.version_info < (3,7):
+                # imp is deprecated since Python v.3.4
                 from importlib.machinery import SourceFileLoader
                 SourceFileLoader('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
+                import strings
             else:
-                import imp
-                imp.load_source('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc'))
+                # have to jump through hoops since 3.7, partly because python 
does not like loading modules that do have a .py extension
+                import importlib
+                import importlib.util
+                import importlib.machinery
+                module_name = 'strings'
+                path = os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc')
+                spec = importlib.util.spec_from_loader(
+                    module_name,
+                    importlib.machinery.SourceFileLoader(module_name, path)
+                )
+                module = importlib.util.module_from_spec(spec)
+                spec.loader.exec_module(module)
+                sys.modules[module_name] = module
+                strings = module
 
-            import strings
             SystemDialog.showErrorBox(xMSF, strings.RID_COMMON_START_21) 
#OfficePathnotavailable
 
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py 
b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
index a5bd469df80f..fa3254207c2f 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
@@ -21,15 +21,30 @@ class FaxWizardDialogResources(object):
     def __init__(self):
         import sys, os
 
-        # imp is deprecated since Python v.3.4
-        if sys.version_info >= (3,3):
+        if sys.version_info < (3,4):
+            import imp
+            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+            import strings
+        elif sys.version_info < (3,7):
+            # imp is deprecated since Python v.3.4
             from importlib.machinery import SourceFileLoader
             SourceFileLoader('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
+            import strings
         else:
-            import imp
-            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
-
-        import strings
+            # have to jump through hoops since 3.7, partly because python does 
not like loading modules that do have a .py extension
+            import importlib
+            import importlib.util
+            import importlib.machinery
+            module_name = 'strings'
+            path = os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc')
+            spec = importlib.util.spec_from_loader(
+                module_name,
+                importlib.machinery.SourceFileLoader(module_name, path)
+            )
+            module = importlib.util.module_from_spec(spec)
+            spec.loader.exec_module(module)
+            sys.modules[module_name] = module
+            strings = module
 
         self.resFaxWizardDialog_title = strings.RID_FAXWIZARDDIALOG_START_1
         self.resoptBusinessFax_value = strings.RID_FAXWIZARDDIALOG_START_3
diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py 
b/wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py
index 19ef40c4a576..3a7802f2baa7 100644
--- a/wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py
+++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialogResources.py
@@ -21,13 +21,30 @@ class LetterWizardDialogResources(object):
     def __init__(self):
         import sys, os
 
-        # imp is deprecated since Python v.3.4
-        if sys.version_info >= (3,3):
+        if sys.version_info < (3,4):
+            import imp
+            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+            import strings
+        elif sys.version_info < (3,7):
+            # imp is deprecated since Python v.3.4
             from importlib.machinery import SourceFileLoader
             SourceFileLoader('strings', 
os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
+            import strings
         else:
-            import imp
-            imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+            # have to jump through hoops since 3.7, partly because python does 
not like loading modules that do have a .py extension
+            import importlib
+            import importlib.util
+            import importlib.machinery
+            module_name = 'strings'
+            path = os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc')
+            spec = importlib.util.spec_from_loader(
+                module_name,
+                importlib.machinery.SourceFileLoader(module_name, path)
+            )
+            module = importlib.util.module_from_spec(spec)
+            spec.loader.exec_module(module)
+            sys.modules[module_name] = module
+            strings = module
 
         import strings
 
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py 
b/wizards/com/sun/star/wizards/ui/WizardDialog.py
index afa865a224c0..e5970535142b 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.py
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py
@@ -30,15 +30,30 @@ from com.sun.star.awt.FontWeight import BOLD
 
 import sys, os
 
-# imp is deprecated since Python v.3.4
-if sys.version_info >= (3,3):
+if sys.version_info < (3,4):
+    import imp
+    imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
+    import strings
+elif sys.version_info < (3,7):
+    # imp is deprecated since Python v.3.4
     from importlib.machinery import SourceFileLoader
     SourceFileLoader('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc')).load_module()
+    import strings
 else:
-    import imp
-    imp.load_source('strings', os.path.join(os.path.dirname(__file__), 
'../common/strings.hrc'))
-
-import strings
+    # have to jump through hoops since 3.7, partly because python does not 
like loading modules that do have a .py extension
+    import importlib
+    import importlib.util
+    import importlib.machinery
+    module_name = 'strings'
+    path = os.path.join(os.path.dirname(__file__), '../common/strings.hrc')
+    spec = importlib.util.spec_from_loader(
+        module_name,
+        importlib.machinery.SourceFileLoader(module_name, path)
+    )
+    module = importlib.util.module_from_spec(spec)
+    spec.loader.exec_module(module)
+    sys.modules[module_name] = module
+    strings = module
 
 class WizardDialog(UnoDialog2):
 

Reply via email to