e94c2df
From 21b9a845ac7e8805b41d7dab1a6fbf8076689ae8 Mon Sep 17 00:00:00 2001
e94c2df
From: rpm-build <rpm-build>
e94c2df
Date: Sat, 19 Apr 2014 12:06:27 +0200
e94c2df
Subject: [PATCH] 0001-python3-added-compatibility.3.patch
e94c2df
e94c2df
---
e94c2df
 unoconv | 248 ++++++++++++++++++++++++++++++++++++----------------------------
e94c2df
 1 file changed, 139 insertions(+), 109 deletions(-)
e94c2df
e94c2df
diff --git a/unoconv b/unoconv
e94c2df
index 30e6706..a13db44 100755
e94c2df
--- a/unoconv
e94c2df
+++ b/unoconv
e94c2df
@@ -1,4 +1,4 @@
e94c2df
-#!/usr/bin/env python
e94c2df
+#!/usr/bin/python3
e94c2df
 
e94c2df
 ### This program is free software; you can redistribute it and/or modify
e94c2df
 ### it under the terms of the GNU General Public License as published by
e94c2df
@@ -77,11 +77,11 @@ def find_offices():
e94c2df
     else:
e94c2df
 
e94c2df
         if os.name in ( 'nt', 'os2' ):
e94c2df
-            if 'PROGRAMFILES' in os.environ.keys():
e94c2df
+            if 'PROGRAMFILES' in list(os.environ.keys()):
e94c2df
                 extrapaths += glob.glob(os.environ['PROGRAMFILES']+'\\LibreOffice*') + \
e94c2df
                               glob.glob(os.environ['PROGRAMFILES']+'\\OpenOffice.org*')
e94c2df
 
e94c2df
-            if 'PROGRAMFILES(X86)' in os.environ.keys():
e94c2df
+            if 'PROGRAMFILES(X86)' in list(os.environ.keys()):
e94c2df
                 extrapaths += glob.glob(os.environ['PROGRAMFILES(X86)']+'\\LibreOffice*') + \
e94c2df
                               glob.glob(os.environ['PROGRAMFILES(X86)']+'\\OpenOffice.org*')
e94c2df
 
e94c2df
@@ -203,7 +203,7 @@ def office_environ(office):
e94c2df
     ### Set UNO_PATH so that "officehelper.bootstrap()" can find soffice executable:
e94c2df
     os.environ['UNO_PATH'] = office.unopath
e94c2df
 
e94c2df
-    ### Set URE_BOOTSTRAP so that "uno.getComponentContext()" bootstraps a complete
e94c2df
+    ### Set URE_BOOTSTRAP so that "global_uno.getComponentContext()" bootstraps a complete
e94c2df
     ### UNO environment
e94c2df
     if os.name in ( 'nt', 'os2' ):
e94c2df
         os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:' + realpath(office.basepath, 'program', 'fundamental.ini')
e94c2df
@@ -233,18 +233,18 @@ def office_environ(office):
e94c2df
 
e94c2df
 def debug_office():
e94c2df
     if 'URE_BOOTSTRAP' in os.environ:
e94c2df
-        print >>sys.stderr, 'URE_BOOTSTRAP=%s' % os.environ['URE_BOOTSTRAP']
e94c2df
+        print('URE_BOOTSTRAP=%s' % os.environ['URE_BOOTSTRAP'], file=sys.stderr)
e94c2df
     if 'UNO_PATH' in os.environ:
e94c2df
-        print >>sys.stderr, 'UNO_PATH=%s' % os.environ['UNO_PATH']
e94c2df
+        print('UNO_PATH=%s' % os.environ['UNO_PATH'], file=sys.stderr)
e94c2df
     if 'UNO_TYPES' in os.environ:
e94c2df
-        print >>sys.stderr, 'UNO_TYPES=%s' % os.environ['UNO_TYPES']
e94c2df
-    print 'PATH=%s' % os.environ['PATH']
e94c2df
+        print('UNO_TYPES=%s' % os.environ['UNO_TYPES'], file=sys.stderr)
e94c2df
+    print('PATH=%s' % os.environ['PATH'])
e94c2df
     if 'PYTHONHOME' in os.environ:
e94c2df
-        print >>sys.stderr, 'PYTHONHOME=%s' % os.environ['PYTHONHOME']
e94c2df
+        print('PYTHONHOME=%s' % os.environ['PYTHONHOME'], file=sys.stderr)
e94c2df
     if 'PYTHONPATH' in os.environ:
e94c2df
-        print >>sys.stderr, 'PYTHONPATH=%s' % os.environ['PYTHONPATH']
e94c2df
+        print('PYTHONPATH=%s' % os.environ['PYTHONPATH'], file=sys.stderr)
e94c2df
     if 'LD_LIBRARY_PATH' in os.environ:
e94c2df
-        print >>sys.stderr, 'LD_LIBRARY_PATH=%s' % os.environ['LD_LIBRARY_PATH']
e94c2df
+        print('LD_LIBRARY_PATH=%s' % os.environ['LD_LIBRARY_PATH'], file=sys.stderr)
e94c2df
 
e94c2df
 def python_switch(office):
e94c2df
     if office.pythonhome:
e94c2df
@@ -277,6 +277,7 @@ def python_switch(office):
e94c2df
 
e94c2df
         try:
e94c2df
             os.execvpe(office.python, [office.python, ] + sys.argv[0:], os.environ)
e94c2df
+            print((office.python, [office.python, ] + sys.argv[0:], osenviron))
e94c2df
         except OSError:
e94c2df
             ### Mac OS X versions prior to 10.6 do not support execv in
e94c2df
             ### a process that contains multiple threads.  Instead of
e94c2df
@@ -335,11 +336,11 @@ class FmtList:
e94c2df
         return ret
e94c2df
 
e94c2df
     def display(self, doctype):
e94c2df
-        print >>sys.stderr, "The following list of %s formats are currently available:\n" % doctype
e94c2df
+        print("The following list of %s formats are currently available:\n" % doctype, file=sys.stderr)
e94c2df
         for fmt in self.list:
e94c2df
             if fmt.doctype == doctype:
e94c2df
-                print >>sys.stderr, "  %-8s - %s" % (fmt.name, fmt)
e94c2df
-        print >>sys.stderr
e94c2df
+                print("  %-8s - %s" % (fmt.name, fmt), file=sys.stderr)
e94c2df
+        print(file=sys.stderr)
e94c2df
 
e94c2df
 fmts = FmtList()
e94c2df
 
e94c2df
@@ -530,14 +531,14 @@ class Options:
e94c2df
                  'outputpath', 'password=', 'pipe=', 'port=', 'server=',
e94c2df
                  'timeout=', 'show', 'stdout', 'template', 'verbose',
e94c2df
                  'version'] )
e94c2df
-        except getopt.error, exc:
e94c2df
-            print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
e94c2df
+        except getopt.error as exc:
e94c2df
+            print('unoconv: %s, try unoconv -h for a list of all the options' % str(exc))
e94c2df
             sys.exit(255)
e94c2df
 
e94c2df
         for opt, arg in opts:
e94c2df
             if opt in ['-h', '--help']:
e94c2df
                 self.usage()
e94c2df
-                print
e94c2df
+                print()
e94c2df
                 self.help()
e94c2df
                 sys.exit(1)
e94c2df
             elif opt in ['-c', '--connection']:
e94c2df
@@ -553,16 +554,16 @@ class Options:
e94c2df
                     if name in ('FilterOptions'):
e94c2df
                         self.exportfilteroptions = value
e94c2df
                     elif value in ('True', 'true'):
e94c2df
-                        self.exportfilter.append( PropertyValue( name, 0, True, 0 ) )
e94c2df
+                        self.exportfilter.append( UnoPropertyValue( name, 0, True, 0 ) )
e94c2df
                     elif value in ('False', 'false'):
e94c2df
-                        self.exportfilter.append( PropertyValue( name, 0, False, 0 ) )
e94c2df
+                        self.exportfilter.append( UnoPropertyValue( name, 0, False, 0 ) )
e94c2df
                     else:
e94c2df
                         try:
e94c2df
-                            self.exportfilter.append( PropertyValue( name, 0, int(value), 0 ) )
e94c2df
+                            self.exportfilter.append( UnoPropertyValue( name, 0, int(value), 0 ) )
e94c2df
                         except ValueError:
e94c2df
-                            self.exportfilter.append( PropertyValue( name, 0, value, 0 ) )
e94c2df
+                            self.exportfilter.append( UnoPropertyValue( name, 0, value, 0 ) )
e94c2df
                 else:
e94c2df
-                    print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
e94c2df
+                    print('Warning: Option %s cannot be parsed, ignoring.' % arg, file=sys.stderr)
e94c2df
             elif opt in ['-f', '--format']:
e94c2df
                 self.format = arg
e94c2df
             elif opt in ['-i', '--import']:
e94c2df
@@ -572,16 +573,16 @@ class Options:
e94c2df
                     if name in ('FilterOptions'):
e94c2df
                         self.importfilteroptions = value
e94c2df
                     elif value in ('True', 'true'):
e94c2df
-                        self.importfilter.append( PropertyValue( name, 0, True, 0 ) )
e94c2df
+                        self.importfilter.append( UnoPropertyValue( name, 0, True, 0 ) )
e94c2df
                     elif value in ('False', 'false'):
e94c2df
-                        self.importfilter.append( PropertyValue( name, 0, False, 0 ) )
e94c2df
+                        self.importfilter.append( UnoPropertyValue( name, 0, False, 0 ) )
e94c2df
                     else:
e94c2df
                         try:
e94c2df
-                            self.importfilter.append( PropertyValue( name, 0, int(value), 0 ) )
e94c2df
+                            self.importfilter.append( UnoPropertyValue( name, 0, int(value), 0 ) )
e94c2df
                         except ValueError:
e94c2df
-                            self.importfilter.append( PropertyValue( name, 0, value, 0 ) )
e94c2df
+                            self.importfilter.append( UnoPropertyValue( name, 0, value, 0 ) )
e94c2df
                 else:
e94c2df
-                    print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
e94c2df
+                    print('Warning: Option %s cannot be parsed, ignoring.' % arg, file=sys.stderr)
e94c2df
             elif opt in ['-l', '--listener']:
e94c2df
                 self.listener = True
e94c2df
             elif opt in ['-n', '--no-launch']:
e94c2df
@@ -589,7 +590,7 @@ class Options:
e94c2df
             elif opt in ['-o', '--output']:
e94c2df
                 self.output = arg
e94c2df
             elif opt in ['--outputpath']:
e94c2df
-                print >>sys.stderr, 'Warning: This option is deprecated by --output.'
e94c2df
+                print('Warning: This option is deprecated by --output.', file=sys.stderr)
e94c2df
                 self.output = arg
e94c2df
             elif opt in ['--password']:
e94c2df
                 self.password = arg
e94c2df
@@ -615,13 +616,13 @@ class Options:
e94c2df
 
e94c2df
         ### Enable verbosity
e94c2df
         if self.verbose >= 2:
e94c2df
-            print >>sys.stderr, 'Verbosity set to level %d' % self.verbose
e94c2df
+            print('Verbosity set to level %d' % self.verbose, file=sys.stderr)
e94c2df
 
e94c2df
         self.filenames = args
e94c2df
 
e94c2df
         if not self.listener and not self.showlist and self.doctype != 'list' and not self.filenames:
e94c2df
-            print >>sys.stderr, 'unoconv: you have to provide a filename as argument'
e94c2df
-            print >>sys.stderr, 'Try `unoconv -h\' for more information.'
e94c2df
+            print('unoconv: you have to provide a filename as argument', file=sys.stderr)
e94c2df
+            print('Try `unoconv -h\' for more information.', file=sys.stderr)
e94c2df
             sys.exit(255)
e94c2df
 
e94c2df
         ### Set connection string
e94c2df
@@ -657,23 +658,23 @@ class Options:
e94c2df
 
e94c2df
     def version(self):
e94c2df
         ### Get office product information
e94c2df
-        product = uno.getComponentContext().ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
-
e94c2df
-        print 'unoconv %s' % VERSION
e94c2df
-        print 'Written by Dag Wieers <dag@wieers.com>'
e94c2df
-        print 'Homepage at http://dag.wieers.com/home-made/unoconv/'
e94c2df
-        print
e94c2df
-        print 'platform %s/%s' % (os.name, sys.platform)
e94c2df
-        print 'python %s' % sys.version
e94c2df
-        print product.ooName, product.ooSetupVersion
e94c2df
+        product = global_uno.getComponentContext().ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
+
e94c2df
+        print('unoconv %s' % VERSION)
e94c2df
+        print('Written by Dag Wieers <dag@wieers.com>')
e94c2df
+        print('Homepage at http://dag.wieers.com/home-made/unoconv/')
e94c2df
+        print()
e94c2df
+        print('platform %s/%s' % (os.name, sys.platform))
e94c2df
+        print('python %s' % sys.version)
e94c2df
+        print(product.ooName, product.ooSetupVersion)
e94c2df
 #        print
e94c2df
 #        print 'build revision $Rev$'
e94c2df
 
e94c2df
     def usage(self):
e94c2df
-        print >>sys.stderr, 'usage: unoconv [options] file [file2 ..]'
e94c2df
+        print('usage: unoconv [options] file [file2 ..]', file=sys.stderr)
e94c2df
 
e94c2df
     def help(self):
e94c2df
-        print >>sys.stderr, '''Convert from and to any format supported by LibreOffice
e94c2df
+        print('''Convert from and to any format supported by LibreOffice
e94c2df
 
e94c2df
 unoconv options:
e94c2df
   -c, --connection=string  use a custom connection string
e94c2df
@@ -698,7 +699,7 @@ unoconv options:
e94c2df
   -t, --template=file      import the styles from template (.ott)
e94c2df
   -T, --timeout=secs       timeout after secs if connection to listener fails
e94c2df
   -v, --verbose            be more and more verbose (-vvv for debugging)
e94c2df
-'''
e94c2df
+''', file=sys.stderr)
e94c2df
 
e94c2df
 class Convertor:
e94c2df
     def __init__(self):
e94c2df
@@ -706,7 +707,7 @@ class Convertor:
e94c2df
         unocontext = None
e94c2df
 
e94c2df
         ### Do the LibreOffice component dance
e94c2df
-        self.context = uno.getComponentContext()
e94c2df
+        self.context = global_uno.getComponentContext()
e94c2df
         self.svcmgr = self.context.ServiceManager
e94c2df
         resolver = self.svcmgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.context)
e94c2df
 
e94c2df
@@ -714,7 +715,7 @@ class Convertor:
e94c2df
         info(3, 'Connection type: %s' % op.connection)
e94c2df
         try:
e94c2df
             unocontext = resolver.resolve("uno:%s" % op.connection)
e94c2df
-        except NoConnectException, e:
e94c2df
+        except UnoNoConnectException as e:
e94c2df
 #            info(3, "Existing listener not found.\n%s" % e)
e94c2df
             info(3, "Existing listener not found.")
e94c2df
 
e94c2df
@@ -724,7 +725,7 @@ class Convertor:
e94c2df
             ### Start our own OpenOffice instance
e94c2df
             info(3, "Launching our own listener using %s." % office.binary)
e94c2df
             try:
e94c2df
-                product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
+                product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
                 if product.ooName != "LibreOffice" or LooseVersion(product.ooSetupVersion) <= LooseVersion('3.3'):
e94c2df
                     ooproc = subprocess.Popen([office.binary, "-headless", "-invisible", "-nocrashreport", "-nodefault", "-nofirststartwizard", "-nologo", "-norestore", "-accept=%s" % op.connection], env=os.environ)
e94c2df
                 else:
e94c2df
@@ -742,14 +743,14 @@ class Convertor:
e94c2df
                     try:
e94c2df
                         unocontext = resolver.resolve("uno:%s" % op.connection)
e94c2df
                         break
e94c2df
-                    except NoConnectException:
e94c2df
+                    except UnoNoConnectException:
e94c2df
                         time.sleep(0.5)
e94c2df
                         timeout += 0.5
e94c2df
                     except:
e94c2df
                         raise
e94c2df
                 else:
e94c2df
                     error("Failed to connect to %s (pid=%s) in %d seconds.\n%s" % (office.binary, ooproc.pid, op.timeout, e))
e94c2df
-            except Exception, e:
e94c2df
+            except Exception as e:
e94c2df
                 raise
e94c2df
                 error("Launch of %s failed.\n%s" % (office.binary, e))
e94c2df
 
e94c2df
@@ -759,7 +760,7 @@ class Convertor:
e94c2df
         ### And some more LibreOffice magic
e94c2df
         unosvcmgr = unocontext.ServiceManager
e94c2df
         self.desktop = unosvcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", unocontext)
e94c2df
-        self.cwd = unohelper.systemPathToFileUrl( os.getcwd() )
e94c2df
+        self.cwd = global_unohelper.systemPathToFileUrl( os.getcwd() )
e94c2df
 
e94c2df
         ### List all filters
e94c2df
 #        self.filters = unosvcmgr.createInstanceWithContext( "com.sun.star.document.FilterFactory", unocontext)
e94c2df
@@ -799,9 +800,9 @@ class Convertor:
e94c2df
         ### No format found, throw error
e94c2df
         if not outputfmt:
e94c2df
             if doctype:
e94c2df
-                print >>sys.stderr, 'unoconv: format [%s/%s] is not known to unoconv.' % (op.doctype, op.format)
e94c2df
+                print('unoconv: format [%s/%s] is not known to unoconv.' % (op.doctype, op.format), file=sys.stderr)
e94c2df
             else:
e94c2df
-                print >>sys.stderr, 'unoconv: format [%s] is not known to unoconv.' % op.format
e94c2df
+                print('unoconv: format [%s] is not known to unoconv.' % op.format, file=sys.stderr)
e94c2df
             die(1)
e94c2df
 
e94c2df
         return outputfmt
e94c2df
@@ -813,10 +814,10 @@ class Convertor:
e94c2df
         outputfmt = self.getformat(inputfn)
e94c2df
 
e94c2df
         if op.verbose > 0:
e94c2df
-            print >>sys.stderr, 'Input file:', inputfn
e94c2df
+            print('Input file:', inputfn, file=sys.stderr)
e94c2df
 
e94c2df
         if not os.path.exists(inputfn):
e94c2df
-            print >>sys.stderr, 'unoconv: file `%s\' does not exist.' % inputfn
e94c2df
+            print('unoconv: file `%s\' does not exist.' % inputfn, file=sys.stderr)
e94c2df
             exitcode = 1
e94c2df
 
e94c2df
         try:
e94c2df
@@ -824,22 +825,22 @@ class Convertor:
e94c2df
             phase = "import"
e94c2df
 
e94c2df
             ### Load inputfile
e94c2df
-            inputprops = UnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=QUIET_UPDATE)
e94c2df
+            inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=UNO_QUIET_UPDATE)
e94c2df
 
e94c2df
 #            if op.password:
e94c2df
-#                info = UnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
e94c2df
-#                inputprops += UnoProps(ModifyPasswordInfo=info)
e94c2df
+#                info = GlobalUnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
e94c2df
+#                inputprops += GlobalUnoProps(ModifyPasswordInfo=info)
e94c2df
 
e94c2df
-            ### Cannot use UnoProps for FilterData property
e94c2df
+            ### Cannot use GlobalUnoProps for FilterData property
e94c2df
             if op.importfilteroptions:
e94c2df
 #                print "Import filter options: %s" % op.importfilteroptions
e94c2df
-                inputprops += UnoProps(FilterOptions=op.importfilteroptions)
e94c2df
+                inputprops += GlobalUnoProps(FilterOptions=op.importfilteroptions)
e94c2df
 
e94c2df
-            ### Cannot use UnoProps for FilterData property
e94c2df
+            ### Cannot use GlobalUnoProps for FilterData property
e94c2df
             if op.importfilter:
e94c2df
-                inputprops += ( PropertyValue( "FilterData", 0, uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.importfilter ), ), 0 ), )
e94c2df
+                inputprops += ( UnoPropertyValue( "FilterData", 0, global_uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.importfilter ), ), 0 ), )
e94c2df
 
e94c2df
-            inputurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(inputfn))
e94c2df
+            inputurl = global_unohelper.absolutize(self.cwd, global_unohelper.systemPathToFileUrl(inputfn))
e94c2df
             document = self.desktop.loadComponentFromURL( inputurl , "_blank", 0, inputprops )
e94c2df
 
e94c2df
             if not document:
e94c2df
@@ -850,11 +851,11 @@ class Convertor:
e94c2df
             if op.template:
e94c2df
                 if os.path.exists(op.template):
e94c2df
                     info(1, "Template file: %s" % op.template)
e94c2df
-                    templateprops = UnoProps(OverwriteStyles=True)
e94c2df
-                    templateurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(op.template))
e94c2df
+                    templateprops = GlobalUnoProps(OverwriteStyles=True)
e94c2df
+                    templateurl = global_unohelper.absolutize(self.cwd, global_unohelper.systemPathToFileUrl(op.template))
e94c2df
                     document.StyleFamilies.loadStylesFromURL(templateurl, templateprops)
e94c2df
                 else:
e94c2df
-                    print >>sys.stderr, 'unoconv: template file `%s\' does not exist.' % op.template
e94c2df
+                    print('unoconv: template file `%s\' does not exist.' % op.template, file=sys.stderr)
e94c2df
                     exitcode = 1
e94c2df
 
e94c2df
             ### Update document links
e94c2df
@@ -885,26 +886,26 @@ class Convertor:
e94c2df
             ### Export phase
e94c2df
             phase = "export"
e94c2df
 
e94c2df
-            outputprops = UnoProps(FilterName=outputfmt.filter, OutputStream=OutputStream(), Overwrite=True)
e94c2df
+            outputprops = GlobalUnoProps(FilterName=outputfmt.filter, OutputStream=GlobalOutputStream(), Overwrite=True)
e94c2df
 
e94c2df
             ### Set default filter options
e94c2df
             if op.exportfilteroptions:
e94c2df
 #                print "Export filter options: %s" % op.exportfilteroptions
e94c2df
-                outputprops += UnoProps(FilterOptions=op.exportfilteroptions)
e94c2df
+                outputprops += GlobalUnoProps(FilterOptions=op.exportfilteroptions)
e94c2df
             else:
e94c2df
                 if outputfmt.filter == 'Text (encoded)':
e94c2df
-                    outputprops += UnoProps(FilterOptions="76,LF")
e94c2df
+                    outputprops += GlobalUnoProps(FilterOptions="76,LF")
e94c2df
 
e94c2df
                 elif outputfmt.filter == 'Text':
e94c2df
-                    outputprops += UnoProps(FilterOptions="76")
e94c2df
+                    outputprops += GlobalUnoProps(FilterOptions="76")
e94c2df
 
e94c2df
                 elif outputfmt.filter == 'Text - txt - csv (StarCalc)':
e94c2df
-                    outputprops += UnoProps(FilterOptions="44,34,76")
e94c2df
+                    outputprops += GlobalUnoProps(FilterOptions="44,34,76")
e94c2df
 
e94c2df
 
e94c2df
-            ### Cannot use UnoProps for FilterData property
e94c2df
+            ### Cannot use GlobalUnoProps for FilterData property
e94c2df
             if op.exportfilter:
e94c2df
-                outputprops += ( PropertyValue( "FilterData", 0, uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.exportfilter ), ), 0 ), )
e94c2df
+                outputprops += ( UnoPropertyValue( "FilterData", 0, global_uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.exportfilter ), ), 0 ), )
e94c2df
 
e94c2df
             if not op.stdout:
e94c2df
                 (outputfn, ext) = os.path.splitext(inputfn)
e94c2df
@@ -917,47 +918,47 @@ class Convertor:
e94c2df
                 else:
e94c2df
                     outputfn = op.output
e94c2df
 
e94c2df
-                outputurl = unohelper.absolutize( self.cwd, unohelper.systemPathToFileUrl(outputfn) )
e94c2df
+                outputurl = global_unohelper.absolutize( self.cwd, global_unohelper.systemPathToFileUrl(outputfn) )
e94c2df
                 info(1, "Output file: %s" % outputfn)
e94c2df
             else:
e94c2df
                 outputurl = "private:stream"
e94c2df
 
e94c2df
             try:
e94c2df
                 document.storeToURL(outputurl, tuple(outputprops) )
e94c2df
-            except IOException, e:
e94c2df
+            except UnoIOException as e:
e94c2df
                 raise UnoException("Unable to store document to %s (ErrCode %d)\n\nProperties: %s" % (outputurl, e.ErrCode, outputprops), None)
e94c2df
 
e94c2df
             phase = "dispose"
e94c2df
             document.dispose()
e94c2df
             document.close(True)
e94c2df
 
e94c2df
-        except SystemError, e:
e94c2df
+        except SystemError as e:
e94c2df
             error("unoconv: SystemError during %s phase:\n%s" % (phase, e))
e94c2df
             exitcode = 1
e94c2df
 
e94c2df
-        except RuntimeException, e:
e94c2df
+        except UnoRuntimeException as e:
e94c2df
             error("unoconv: RuntimeException during %s phase:\nOffice probably died. %s" % (phase, e))
e94c2df
             exitcode = 6
e94c2df
 
e94c2df
-        except DisposedException, e:
e94c2df
+        except UnoDisposedException as e:
e94c2df
             error("unoconv: DisposedException during %s phase:\nOffice probably died. %s" % (phase, e))
e94c2df
             exitcode = 7
e94c2df
 
e94c2df
-        except IllegalArgumentException, e:
e94c2df
+        except UnoIllegalArgumentException as e:
e94c2df
             error("UNO IllegalArgument during %s phase:\nSource file cannot be read. %s" % (phase, e))
e94c2df
             exitcode = 8
e94c2df
 
e94c2df
-        except IOException, e:
e94c2df
+        except UnoIOException as e:
e94c2df
 #            for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
e94c2df
             error("unoconv: IOException during %s phase:\n%s" % (phase, e.Message))
e94c2df
             exitcode = 3
e94c2df
 
e94c2df
-        except CannotConvertException, e:
e94c2df
+        except UnoCannotConvertException as e:
e94c2df
 #            for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
e94c2df
             error("unoconv: CannotConvertException during %s phase:\n%s" % (phase, e.Message))
e94c2df
             exitcode = 4
e94c2df
 
e94c2df
-        except UnoException, e:
e94c2df
+        except UnoException as e:
e94c2df
             if hasattr(e, 'ErrCode'):
e94c2df
                 error("unoconv: UnoException during %s phase in %s (ErrCode %d)" % (phase, repr(e.__class__), e.ErrCode))
e94c2df
                 exitcode = e.ErrCode
e94c2df
@@ -975,14 +976,14 @@ class Listener:
e94c2df
         global product
e94c2df
 
e94c2df
         info(1, "Start listener on %s:%s" % (op.server, op.port))
e94c2df
-        self.context = uno.getComponentContext()
e94c2df
+        self.context = global_uno.getComponentContext()
e94c2df
         self.svcmgr = self.context.ServiceManager
e94c2df
         try:
e94c2df
             resolver = self.svcmgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.context)
e94c2df
-            product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
+            product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
e94c2df
             try:
e94c2df
                 unocontext = resolver.resolve("uno:%s" % op.connection)
e94c2df
-            except NoConnectException, e:
e94c2df
+            except UnoNoConnectException as e:
e94c2df
                 pass
e94c2df
             else:
e94c2df
                 info(1, "Existing %s listener found, nothing to do." % product.ooName)
e94c2df
@@ -991,25 +992,25 @@ class Listener:
e94c2df
                 subprocess.call([office.binary, "-headless", "-invisible", "-nocrashreport", "-nodefault", "-nologo", "-nofirststartwizard", "-norestore", "-accept=%s" % op.connection], env=os.environ)
e94c2df
             else:
e94c2df
                 subprocess.call([office.binary, "--headless", "--invisible", "--nocrashreport", "--nodefault", "--nologo", "--nofirststartwizard", "--norestore", "--accept=%s" % op.connection], env=os.environ)
e94c2df
-        except Exception, e:
e94c2df
+        except Exception as e:
e94c2df
             error("Launch of %s failed.\n%s" % (office.binary, e))
e94c2df
         else:
e94c2df
             info(1, "Existing %s listener found, nothing to do." % product.ooName)
e94c2df
 
e94c2df
 def error(msg):
e94c2df
     "Output error message"
e94c2df
-    print >>sys.stderr, msg
e94c2df
+    print(msg, file=sys.stderr)
e94c2df
 
e94c2df
 def info(level, msg):
e94c2df
     "Output info message"
e94c2df
     if 'op' not in globals():
e94c2df
         pass
e94c2df
     elif op.verbose >= 3 and level >= 3:
e94c2df
-        print >>sys.stderr, "DEBUG:", msg
e94c2df
+        print("DEBUG:", msg, file=sys.stderr)
e94c2df
     elif not op.stdout and level <= op.verbose:
e94c2df
-        print >>sys.stdout, msg
e94c2df
+        print(msg, file=sys.stdout)
e94c2df
     elif level <= op.verbose:
e94c2df
-        print >>sys.stderr, msg
e94c2df
+        print(msg, file=sys.stderr)
e94c2df
 
e94c2df
 def die(ret, msg=None):
e94c2df
     "Print optional error and exit with errorcode"
e94c2df
@@ -1031,7 +1032,7 @@ def die(ret, msg=None):
e94c2df
                     subprocess.Popen([office.binary, "--headless", "--invisible", "--nocrashreport", "--nodefault", "--nofirststartwizard", "--nologo", "--norestore", "--unaccept=%s" % op.connection], env=os.environ)
e94c2df
                 ooproc.wait()
e94c2df
                 info(2, '%s listener successfully disabled.' % product.ooName)
e94c2df
-            except Exception, e:
e94c2df
+            except Exception as e:
e94c2df
                 error("Terminate using %s failed.\n%s" % (office.binary, e))
e94c2df
 
e94c2df
         ### If there is no GUI attached to the instance, terminate instance
e94c2df
@@ -1039,7 +1040,7 @@ def die(ret, msg=None):
e94c2df
             info(3, 'Terminating %s instance.' % product.ooName)
e94c2df
             try:
e94c2df
                 convertor.desktop.terminate()
e94c2df
-            except DisposedException:
e94c2df
+            except UnoDisposedException:
e94c2df
                 info(2, '%s instance unsuccessfully closed, sending TERM signal.' % product.ooName)
e94c2df
                 try:
e94c2df
                     ooproc.terminate()
e94c2df
@@ -1080,7 +1081,7 @@ def main():
e94c2df
             for inputfn in op.filenames:
e94c2df
                 convertor.convert(inputfn)
e94c2df
 
e94c2df
-    except NoConnectException, e:
e94c2df
+    except UnoNoConnectException as e:
e94c2df
         error("unoconv: could not find an existing connection to LibreOffice at %s:%s." % (op.server, op.port))
e94c2df
         if op.connection:
e94c2df
             info(0, "Please start an LibreOffice instance on server '%s' by doing:\n\n    unoconv --listener --server %s --port %s\n\nor alternatively:\n\n    soffice -nologo -nodefault -accept=\"%s\"" % (op.server, op.server, op.port, op.connection))
e94c2df
@@ -1094,7 +1095,8 @@ def main():
e94c2df
         error("Warning: failed to launch Office suite. Aborting.")
e94c2df
 
e94c2df
 ### Main entrance
e94c2df
-if __name__ == '__main__':
e94c2df
+def run():
e94c2df
+    global exitcode
e94c2df
     exitcode = 0
e94c2df
 
e94c2df
     info(3, 'sysname=%s, platform=%s, python=%s, python-version=%s' % (os.name, sys.platform, sys.executable, sys.version))
e94c2df
@@ -1105,33 +1107,51 @@ if __name__ == '__main__':
e94c2df
         office_environ(of)
e94c2df
 #        debug_office()
e94c2df
         try:
e94c2df
-            import uno, unohelper
e94c2df
+            global global_uno
e94c2df
+            global global_unohelper
e94c2df
+
e94c2df
+            import uno as global_uno
e94c2df
+            import unohelper as global_unohelper
e94c2df
+            global office
e94c2df
             office = of
e94c2df
             break
e94c2df
         except:
e94c2df
 #            debug_office()
e94c2df
-            print >>sys.stderr, "unoconv: Cannot find a suitable pyuno library and python binary combination in %s" % of
e94c2df
-            print >>sys.stderr, "ERROR:", sys.exc_info()[1]
e94c2df
-            print >>sys.stderr
e94c2df
+            print("unoconv: Cannot find a suitable pyuno library and python binary combination in %s" % of, file=sys.stderr)
e94c2df
+            print("ERROR:", sys.exc_info()[1], file=sys.stderr)
e94c2df
+            print(file=sys.stderr)
e94c2df
     else:
e94c2df
 #        debug_office()
e94c2df
-        print >>sys.stderr, "unoconv: Cannot find a suitable office installation on your system."
e94c2df
-        print >>sys.stderr, "ERROR: Please locate your office installation and send your feedback to:"
e94c2df
-        print >>sys.stderr, "       http://github.com/dagwieers/unoconv/issues"
e94c2df
+        print("unoconv: Cannot find a suitable office installation on your system.", file=sys.stderr)
e94c2df
+        print("ERROR: Please locate your office installation and send your feedback to:", file=sys.stderr)
e94c2df
+        print("       http://github.com/dagwieers/unoconv/issues", file=sys.stderr)
e94c2df
         sys.exit(1)
e94c2df
 
e94c2df
     ### Now that we have found a working pyuno library, let's import some classes
e94c2df
-    from com.sun.star.beans import PropertyValue
e94c2df
-    from com.sun.star.connection import NoConnectException
e94c2df
-    from com.sun.star.document.UpdateDocMode import QUIET_UPDATE
e94c2df
-    from com.sun.star.lang import DisposedException, IllegalArgumentException
e94c2df
-    from com.sun.star.io import IOException, XOutputStream
e94c2df
-    from com.sun.star.script import CannotConvertException
e94c2df
+    global UnoPropertyValue
e94c2df
+    global UnoNoConnectException
e94c2df
+    global UNO_QUIET_UPDATE
e94c2df
+    global UnoDisposedException
e94c2df
+    global UnoIllegalArgumentException
e94c2df
+    global UnoIOException
e94c2df
+    global UnoXOutputStream
e94c2df
+    global UnoCannotConvertException
e94c2df
+    global UnoException
e94c2df
+    global UnoRuntimeException
e94c2df
+
e94c2df
+    from com.sun.star.beans import PropertyValue as UnoPropertyValue
e94c2df
+    from com.sun.star.connection import NoConnectException as UnoNoConnectException
e94c2df
+    from com.sun.star.document.UpdateDocMode import QUIET_UPDATE as UNO_QUIET_UPDATE
e94c2df
+    from com.sun.star.lang import DisposedException as UnoDisposedException
e94c2df
+    from com.sun.star.lang import IllegalArgumentException as UnoIllegalArgumentException
e94c2df
+    from com.sun.star.io import IOException as UnoIOException
e94c2df
+    from com.sun.star.io import XOutputStream as UnoXOutputStream
e94c2df
+    from com.sun.star.script import CannotConvertException as UnoCannotConvertException
e94c2df
     from com.sun.star.uno import Exception as UnoException
e94c2df
-    from com.sun.star.uno import RuntimeException
e94c2df
+    from com.sun.star.uno import RuntimeException as UnoRuntimeException
e94c2df
 
e94c2df
     ### And now that we have those classes, build on them
e94c2df
-    class OutputStream( unohelper.Base, XOutputStream ):
e94c2df
+    class OutputStream( global_unohelper.Base, UnoXOutputStream ):
e94c2df
         def __init__( self ):
e94c2df
             self.closed = 0
e94c2df
 
e94c2df
@@ -1144,15 +1164,22 @@ if __name__ == '__main__':
e94c2df
         def flush( self ):
e94c2df
             pass
e94c2df
 
e94c2df
+    global GlobalOutputStream
e94c2df
+    GlobalOutputStream = OutputStream
e94c2df
+
e94c2df
     def UnoProps(**args):
e94c2df
         props = []
e94c2df
         for key in args:
e94c2df
-            prop = PropertyValue()
e94c2df
+            prop = UnoPropertyValue()
e94c2df
             prop.Name = key
e94c2df
             prop.Value = args[key]
e94c2df
             props.append(prop)
e94c2df
         return tuple(props)
e94c2df
 
e94c2df
+    global GlobalUnoProps
e94c2df
+    GlobalUnoProps = UnoProps
e94c2df
+
e94c2df
+    global op
e94c2df
     op = Options(sys.argv[1:])
e94c2df
 
e94c2df
     info(2, "Using office base path: %s" % office.basepath)
e94c2df
@@ -1160,6 +1187,9 @@ if __name__ == '__main__':
e94c2df
 
e94c2df
     try:
e94c2df
         main()
e94c2df
-    except KeyboardInterrupt, e:
e94c2df
+    except KeyboardInterrupt as e:
e94c2df
         die(6, 'Exiting on user request')
e94c2df
     die(exitcode)
e94c2df
+
e94c2df
+if __name__ == '__main__':
e94c2df
+    run()
e94c2df
-- 
e94c2df
1.9.0
e94c2df