File python3-to-python2.diff of Package system-config-printer

Index: system-config-printer-1.5.7/applet.py
===================================================================
--- system-config-printer-1.5.7.orig/applet.py
+++ system-config-printer-1.5.7/applet.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
 ## Author: Tim Waugh <twaugh@redhat.com>
@@ -326,8 +326,8 @@ class RunLoop:
                                             dbus_interface=self.DBUS_IFACE)
         except dbus.DBusException as e:
             try:
-                print ("%s: failed to add D-Bus signal receiver: %s" \
-                        % (PROGRAM_NAME, e), file=sys.stderr)
+                print >> sys.stderr, ("%s: failed to add D-Bus signal receiver: %s" \
+                        % (PROGRAM_NAME, e))
             finally:
                 sys.exit (1)
 
@@ -340,8 +340,8 @@ class RunLoop:
                                                     dbus_interface=self.DBUS_IFACE)
         except dbus.DBusException as e:
             try:
-                print ("%s: failed to remove D-Bus signal receiver: %s" \
-                        % (PROGRAM_NAME, e), file=sys.stderr)
+                print >> sys.stderr, ("%s: failed to remove D-Bus signal receiver: %s" \
+                        % (PROGRAM_NAME, e))
             except:
                 pass
 
@@ -406,8 +406,8 @@ if __name__ == '__main__':
     # Must be done before connecting to D-Bus (for some reason).
     if not Notify.init (PROGRAM_NAME):
         try:
-            print(("%s: unable to initialize pynotify" %
-                                  PROGRAM_NAME), file=sys.stderr)
+            print >> sys.stderr, ("%s: unable to initialize pynotify" %
+                                  PROGRAM_NAME)
         except:
             pass
 
@@ -416,8 +416,8 @@ if __name__ == '__main__':
         system_bus = dbus.SystemBus()
     except:
         try:
-            print(("%s: failed to connect to system D-Bus" %
-                                  PROGRAM_NAME), file=sys.stderr)
+            print >> sys.stderr, ("%s: failed to connect to system D-Bus" %
+                                  PROGRAM_NAME)
         finally:
             sys.exit (1)
 
@@ -427,8 +427,8 @@ if __name__ == '__main__':
         session_bus.add_signal_receiver (monitor_session)
     except:
         try:
-            print(("%s: failed to connect to "
-                                  "session D-Bus" % PROGRAM_NAME), file=sys.stderr)
+            print >> sys.stderr, ("%s: failed to connect to "
+                                  "session D-Bus" % PROGRAM_NAME)
         finally:
             sys.exit (1)
 
@@ -436,9 +436,9 @@ if __name__ == '__main__':
         NewPrinterNotification(system_bus, session_bus)
     except:
         try:
-            print(("%s: failed to start "
+            print >> sys.stderr, ("%s: failed to start "
                                   "NewPrinterNotification service" %
-                                  PROGRAM_NAME), file=sys.stderr)
+                                  PROGRAM_NAME)
         except:
             pass
 
@@ -447,9 +447,9 @@ if __name__ == '__main__':
         cupshelpers.installdriver.PrinterDriversInstaller(system_bus)
     except Exception as e:
         try:
-            print(("%s: failed to start "
+            print >> sys.stderr, ("%s: failed to start "
                                   "PrinterDriversInstaller service: "
-                                  "%s" % (PROGRAM_NAME, e)), file=sys.stderr)
+                                  "%s" % (PROGRAM_NAME, e))
         except:
             pass
 
Index: system-config-printer-1.5.7/asyncconn.py
===================================================================
--- system-config-printer-1.5.7.orig/asyncconn.py
+++ system-config-printer-1.5.7/asyncconn.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2012, 2013 Red Hat, Inc.
 ## Copyright (C) 2008 Novell, Inc.
Index: system-config-printer-1.5.7/asyncipp.py
===================================================================
--- system-config-printer-1.5.7.orig/asyncipp.py
+++ system-config-printer-1.5.7/asyncipp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015 Red Hat, Inc.
 ## Copyright (C) 2008 Novell, Inc.
@@ -25,7 +25,7 @@ from gi.repository import GObject
 from gi.repository import GLib
 from gi.repository import Gdk
 from gi.repository import Gtk
-import queue
+import Queue as queue
 
 cups.require ("1.9.60")
 
Index: system-config-printer-1.5.7/asyncpk1.py
===================================================================
--- system-config-printer-1.5.7.orig/asyncpk1.py
+++ system-config-printer-1.5.7/asyncpk1.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2012, 2013, 2014 Red Hat, Inc.
 ## Copyright (C) 2008 Novell, Inc.
Index: system-config-printer-1.5.7/authconn.py
===================================================================
--- system-config-printer-1.5.7.orig/authconn.py
+++ system-config-printer-1.5.7/authconn.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013, 2014 Red Hat, Inc.
 ## Author: Tim Waugh <twaugh@redhat.com>
@@ -250,6 +250,8 @@ class Connection:
                 break
             except cups.IPPError as e:
                 (e, m) = e.args
+                if isinstance(m, bytes):
+                    m = m.decode('utf-8', 'replace')
                 if self._use_pk and m == 'pkcancel':
                     raise cups.IPPError (0, _("Operation canceled"))
 
Index: system-config-printer-1.5.7/check-device-ids.py
===================================================================
--- system-config-printer-1.5.7.orig/check-device-ids.py
+++ system-config-printer-1.5.7/check-device-ids.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## check-device-ids
 
@@ -54,6 +54,8 @@ elif len (sys.argv) == 2:
             attrs = c.getPrinterAttributes (sys.argv[1])
         except cups.IPPError as e:
             (e, m) = e.args
+            if isinstance(m, bytes):
+                m = m.decode('utf-8', 'replace')
             print("Error getting printer attibutes: %s" % m)
             sys.exit (1)
 
@@ -235,8 +237,8 @@ def driver_uri_to_pkg (uri):
 
 i = 1
 if sys.stdout.encoding == 'UTF-8':
-    item = chr (0x251c) + chr (0x2500) + chr (0x2500)
-    last = chr (0x2514) + chr (0x2500) + chr (0x2500)
+    item = unichr (0x251c) + unichr (0x2500) + unichr (0x2500)
+    last = unichr (0x2514) + unichr (0x2500) + unichr (0x2500)
 else:
     item = "|--"
     last = "`--"
@@ -275,7 +277,7 @@ for device, attrs in devices.items ():
         drivers = []
 
     if i < n:
-        more = chr (0x2502)
+        more = unichr (0x2502)
     else:
         more = " "
 
Index: system-config-printer-1.5.7/cupshelpers/cupshelpers.py
===================================================================
--- system-config-printer-1.5.7.orig/cupshelpers/cupshelpers.py
+++ system-config-printer-1.5.7/cupshelpers/cupshelpers.py
@@ -19,7 +19,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-import cups, pprint, os, tempfile, re, string
+import cups, pprint, os, tempfile, re, string, sys
 import locale
 from . import _debugprint
 from . import config
@@ -527,6 +527,12 @@ class Device:
         self.id = kw.get('device-id', '')
         self.location = kw.get('device-location', '')
 
+        if sys.version_info < (3,0,0):
+           if type (self.info) == unicode:
+               # Convert unicode objects to UTF-8 encoding so they can be
+               # compared with other UTF-8 encoded strings (bug #957444).
+               self.info = self.info.encode ('utf-8')
+
         uri_pieces = uri.split(":")
         self.type =  uri_pieces[0]
         self.is_class = len(uri_pieces)==1
Index: system-config-printer-1.5.7/cupshelpers/installdriver.py
===================================================================
--- system-config-printer-1.5.7.orig/cupshelpers/installdriver.py
+++ system-config-printer-1.5.7/cupshelpers/installdriver.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/cupshelpers/openprinting.py
===================================================================
--- system-config-printer-1.5.7.orig/cupshelpers/openprinting.py
+++ system-config-printer-1.5.7/cupshelpers/openprinting.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -19,8 +19,14 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-import requests, urllib.request, urllib.parse, urllib.error, platform, threading, tempfile, traceback
 import os, sys
+import pycurl, platform, threading, tempfile, traceback
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+   import requests, urllib.request, urllib.error
+else:
+   import urlparse
+   import urllib
 from xml.etree.ElementTree import XML
 from . import Device
 from . import _debugprint
@@ -52,6 +58,13 @@ class _QueryThread (threading.Thread):
         _debugprint ("-%s" % self)
 
     def run (self):
+
+        # Callback function for pycURL collecting the data coming from
+        # the web server
+        def collect_data(result):
+            self.result += result;
+            return len(result)
+
         ## Disabled on openSUSE, see discussion in https://bugzilla.novell.com/show_bug.cgi?id=733542
         if self.callback != None:
             self.callback (403, self.user_data, None)
@@ -63,7 +76,7 @@ class _QueryThread (threading.Thread):
         headers = {"Content-type": "application/x-www-form-urlencoded",
                    "Accept": "text/plain"}
         params = ("%s&uilanguage=%s&locale=%s" %
-                  (urllib.parse.urlencode (self.parameters),
+                  (urllib.urlencode (self.parameters),
                    self.parent.language[0],
                    self.parent.language[0]))
         self.url = "https://%s%s?%s" % (self.parent.base_url, query_command, params)
@@ -72,9 +85,20 @@ class _QueryThread (threading.Thread):
         self.result = b''
         status = 1
         try:
-            req = requests.get(self.url, verify=True)
-            self.result = req.content
-            status = 0
+            if sys.version_info >= (3,0,0):
+                req = requests.get(self.url, verify=True)
+                self.result = req.content
+                status = 0
+            else:
+                curl = pycurl.Curl()
+                curl.setopt(pycurl.SSL_VERIFYPEER, 1)
+                curl.setopt(pycurl.SSL_VERIFYHOST, 2)
+                curl.setopt(pycurl.WRITEFUNCTION, collect_data)
+                curl.setopt(pycurl.URL, self.url)
+                status = curl.perform()
+                if status == None: status = 0
+                if (status != 0):
+                    self.result = sys.exc_info ()
         except:
             self.result = sys.exc_info ()
             if status == None: status = 0
@@ -269,6 +293,13 @@ class OpenPrinting:
                 # There is more information in the raw XML, but this
                 # can be added to the Python structure as needed.
 
+                # Callback function for pycURL collecting the data coming from
+                # the web server
+                def collect_licensedata(result):
+                    self.licensetext += result;
+                    return len(result)
+
+
                 for driver in root.findall ('driver'):
                     id = driver.attrib.get ('id')
                     if id == None:
@@ -290,12 +321,22 @@ class OpenPrinting:
                         if element != None:
                             license_url = element.text
                             if license_url != None:
+                                self.license_text = b''
                                 try:
-                                    req = requests.get(license_url, verify=True)
-                                    dict['licensetext'] = \
-                                        req.content.decode("utf-8")
+                                    if sys.version_info >= (3,0,0):
+                                        req = requests.get(license_url, verify=True)
+                                        dict['licensetext'] = \
+                                            req.content.decode("utf-8")
+                                    else:
+                                        curl = pycurl.Curl()
+                                        curl.setopt(pycurl.SSL_VERIFYPEER, 1)
+                                        curl.setopt(pycurl.SSL_VERIFYHOST, 2)
+                                        curl.setopt(pycurl.WRITEFUNCTION, collect_licensedata)
+                                        curl.setopt(pycurl.URL, license_url)
+                                        status = curl.perform()
+                                        if status == None: status = 0
                                 except:
-                                    _debugprint('Cannot retrieve %s' % url)
+                                    _debugprint('Cannot retrieve %s' % license_url)
 
                     for boolean in ['nonfreesoftware', 'recommended',
                                     'patents', 'thirdpartysupplied',
Index: system-config-printer-1.5.7/cupshelpers/ppds.py
===================================================================
--- system-config-printer-1.5.7.orig/cupshelpers/ppds.py
+++ system-config-printer-1.5.7/cupshelpers/ppds.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -1278,7 +1278,7 @@ def _self_test(argv):
         ]
 
     if stdin_deviceid:
-        idlist = [(input ('Device ID: '), 2, '')]
+        idlist = [(raw_input ('Device ID: '), 2, '')]
 
     all_passed = True
     for id, max_status_code, modelre in idlist:
Index: system-config-printer-1.5.7/cupshelpers/xmldriverprefs.py
===================================================================
--- system-config-printer-1.5.7.orig/cupshelpers/xmldriverprefs.py
+++ system-config-printer-1.5.7/cupshelpers/xmldriverprefs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -20,6 +20,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 import fnmatch
 import re
 import xml.etree.ElementTree
@@ -520,6 +521,7 @@ def test (xml_path=None, attached=False,
         ppds.set_debugprint_fn (debugprint)
             
     locale.setlocale (locale.LC_ALL, "")
+    encoding = locale.getlocale (locale.LC_CTYPE)[1]
     if xml_path == None:
         xml_path = os.path.join (os.path.join (os.path.dirname (__file__),
                                                ".."),
@@ -610,7 +612,10 @@ def test (xml_path=None, attached=False,
 
                 orderedppds = drivertypes.get_ordered_ppdnames (orderedtypes,
                                                                 ppdsdict, fit)
-                print(mm + ":")
+                if sys.version_info >= (3,0,0):
+                   print(mm + ":")
+                else:
+                   print(mm.encode (encoding) + ":")
                 i = 1
                 for t, ppd in orderedppds:
                     print("%d  %s\n    (%s)" % (i, ppd, t))
Index: system-config-printer-1.5.7/cupspk.py
===================================================================
--- system-config-printer-1.5.7.orig/cupspk.py
+++ system-config-printer-1.5.7/cupspk.py
@@ -164,6 +164,9 @@ class Connection:
                     # we accept a mix between int and str
                     retval.append(str(args[i]))
                     continue
+                elif sys.version_info < (3,0,0) and types[i] == str and type(args[i]) == unicode:
+                    # we accept a mix between unicode and str
+                    pass
                 elif types[i] == str and type(args[i]) == float:
                     # we accept a mix between float and str
                     retval.append(str(args[i]))
Index: system-config-printer-1.5.7/debug.py
===================================================================
--- system-config-printer-1.5.7.orig/debug.py
+++ system-config-printer-1.5.7/debug.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2008, 2010 Red Hat, Inc.
 ## Authors:
Index: system-config-printer-1.5.7/dnssdresolve.py
===================================================================
--- system-config-printer-1.5.7.orig/dnssdresolve.py
+++ system-config-printer-1.5.7/dnssdresolve.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
 ## Authors:
@@ -18,8 +18,13 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-import dbus, re
-import urllib.parse
+import dbus, re, sys
+if sys.version_info >= (3,0,0):
+  import urllib.parse as urlparse
+else:
+  import urlparse
+  import urllib
+
 from debug import *
 
 class DNSSDHostNamesResolver:
@@ -50,7 +55,7 @@ class DNSSDHostNamesResolver:
 
             # We need to resolve the DNS-SD hostname in order to
             # compare with other network devices.
-            result = urllib.parse.urlparse (uri)
+            result = urlparse.urlparse (uri)
             hostname = result.netloc
             elements = hostname.rsplit (".", 3)
             if len (elements) != 4:
@@ -58,7 +63,11 @@ class DNSSDHostNamesResolver:
                 continue
 
             name, stype, protocol, domain = elements
-            name = urllib.parse.unquote (name)
+
+            if sys.version_info >= (3,0,0):
+                name = urlparse.unquote (name)
+            else:
+                name = urllib.unquote (name)
             stype += "." + protocol #  e.g. _printer._tcp
 
             try:
@@ -87,7 +96,7 @@ class DNSSDHostNamesResolver:
 
     def _reply (self, interface, protocol, name, stype, domain,
                 host, aprotocol, address, port, txt, flags):
-        uri = self._device_uri_by_name[(name, stype, domain)]
+        uri = self._device_uri_by_name[(name.encode ('utf-8'), stype, domain)]
         self._devices[uri].address = address
         hostname = host
         p = hostname.find(".")
Index: system-config-printer-1.5.7/errordialogs.py
===================================================================
--- system-config-printer-1.5.7.orig/errordialogs.py
+++ system-config-printer-1.5.7/errordialogs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -21,6 +21,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 import config
 import cups
 from gi.repository import Gtk
@@ -51,6 +52,10 @@ def show_IPP_Error(exception, message, p
         # In this case, the user has canceled a retry dialog.
         return
     else:
+        if sys.version_info >= (3,0,0):
+            # cups.IPPError message is utf-8 encoded
+            if isinstance(message, bytes):
+                message = message.decode ('utf-8', 'replace')
         title = _("CUPS server error")
         text = _("There was an error during the CUPS "
                  "operation: '%s'.") % message
Index: system-config-printer-1.5.7/firewallsettings.py
===================================================================
--- system-config-printer-1.5.7.orig/firewallsettings.py
+++ system-config-printer-1.5.7/firewallsettings.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -183,7 +183,7 @@ class SystemConfigFirewall:
                     return
 
                 p = self._fw.read ()
-                self._fw_data = json.loads (p)
+                self._fw_data = json.loads (p.encode ('utf-8'))
             except (dbus.exceptions.DBusException, AttributeError, ValueError) as e:
                 self._fw_data = (None, None)
                 if error_handler:
@@ -203,7 +203,7 @@ class SystemConfigFirewall:
 
     def reply_handler (self, result):
         try:
-            self._fw_data = json.loads (result)
+            self._fw_data = json.loads (result.encode ('utf-8'))
         except ValueError as e:
             self.error_handler (e)
             return
Index: system-config-printer-1.5.7/gtkinklevel.py
===================================================================
--- system-config-printer-1.5.7.orig/gtkinklevel.py
+++ system-config-printer-1.5.7/gtkinklevel.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2009, 2010, 2012 Red Hat, Inc.
 ## Authors:
Index: system-config-printer-1.5.7/gui.py
===================================================================
--- system-config-printer-1.5.7.orig/gui.py
+++ system-config-printer-1.5.7/gui.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/install-printerdriver.py
===================================================================
--- system-config-printer-1.5.7.orig/install-printerdriver.py
+++ system-config-printer-1.5.7/install-printerdriver.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 from gi.repository import GLib, PackageKitGlib
 import sys
Index: system-config-printer-1.5.7/installpackage.py
===================================================================
--- system-config-printer-1.5.7.orig/installpackage.py
+++ system-config-printer-1.5.7/installpackage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/jobviewer.py
===================================================================
--- system-config-printer-1.5.7.orig/jobviewer.py
+++ system-config-printer-1.5.7/jobviewer.py
@@ -40,7 +40,10 @@ import smburi
 import subprocess
 import sys
 import time
-import urllib.parse
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+else:
+   import urlparse
 from xml.sax import saxutils
 
 from debug import *
@@ -143,6 +146,9 @@ class PrinterURIIndex:
         try:
             if connection == None:
                 connection = cups.Connection ()
+            if sys.version_info < (3,0,0):
+                if isinstance(name, bytes):
+                    name = name.decode ('utf-8')
 
             r = ['printer-name', 'printer-uri-supported', 'printer-more-info']
             if uri != None:
@@ -943,18 +949,18 @@ class JobViewer (GtkGUI):
             informational_attrs = dict()
             auth_info = None
             if try_keyring and 'password' in auth_info_required:
-                (scheme, rest) = urllib.parse.splittype (device_uri)
+                result = urlparse.urlparse (device_uri)
+                scheme = result.scheme
                 if scheme == 'smb':
                     uri = smburi.SMBURI (uri=device_uri)
                     (group, server, share,
                      user, password) = uri.separate ()
                     informational_attrs["domain"] = str (group)
                 else:
-                    (serverport, rest) = urllib.parse.splithost (rest)
-                    if serverport == None:
+                    if not result.hostname:
                         server = None
                     else:
-                        (server, port) = urllib.parse.splitnport (serverport)
+                        (server, port) = (result.hostname, result.port)
 
                 if scheme == None or server == None:
                     try_keyring = False
@@ -1624,6 +1630,9 @@ class JobViewer (GtkGUI):
             for name, value in attrs.items():
                 if name in ['job-id', 'job-printer-up-time']:
                     continue
+                if sys.version_info < (3,0,0):
+                    if isinstance(value, unicode):
+                        value.encode('utf-8')
                 attr_store.append([name, str(value)])
 
     def job_is_active (self, jobdata):
@@ -1878,8 +1887,8 @@ class JobViewer (GtkGUI):
                 device_uri = attrs.get ('device-uri')
 
             if device_uri != None:
-                (scheme, rest) = urllib.parse.splittype (device_uri)
-                if scheme not in ['socket', 'ipp', 'http', 'smb']:
+                result = urlparse.urlparse (device_uri)
+                if result.scheme not in ['socket', 'ipp', 'http', 'smb']:
                     return
 
         printer = job.get ('job-printer-name', _("Unknown"))
Index: system-config-printer-1.5.7/PhysicalDevice.py
===================================================================
--- system-config-printer-1.5.7.orig/PhysicalDevice.py
+++ system-config-printer-1.5.7/PhysicalDevice.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2008, 2009, 2010, 2012, 2014 Red Hat, Inc.
 ## Authors:
@@ -18,11 +18,15 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 import config
 import gettext
 gettext.install(domain=config.PACKAGE, localedir=config.localedir)
 import cupshelpers
-import urllib.parse
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+else:
+   import urlparse
 
 import ppdippstr
 
@@ -54,11 +58,13 @@ class PhysicalDevice:
         hostport = None
         host = None
         dnssdhost = None
-        (scheme, rest) = urllib.parse.splittype (uri)
+        result = urlparse.urlparse (uri)
+        scheme = result.scheme
         if scheme == 'hp' or scheme == 'hpfax':
             ipparam = None
+            rest    = uri[len(scheme)+1:]
             if rest.startswith ("/net/"):
-                (rest, ipparam) = urllib.parse.splitquery (rest[5:])
+                ipparam = result.query
 
             if ipparam != None:
                 if ipparam.startswith("ip="):
@@ -76,13 +82,17 @@ class PhysicalDevice:
             # name of the printer
             return None, None
         else:
-            (hostport, rest) = urllib.parse.splithost (rest)
-            if hostport == None:
+            if not result.netloc:
                 return None, None
 
-        if hostport:
-            (host, port) = urllib.parse.splitport (hostport)
+        if result.netloc:
+            (host, port) = (result.hostname, result.port)
 
+        if sys.version_info < (3,0,0):
+            if type (host) == unicode:
+                host = host.encode ('utf-8')
+            if type (dnssdhost) == unicode:
+                dnssdhost = dnssdhost.encode ('utf-8')
         return host, dnssdhost
 
     def add_device (self, device):
@@ -160,10 +170,14 @@ class PhysicalDevice:
         if (hasattr (device, 'address') and self._network_host == None):
             address = device.address
             if address:
+                if sys.version_info < (3,0,0) and type (address) == unicode:
+                    address = address.encode ('utf-8')
                 self._network_host = address
         if (hasattr (device, 'hostname') and self.dnssd_hostname == None):
             hostname = device.hostname
             if hostname:
+                if sys.version_info < (3,0,0) and type (hostname) == unicode:
+                    hostname = hostname.encode ('utf-8')
                 self.dnssd_hostname = hostname
 
     def get_devices (self):
Index: system-config-printer-1.5.7/monitor.py
===================================================================
--- system-config-printer-1.5.7.orig/monitor.py
+++ system-config-printer-1.5.7/monitor.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2014 Red Hat, Inc.
 ## Author: Tim Waugh <twaugh@redhat.com>
@@ -676,7 +676,7 @@ class Monitor(GObject.GObject):
                 debugprint ("That's not what we asked for!")
         else:
             last_jobid = self.fetch_first_job_id + limit - 1
-        for jobid in range (self.fetch_first_job_id, last_jobid + 1):
+        for jobid in xrange (self.fetch_first_job_id, last_jobid + 1):
             try:
                 job = fetched[jobid]
                 if self.specific_dests != None:
@@ -825,6 +825,9 @@ if __name__ == '__main__':
             print("*%s: cups connection error" % obj)
 
         def on_cups_ipp_error (self, obj, err, errstring):
+            # cups.IPPError message is (utf-8) encoded
+            if sys.version_info < (3,0,0) and isinstance(errstring, bytes):
+                    errstring = errstring.decode('utf-8', 'replace')
             print("*%s: IPP error (%d): %s" % (obj, err, errstring))
 
     set_debugging (True)
Index: system-config-printer-1.5.7/newprinter.py
===================================================================
--- system-config-printer-1.5.7.orig/newprinter.py
+++ system-config-printer-1.5.7/newprinter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -29,7 +29,11 @@ import cupshelpers
 from OpenPrintingRequest import OpenPrintingRequest
 
 import errno
-import sys, os, tempfile, time, traceback, re, http.client
+import sys, os, tempfile, time, traceback, re
+if sys.version_info >= (3,0,0):
+    import http.client
+else:
+    import httplib
 import locale
 import string
 import subprocess
@@ -37,8 +41,16 @@ from timedops import *
 import dbus
 from gi.repository import Gdk
 from gi.repository import Gtk
-import requests
-import functools
+if sys.version_info >= (3,0,0):
+    import requests
+    import functools
+else:
+    import pycurl
+    # prefer Python 2 module here, as in Python 2 io.StringIO is broken
+    try:
+        from cStringIO import StringIO
+    except ImportError:
+        from io import StringIO
 
 import cups
 
@@ -55,7 +67,12 @@ from gui import GtkGUI
 from optionwidgets import OptionWidget
 from debug import *
 import probe_printer
-import urllib.request, urllib.parse
+if sys.version_info >= (3,0,0):
+    import urllib.request
+    import urllib.parse as urlparse
+else:
+    import urllib
+    import urlparse
 from smburi import SMBURI
 from errordialogs import *
 from PhysicalDevice import PhysicalDevice
@@ -75,7 +92,7 @@ TEXT_adjust_firewall = _("The firewall m
 
 def validDeviceURI (uri):
     """Returns True is the provided URI is valid."""
-    (scheme, rest) = urllib.parse.splittype (uri)
+    scheme = urlparse.urlparse (uri).scheme
     if scheme == None or scheme == '':
         return False
     return True
@@ -101,7 +118,10 @@ def getCurrentClassMembers(treeview):
     iter = model.get_iter_first()
     result = []
     while iter:
-        result.append(model.get(iter, 0)[0])
+        if sys.version_info >= (3,0,0):
+            result.append(model.get(iter, 0)[0])
+        else:
+            result.append(model.get(iter, 0)[0].decode('utf-8'))
         iter = model.iter_next(iter)
     result.sort()
     return result
@@ -109,6 +129,7 @@ def getCurrentClassMembers(treeview):
 def checkNPName(printers, name):
     if not name: return False
     name = name.lower()
+    if sys.version_info < (3,0,0): name = unicode (name)
     for printer in printers.values():
         if not printer.discovered and printer.name.lower()==name:
             return False
@@ -174,12 +195,27 @@ def download_gpg_fingerprint(url):
         debugprint('No system SSL certificates available for trust checking')
         return None
 
-    try:
-        req = requests.get(url, verify=cert)
-        content = req.content.decode("utf-8")
-    except:
-        debugprint('Cannot retrieve %s' % url)
-        return None
+    if sys.version_info >= (3,0,0):
+        try:
+            req = requests.get(url, verify=cert)
+            content = req.content.decode("utf-8")
+        except:
+            debugprint('Cannot retrieve %s' % url)
+            return None
+    else:
+        c = pycurl.Curl()
+        c.setopt(pycurl.URL, url)
+        content = StringIO()
+        c.setopt(pycurl.WRITEFUNCTION, content.write)
+        c.setopt(pycurl.FOLLOWLOCATION, 1)
+        c.setopt(pycurl.MAXREDIRS, 5)
+        c.setopt(pycurl.CAINFO, cert)
+        try:
+            c.perform()
+        except pycurl.error as e:
+            debugprint('Cannot retrieve %s: %s' % (url, repr (e)))
+            return None
+        content = content.getvalue()
 
     keyid_re = re.compile(' ((?:(?:[0-9A-F]{4})(?:\s+|$)){10})$', re.M)
 
@@ -996,7 +1032,7 @@ class NewPrinterGUI(GtkGUI):
         ret = True
         try:
             self.p = subprocess.Popen (args, env=new_environ, close_fds=True,
-                                       stdin=subprocess.DEVNULL,
+                                       stdin=file("/dev/null"),
                                        stdout=subprocess.PIPE)
             # Keep the UI refreshed while we wait for
             # the drivers query to complete.
@@ -1109,7 +1145,11 @@ class NewPrinterGUI(GtkGUI):
                         else:
                             port = 631
                         try:
-                            conn = http.client.HTTPConnection(resg[0], port)
+                            if sys.version_info >= (3,0,0):
+                                conn = http.client.HTTPConnection(resg[0], port)
+                            else:
+                                conn = httplib.HTTPConnection(resg[0], port)
+
                             conn.request("GET", "/printers/%s.ppd" % resg[2])
                             resp = conn.getresponse()
                             if resp.status == 200:
@@ -1749,6 +1789,7 @@ class NewPrinterGUI(GtkGUI):
     def on_entNPName_changed(self, widget):
         # restrict
         text = widget.get_text()
+        if sys.version_info < (3,0,0): text = unicode (text, 'utf-8')
         new_text = text
         new_text = new_text.replace("/", "")
         new_text = new_text.replace("#", "")
@@ -1846,7 +1887,7 @@ class NewPrinterGUI(GtkGUI):
         debugprint (faxuri + ": " + repr(args))
         try:
             p = subprocess.Popen (args, env=new_environ, close_fds=True,
-                                  stdin=subprocess.DEVNULL,
+                                  stdin=file("/dev/null"),
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
             (stdout, stderr) = p.communicate ()
@@ -1855,7 +1896,8 @@ class NewPrinterGUI(GtkGUI):
             return None
 
         faxtype = -1
-        for line in stdout.decode ().split ("\n"):
+        if sys.version_info >= (3,0,0): stdout = stdout.decode ()
+        for line in stdout.split ("\n"):
             if line.find ("fax-type") == -1:
                 continue
             res = re.search ("(\d+)", line)
@@ -1879,7 +1921,7 @@ class NewPrinterGUI(GtkGUI):
         debugprint (uri + ": " + repr(args))
         try:
             p = subprocess.Popen (args, close_fds=True,
-                                  stdin=subprocess.DEVNULL,
+                                  stdin=file("/dev/null"),
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
             (stdout, stderr) = p.communicate ()
@@ -1889,7 +1931,8 @@ class NewPrinterGUI(GtkGUI):
             # Problem executing command.
             return None
 
-        scan_type = stdout.decode ().strip ()
+        if sys.version_info >= (3,0,0): stdout = stdout.decode ()
+        scan_type = stdout.strip ()
         fields = scan_type.split ("=", 1)
         if len (fields) < 2:
             return None
@@ -1909,7 +1952,7 @@ class NewPrinterGUI(GtkGUI):
         uri = None
         try:
             p = subprocess.Popen (args, close_fds=True,
-                                  stdin=subprocess.DEVNULL,
+                                  stdin=file("/dev/null"),
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
             (stdout, stderr) = p.communicate ()
@@ -1919,7 +1962,8 @@ class NewPrinterGUI(GtkGUI):
             # Problem executing command.
             return None
 
-        uri = stdout.decode ().strip ()
+        if sys.version_info >= (3,0,0): stdout = stdout.decode ()
+        uri = stdout.strip ()
         return uri
 
     def getNetworkPrinterMakeModel(self, host=None, device=None):
@@ -1949,7 +1993,7 @@ class NewPrinterGUI(GtkGUI):
             stdout = None
             try:
                 p = subprocess.Popen (args, close_fds=True,
-                                      stdin=subprocess.DEVNULL,
+                                      stdin=file("/dev/null"),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
                 (stdout, stderr) = p.communicate ()
@@ -1960,7 +2004,8 @@ class NewPrinterGUI(GtkGUI):
                 pass
 
             if stdout != None:
-                line = stdout.decode ().strip ()
+                if sys.version_info >= (3,0,0): stdout = stdout.decode ()
+                line = stdout.strip ()
                 words = probe_printer.wordsep (line)
                 n = len (words)
                 if n < 4:
@@ -2775,9 +2820,8 @@ class NewPrinterGUI(GtkGUI):
             elif device.type == "socket":
                 device.menuentry = _("AppSocket/HP JetDirect")
             elif device.type == "lpd":
-                (scheme, rest) = urllib.parse.splittype (device.uri)
-                (hostport, rest) = urllib.parse.splithost (rest)
-                (queue, rest) = urllib.parse.splitquery (rest)
+                result = urlparse.urlparse (device.uri)
+                (scheme, hostport, queue) = (result.scheme, result.netloc, result.query)
                 if queue != '':
                     if queue[0] == '/':
                         queue = queue[1:]
@@ -2790,9 +2834,8 @@ class NewPrinterGUI(GtkGUI):
             elif device.type == "smb":
                 device.menuentry = _("Windows Printer via SAMBA")
             elif device.type == "ipp":
-                (scheme, rest) = urllib.parse.splittype (device.uri)
-                (hostport, rest) = urllib.parse.splithost (rest)
-                (queue, rest) = urllib.parse.splitquery (rest)
+                result = urlparse.urlparse (device.uri)
+                (scheme, hostport, queue) = (result.scheme, result.netloc, result.query)
                 if queue != '':
                     if queue[0] == '/':
                         queue = queue[1:]
@@ -2805,9 +2848,8 @@ class NewPrinterGUI(GtkGUI):
             elif device.type == "http" or device.type == "https":
                 device.menuentry = _("HTTP")
             elif device.type == "dnssd" or device.type == "mdns":
-                (scheme, rest) = urllib.parse.splittype (device.uri)
-                (name, rest) = urllib.parse.splithost (rest)
-                (cupsqueue, rest) = urllib.parse.splitquery (rest)
+                result = urlparse.urlparse (device.uri)
+                (scheme, name, cupsqueue) = (result.scheme, result.netloc, result.query)
                 if cupsqueue != '' and cupsqueue[0] == '/':
                     cupsqueue = cupsqueue[1:]
                 if cupsqueue == 'cups':
@@ -2859,10 +2901,8 @@ class NewPrinterGUI(GtkGUI):
                 elif device.type in ["socket", "lpd", "ipp", "dnssd", "mdns"]:
                     # This is a network printer.
                     if host == None and device.type in ["socket", "lpd", "ipp"]:
-                        (scheme, rest) = urllib.parse.splittype (device.uri)
-                        (hostport, rest) = urllib.parse.splithost (rest)
-                        if hostport != None:
-                            (host, port) = urllib.parse.splitport (hostport)
+                        result = urlparse.urlparse (device.uri)
+                        (scheme, host, port) = (result.scheme, result.hostname, result.port)
                     if host:
                         is_network = True
                         remotecups = ((device.uri.startswith('dnssd:') or \
@@ -2966,9 +3006,8 @@ class NewPrinterGUI(GtkGUI):
                 text = _("Local printer detected by the "
                          "Hardware Abstraction Layer (HAL).")
             elif device.type == "dnssd" or device.type == "mdns":
-                (scheme, rest) = urllib.parse.splittype (device.uri)
-                (name, rest) = urllib.parse.splithost (rest)
-                (cupsqueue, rest) = urllib.parse.splitquery (rest)
+                result = urlparse.urlparse (device.uri)
+                (scheme, name, cupsqueue) = (result.scheme, result.hostname, result.query)
                 if cupsqueue != '' and cupsqueue[0] == '/':
                     cupsqueue = cupsqueue[1:]
                 if cupsqueue == 'cups':
@@ -2990,12 +3029,12 @@ class NewPrinterGUI(GtkGUI):
 
             self.lblNPDeviceDescription.set_text (text)
         elif device.type=="socket":
-            (scheme, rest) = urllib.parse.splittype (device.uri)
+            result = urlparse.urlparse (device.uri)
+            scheme = result.scheme
             host = ''
             port = 9100
             if scheme == "socket":
-                (hostport, rest) = urllib.parse.splithost (rest)
-                (host, port) = urllib.parse.splitnport (hostport, defport=port)
+                (host, port) = ( result.hostname, result.port if result.port else port)
                 debugprint ("socket: host is %s, port is %s" % (host,
                                                                 repr (port)))
                 if device.location != '':
@@ -3029,7 +3068,8 @@ class NewPrinterGUI(GtkGUI):
                         nr = 0
                         while iter:
                             value = model.get(iter,1)[0]
-                            if str (value) == str (option_dict[name]):
+                            if (sys.version_info >= (3,0,0) and str (value) == str (option_dict[name])) or \
+                               (sys.version_info <  (3,0,0) and unicode (value) == unicode (option_dict[name])):
                                 break
                             iter = model.iter_next(iter)
                             nr += 1
@@ -3912,11 +3952,14 @@ class NewPrinterGUI(GtkGUI):
                     p = subprocess.Popen (['/usr/bin/cupstestppd',
                                            '-rvv', filename],
                                           close_fds=True,
-                                          stdin=subprocess.DEVNULL,
+                                          stdin=file("/dev/null"),
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                     (stdout, stderr) = p.communicate ()
-                    err += stdout.decode ()
+                    if sys.version_info >= (3,0,0):
+                        err += stdout.decode ()
+                    else:
+                        err += stdout.decode ('utf-8', 'replace')
                 except:
                     # Problem executing command.
                     raise
@@ -4024,6 +4067,10 @@ class NewPrinterGUI(GtkGUI):
             name = self.entNPName.get_text()
             location = self.entNPLocation.get_text()
             info = self.entNPDescription.get_text()
+            if sys.version_info < (3,0,0):
+                name = unicode ( name, 'utf-8')
+                location = unicode ( location, 'utf-8')
+                info = unicode ( info, 'utf-8')
         else:
             name = self._name
 
@@ -4063,7 +4110,7 @@ class NewPrinterGUI(GtkGUI):
                 Gtk.main_iteration ()
             self.cups._begin_operation (_("adding printer %s") % name)
             try:
-                if isinstance(ppd, str):
+                if isinstance(ppd, str) or (sys.version_info < (3,0,0) and isinstance(ppd, unicode)):
                     self.cups.addPrinter(name, ppdname=ppd,
                          device=uri, info=info, location=location)
                 elif ppd is None: # raw queue
@@ -4124,7 +4171,7 @@ class NewPrinterGUI(GtkGUI):
             # set ppd on server and retrieve it
             # cups doesn't offer a way to just download a ppd ;(=
             raw = False
-            if isinstance(ppd, str):
+            if isinstance(ppd, str) or (sys.version_info < (3,0,0) and isinstance(ppd, unicode)):
                 if self.rbtnChangePPDasIs.get_active():
                     # To use the PPD as-is we need to prevent CUPS copying
                     # the old options over.  Do this by setting it to a
Index: system-config-printer-1.5.7/ppdcache.py
===================================================================
--- system-config-printer-1.5.7.orig/ppdcache.py
+++ system-config-printer-1.5.7/ppdcache.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
 ## Authors:
Index: system-config-printer-1.5.7/ppdippstr.py
===================================================================
--- system-config-printer-1.5.7.orig/ppdippstr.py
+++ system-config-printer-1.5.7/ppdippstr.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/ppdsloader.py
===================================================================
--- system-config-printer-1.5.7.orig/ppdsloader.py
+++ system-config-printer-1.5.7/ppdsloader.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/printerproperties.py
===================================================================
--- system-config-printer-1.5.7.orig/printerproperties.py
+++ system-config-printer-1.5.7/printerproperties.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -24,7 +24,7 @@
 # config is generated from config.py.in by configure
 import config
 
-import os, tempfile
+import sys, os, tempfile
 from gi.repository import Gtk
 import cups
 import locale
@@ -686,6 +686,9 @@ class PrinterPropertiesDialog(GtkGUI):
 
         old_value = old_values[widget]
 
+        if sys.version_info < (3,0,0) and type (old_value) == unicode:
+            old_value = old_value.encode ('utf-8')
+
         if old_value == value:
             self.changed.discard(widget)
         else:
@@ -995,6 +998,8 @@ class PrinterPropertiesDialog(GtkGUI):
             parent = self.dialog
         class_deleted = False
         name = printer.name
+        if sys.version_info < (3,0,0) and isinstance (name, bytes):
+            name = name.decode ('utf-8')
 
         if printer.is_class:
             self.cups._begin_operation (_("modifying class %s") % name)
@@ -1040,6 +1045,10 @@ class PrinterPropertiesDialog(GtkGUI):
             location = self.entPLocation.get_text()
             info = self.entPDescription.get_text()
             device_uri = self.entPDevice.get_text()
+            if sys.version_info < (3,0,0):
+                location = location.decode ('utf-8')
+                info = info.decode ('utf-8')
+                device_uri = device_uri.decode ('utf-8')
 
             enabled = self.chkPEnabled.get_active()
             accepting = self.chkPAccepting.get_active()
@@ -1332,7 +1341,7 @@ class PrinterPropertiesDialog(GtkGUI):
             # Either the underlying cupsGetPPD2() function returned
             # NULL without setting an IPP error (so it'll be something
             # like a failed connection), or the PPD could not be parsed.
-            if str (e).startswith ("ppd"):
+            if str (e).startswith ("ppd"): # or e.message.startswith ("ppd")
                 show_error_dialog (_("Error"),
                                    _("The PPD file for this queue "
                                      "is damaged."),
@@ -1909,6 +1918,9 @@ class PrinterPropertiesDialog(GtkGUI):
         self.on_printer_modified (None, printer, False)
 
     def on_printer_removed (self, mon, printer):
+        if sys.version_info < (3,0,0) and isinstance (printer, bytes):
+            printer = printer.decode ('utf-8')
+
         if (self.dialog.get_property ('visible') and
             self.printer and self.printer.name == printer):
             self.dialog.response (Gtk.ResponseType.CANCEL)
Index: system-config-printer-1.5.7/probe_printer.py
===================================================================
--- system-config-printer-1.5.7.orig/probe_printer.py
+++ system-config-printer-1.5.7/probe_printer.py
@@ -18,6 +18,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 import cupshelpers
 from debug import *
 import errno
@@ -272,14 +273,18 @@ class PrinterFinder:
 
     def _probe_snmp (self):
         # Run the CUPS SNMP backend, pointing it at the host.
+        if sys.version_info < (3,0,0):
+            null = file ("/dev/null", "r+")
+        else:
+            null = subprocess.DEVNULL
         try:
             debugprint ("snmp: trying")
             p = subprocess.Popen (args=["/usr/lib/cups/backend/snmp",
                                         self.hostname],
                                   close_fds=True,
-                                  stdin=subprocess.DEVNULL,
+                                  stdin=null,
                                   stdout=subprocess.PIPE,
-                                  stderr=subprocess.DEVNULL)
+                                  stderr=null)
         except OSError as e:
             debugprint ("snmp: no good")
             if e.errno == errno.ENOENT:
@@ -296,7 +301,7 @@ class PrinterFinder:
             debugprint ("snmp: no good")
             return
 
-        for line in stdout.decode ().split ('\n'):
+        for line in stdout.split ('\n'):
             words = wordsep (line)
             n = len (words)
             if n == 6:
@@ -364,13 +369,17 @@ class PrinterFinder:
                         self._cached_attributes['device-make-and-model'])
             return
 
+        if sys.version_info < (3,0,0):
+            null = file ("/dev/null", "r+")
+        else:
+            null = subprocess.DEVNULL
         try:
             debugprint ("hplip: trying")
             p = subprocess.Popen (args=["hp-makeuri", "-c", self.hostname],
                                   close_fds=True,
-                                  stdin=subprocess.DEVNULL,
+                                  stdin=null,
                                   stdout=subprocess.PIPE,
-                                  stderr=subprocess.DEVNULL)
+                                  stderr=null)
         except OSError as e:
             if e.errno == errno.ENOENT:
                 return
@@ -386,7 +395,7 @@ class PrinterFinder:
             debugprint ("hplip: no good")
             return
 
-        uri = stdout.decode ().strip ()
+        uri = stdout.strip ()
         debugprint ("hplip: uri is %s" % uri)
         if uri.find (":") != -1:
             self._new_device(uri, uri)
Index: system-config-printer-1.5.7/profile-ppds.py
===================================================================
--- system-config-printer-1.5.7.orig/profile-ppds.py
+++ system-config-printer-1.5.7/profile-ppds.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 import cups
 import cupshelpers
 import hotshot
Index: system-config-printer-1.5.7/pysmb.py
===================================================================
--- system-config-printer-1.5.7.orig/pysmb.py
+++ system-config-printer-1.5.7/pysmb.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 ## CUPS backend
Index: system-config-printer-1.5.7/scp-dbus-service.py
===================================================================
--- system-config-printer-1.5.7.orig/scp-dbus-service.py
+++ system-config-printer-1.5.7/scp-dbus-service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/serversettings.py
===================================================================
--- system-config-printer-1.5.7.orig/serversettings.py
+++ system-config-printer-1.5.7/serversettings.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
Index: system-config-printer-1.5.7/smburi.py
===================================================================
--- system-config-printer-1.5.7.orig/smburi.py
+++ system-config-printer-1.5.7/smburi.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -20,10 +20,20 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-import urllib.parse
+import sys
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+else:
+   import urlparse
+   import urllib
 
 def urlquote (x):
     q = urllib.parse.quote (x)
+    if sys.version_info >= (3,0,0):
+        q = urllib.parse.quote (x)
+    else:
+        q = urllib.quote (x)
+
     for c in ["/", "@", ":"]:
         q = q.replace (c, "%%%02X" % ord (c))
 
@@ -37,6 +47,8 @@ class SMBURI:
             if group or host or share or user or password:
                 raise RuntimeError
 
+            if sys.version_info < (3,0,0):
+                uri = uri.encode ('utf-8')
             if uri.startswith ("smb://"):
                 uri = uri[6:]
 
@@ -97,6 +109,11 @@ class SMBURI:
             if p != -1:
                 host = host[:p]
         share = uri
-        return (urllib.parse.unquote (group), urllib.parse.unquote (host),
-                urllib.parse.unquote (share),
-                urllib.parse.unquote (user), urllib.parse.unquote (password))
+        if sys.version_info >= (3,0,0):
+            return (urlparse.unquote (group), urlparse.unquote (host),
+                urlparse.unquote (share),
+                urlparse.unquote (user), urlparse.unquote (password))
+        else:
+            return (urllib.unquote (group), urllib.unquote (host),
+                urllib.unquote (share),
+                urllib.unquote (user), urllib.unquote (password))
Index: system-config-printer-1.5.7/statereason.py
===================================================================
--- system-config-printer-1.5.7.orig/statereason.py
+++ system-config-printer-1.5.7/statereason.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2007, 2008, 2009, 2010, 2012, 2013, 2014 Red Hat, Inc.
 ## Authors:
Index: system-config-printer-1.5.7/system-config-printer.py
===================================================================
--- system-config-printer-1.5.7.orig/system-config-printer.py
+++ system-config-printer-1.5.7/system-config-printer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -25,7 +25,10 @@
 import config
 
 import sys, os, time, re
-import _thread
+if sys.version_info >= (3,0,0):
+   import _thread
+else:
+   import thread as _thread
 import dbus
 try:
     from gi.repository import Polkit
@@ -74,7 +77,12 @@ from gi.repository import GObject
 from gi.repository import GLib
 from gui import GtkGUI
 from debug import *
-import urllib.request, urllib.parse, urllib.error
+if sys.version_info >= (3,0,0):
+    import urllib.request, urllib.error
+    import urllib.parse as urlparse
+else:
+    import urllib
+    import urlparse
 import troubleshoot
 import installpackage
 import jobviewer
@@ -498,6 +506,7 @@ class GUI(GtkGUI):
         iter = model.get_iter_first ()
         while iter != None:
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             if name == queue:
                 path = model.get_path (iter)
                 self.dests_iconview.scroll_to_path (path, True, 0.5, 0.5)
@@ -537,6 +546,7 @@ class GUI(GtkGUI):
         model = iconview.get_model ()
         iter = model.get_iter (path)
         name = model.get_value (iter, 2)
+        if sys.version_info < (3,0,0): name = name.decode ('utf-8')
         object = model.get_value (iter, 0)
 
         self.desensitise_main_window_widgets ()
@@ -586,6 +596,7 @@ class GUI(GtkGUI):
             iter = model.get_iter (path)
             object = model.get_value (iter, 0)
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             if object.discovered:
                 any_discovered = True
             if object.enabled:
@@ -795,6 +806,7 @@ class GUI(GtkGUI):
         for path in paths:
             iter = model.get_iter (path)
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             selected_printers.add (name)
 
         if self.cups:
@@ -930,7 +942,7 @@ class GUI(GtkGUI):
                 elif object.is_class:
                     type = 'local-class'
                 else:
-                    (scheme, rest) = urllib.parse.splittype (object.device_uri)
+                    scheme = urlparse.urlparse (object.device_uri).scheme
                     if scheme == 'ipp':
                         type = 'ipp-printer'
                     elif scheme == 'smb':
@@ -1045,6 +1057,7 @@ class GUI(GtkGUI):
         model = self.dests_iconview.get_model ()
         def maybe_select (model, path, iter, UNUSED):
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             if name in selected_printers:
                 self.dests_iconview.select_path (path)
         model.foreach (maybe_select, None)
@@ -1112,6 +1125,7 @@ class GUI(GtkGUI):
         self.connect_encrypt = cups.getEncryption ()
 
         servername = self.cmbServername.get_child().get_text()
+        if sys.version_info < (3,0,0): servername = servername.decode ('utf-8')
 
         self.lblConnecting.set_markup(_("<i>Opening connection to %s</i>")
                                        % servername)
@@ -1391,6 +1405,7 @@ class GUI(GtkGUI):
         model = self.dests_iconview.get_model ()
         iter = model.get_iter (path)
         name = model.get_value (iter, 2)
+        if sys.version_info < (3,0,0): name = name.decode ('utf-8')
         if not self.is_rename_possible (name):
             return
         if not self.rename_confirmed_by_user (name):
@@ -1416,6 +1431,7 @@ class GUI(GtkGUI):
             model = self.dests_iconview.get_model ()
             iter = model.get_iter (path)
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             id = editable.connect('editing-done',
                                   self.printer_name_editing_done,
                                   cell, name)
@@ -1423,6 +1439,7 @@ class GUI(GtkGUI):
 
     def printer_name_editing (self, entry):
         newname = origname = entry.get_text()
+        if sys.version_info < (3,0,0): newname = origname = newname.decode ('utf-8')
         newname = newname.replace("/", "")
         newname = newname.replace("#", "")
         newname = newname.replace(" ", "")
@@ -1433,6 +1450,7 @@ class GUI(GtkGUI):
     def printer_name_editing_done (self, entry, cell, name):
         debugprint (repr (cell))
         newname = entry.get_text ()
+        if sys.version_info < (3,0,0): newname = newname.decode ('utf-8')
         debugprint ("edited: %s -> %s" % (name, newname))
         try:
             self.rename_printer (name, newname)
@@ -1561,6 +1579,7 @@ class GUI(GtkGUI):
         # ..and select the new printer.
         def select_new_printer (model, path, iter, UNUSED):
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             if name == new_name:
                 self.dests_iconview.select_path (path)
         self.populateList ()
@@ -1585,6 +1604,7 @@ class GUI(GtkGUI):
         model = self.dests_iconview.get_model ()
         iter = model.get_iter (paths[0])
         name = model.get_value (iter, 2)
+        if sys.version_info < (3,0,0): name = name.decode ('utf-8')
         self.entDuplicateName.set_text(name)
         self.NewPrinterName.set_transient_for (self.PrintersWindow)
         result = self.NewPrinterName.run()
@@ -1607,12 +1627,16 @@ class GUI(GtkGUI):
             self.populateList ()
             return
 
-        self.duplicate_printer (self.entDuplicateName.get_text ())
+        if sys.version_info >= (3,0,0):
+            self.duplicate_printer (self.entDuplicateName.get_text ())
+        else:
+            self.duplicate_printer (self.entDuplicateName.get_text ().decode ('utf-8'))
         self.monitor.update ()
 
     def on_entDuplicateName_changed(self, widget):
         # restrict
         text = widget.get_text()
+        if sys.version_info < (3,0,0): text = text.decode ('utf-8')
         new_text = text
         new_text = new_text.replace("/", "")
         new_text = new_text.replace("#", "")
@@ -1636,6 +1660,7 @@ class GUI(GtkGUI):
             itr = model.get_iter (paths[0])
             obj = model.get_value (itr, 0)
             name = model.get_value (itr, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             if obj.is_class:
                 message_format = (_("Really delete class '%s'?") % name)
             else:
@@ -1647,6 +1672,7 @@ class GUI(GtkGUI):
             for path in paths:
                 itr = model.get_iter (path)
                 name = model.get_value (itr, 2)
+                if sys.version_info < (3,0,0): name = name.decode ('utf-8')
                 to_delete.append (name)
         dialog = Gtk.MessageDialog(parent=self.PrintersWindow,
                                    modal=True, destroy_with_parent=True,
@@ -1689,7 +1715,10 @@ class GUI(GtkGUI):
             printers.append (printer)
 
         for printer in printers:
-            self.cups._begin_operation (_("modifying printer %s") % printer.name)
+            printer_name = printer.name
+            if sys.version_info < (3,0,0) and isinstance(printer_name, bytes):
+                printer_name = printer_name.decode ('utf-8')
+            self.cups._begin_operation (_("modifying printer %s") % printer_name)
             try:
                 printer.setEnabled (enable)
             except cups.IPPError as e:
@@ -1719,8 +1748,11 @@ class GUI(GtkGUI):
 
         success = False
         for printer in printers:
+            printer_name = printer.name
+            if sys.version_info < (3,0,0) and isinstance(printer_name, bytes):
+                printer_name = printer_name.decode ('utf-8')
             self.cups._begin_operation (_("modifying printer %s")
-                                        % printer.name)
+                                        % printer_name)
             try:
                 printer.setShared (share)
                 success = True
@@ -1773,6 +1805,7 @@ class GUI(GtkGUI):
             return
 
         name = model.get_value (iter, 2)
+        if sys.version_info < (3,0,0): name = name.decode ('utf-8')
         self.set_system_or_user_default_printer (name)
 
     def on_edit_activate (self, *UNUSED):
@@ -1786,6 +1819,7 @@ class GUI(GtkGUI):
         for path in paths:
             iter = model.get_iter (path)
             name = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): name = name.decode ('utf-8')
             class_members.append (name)
         if not self.newPrinterGUI.init ("class",
                                         host=self.connect_server,
@@ -1813,6 +1847,7 @@ class GUI(GtkGUI):
             for path in paths:
                 iter = model.get_iter (path)
                 name = model.get_value (iter, 2)
+                if sys.version_info < (3,0,0): name = name.decode ('utf-8')
                 specific_dests.append (name)
             viewer = jobviewer.JobViewer (None, None, my_jobs=False,
                                           specific_dests=specific_dests,
@@ -1946,6 +1981,7 @@ class GUI(GtkGUI):
         iter = model.get_iter_first ()
         while iter != None:
             queue = model.get_value (iter, 2)
+            if sys.version_info < (3,0,0): queue = queue.decode ('utf-8')
             if queue == name:
                 path = model.get_path (iter)
                 self.dests_iconview.scroll_to_path (path, True, 0.5, 0.5)
Index: system-config-printer-1.5.7/timedops.py
===================================================================
--- system-config-printer-1.5.7.orig/timedops.py
+++ system-config-printer-1.5.7/timedops.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2008, 2009, 2010, 2012, 2014 Red Hat, Inc.
 ## Authors:
Index: system-config-printer-1.5.7/troubleshoot/CheckLocalServerPublishing.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckLocalServerPublishing.py
+++ system-config-printer-1.5.7/troubleshoot/CheckLocalServerPublishing.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/CheckNetworkServerSanity.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckNetworkServerSanity.py
+++ system-config-printer-1.5.7/troubleshoot/CheckNetworkServerSanity.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -24,6 +24,7 @@ from gi.repository import Gtk
 
 import cups
 import os
+import sys
 import smburi
 import socket
 import subprocess
@@ -184,10 +185,15 @@ class CheckNetworkServerSanity(Question)
         if (try_connect and
             'remote_server_traceroute' not in answers):
             try:
+                if sys.version_info >= (3,0,0):
+                    null = subprocess.DEVNULL
+                else:
+                    null = file("/dev/null")
+
                 self.op = TimedSubprocess (parent=parent, close_fds=True,
                                            args=['traceroute', '-w', '1',
                                                  server_name],
-                                           stdin=subprocess.DEVNULL,
+                                           stdin=null,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
                 self.answers['remote_server_traceroute'] = self.op.run ()
Index: system-config-printer-1.5.7/troubleshoot/CheckPPDSanity.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckPPDSanity.py
+++ system-config-printer-1.5.7/troubleshoot/CheckPPDSanity.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -26,6 +26,7 @@ import cups
 import cupshelpers
 import installpackage
 import os
+import sys
 import subprocess
 from timedops import TimedOperation, TimedSubprocess
 from .base import *
@@ -100,10 +101,14 @@ class CheckPPDSanity(Question):
             title = _("Invalid PPD File")
             self.answers['cups_printer_ppd_valid'] = False
             try:
+                if sys.version_info >= (3,0,0):
+                    null = subprocess.DEVNULL
+                else:
+                    null = file("/dev/null")
                 self.op = TimedSubprocess (parent=parent,
                                            args=['cupstestppd', '-rvv', tmpf],
                                            close_fds=True,
-                                           stdin=subprocess.DEVNULL,
+                                           stdin=null,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
                 result = self.op.run ()
Index: system-config-printer-1.5.7/troubleshoot/CheckPrinterSanity.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckPrinterSanity.py
+++ system-config-printer-1.5.7/troubleshoot/CheckPrinterSanity.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -24,10 +24,14 @@ from gi.repository import Gtk
 
 import cups
 import os
+import sys
 import smburi
 import subprocess
 from timedops import TimedOperation, TimedSubprocess
-import urllib.parse
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+else:
+   import urlparse
 from .base import *
 class CheckPrinterSanity(Question):
     def __init__ (self, troubleshooter):
@@ -72,11 +76,16 @@ class CheckPrinterSanity(Question):
         if 'cups_printer_dict' in self.answers:
             cups_printer_dict = self.answers['cups_printer_dict']
             uri = cups_printer_dict['device-uri']
-            (scheme, rest) = urllib.parse.splittype (uri)
+#            (scheme, rest) = urllib.parse.splittype (uri)
+            parseresult = urlparse.urlparse (uri)
+            scheme = parseresult.scheme
             self.answers['cups_device_uri_scheme'] = scheme
+            if sys.version_info >= (3,0,0):
+                null = subprocess.DEVNULL
+            else:
+                null = file("/dev/null")
             if scheme in ["ipp", "http", "https"]:
-                (hostport, rest) = urllib.parse.splithost (rest)
-                (host, port) = urllib.parse.splitnport (hostport, defport=631)
+                (host, port) = (parseresult.hostname, parseresult.port if parseresult.port else 631)
                 self.answers['remote_server_name'] = host
                 self.answers['remote_server_port'] = port
             elif scheme == "smb":
@@ -94,7 +103,7 @@ class CheckPrinterSanity(Question):
                                          args=args,
                                          env=new_environ,
                                          close_fds=True,
-                                         stdin=subprocess.DEVNULL,
+                                         stdin=null,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
                     result = p.run ()
@@ -121,7 +130,7 @@ class CheckPrinterSanity(Question):
                                          args=["hp-info", "-d" + uri],
                                          close_fds=True,
                                          env=new_environ,
-                                         stdin=subprocess.DEVNULL,
+                                         stdin=null,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
                     self.answers['hplip_output'] = p.run ()
Index: system-config-printer-1.5.7/troubleshoot/CheckSELinux.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckSELinux.py
+++ system-config-printer-1.5.7/troubleshoot/CheckSELinux.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -24,6 +24,7 @@ from gi.repository import Gtk
 import subprocess
 from .base import *
 import os
+import sys
 import shlex
 from timedops import TimedSubprocess
 
@@ -48,6 +49,10 @@ class CheckSELinux(Question):
             return False
 
         paths = ["/etc/cups/", "/usr/lib/cups/", "/usr/share/cups/"]
+        if sys.version_info >= (3,0,0):
+            null = subprocess.DEVNULL
+        else:
+            null = file("/dev/null", "r+")
         parent = self.troubleshooter.get_window ()
         contexts = {}
         new_environ = os.environ.copy()
@@ -59,9 +64,9 @@ class CheckSELinux(Question):
                                        args=restorecon_args,
                                        close_fds=True,
                                        env=new_environ,
-                                       stdin=subprocess.DEVNULL,
+                                       stdin=null,
                                        stdout=subprocess.PIPE,
-                                       stderr=subprocess.DEVNULL)
+                                       stderr=null)
             (restorecon_stdout, restorecon_stderr, result) = self.op.run ()
         except:
             # Problem executing command.
Index: system-config-printer-1.5.7/troubleshoot/CheckUSBPermissions.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/CheckUSBPermissions.py
+++ system-config-printer-1.5.7/troubleshoot/CheckUSBPermissions.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -22,9 +22,13 @@
 
 import glob
 import os
+import sys
 import subprocess
 from timedops import TimedSubprocess
-import urllib.parse
+if sys.version_info >= (3,0,0):
+   import urllib.parse as urlparse
+else:
+   import urlparse
 from .base import *
 from gi.repository import Gtk
 
@@ -47,7 +51,7 @@ class CheckUSBPermissions(Question):
         else:
             return False
 
-        (scheme, rest) = urllib.parse.splittype (device_uri)
+        scheme = urlparse.urlparse (device_uri).scheme
         if scheme not in ['hp', 'hpfax', 'usb', 'hal']:
             return False
 
@@ -64,12 +68,16 @@ class CheckUSBPermissions(Question):
 
         # Run lsusb
         parent = self.troubleshooter.get_window ()
+        if sys.version_info >= (3,0,0):
+            null = subprocess.DEVNULL
+        else:
+            null = file("/dev/null", "r+")
         try:
             self.op = TimedSubprocess (parent=parent,
                                        args=[LSUSB, "-v"],
                                        close_fds=True,
                                        env=new_environ,
-                                       stdin=subprocess.DEVNULL,
+                                       stdin=null,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
             (lsusb_stdout, lsusb_stderr, result) = self.op.run ()
@@ -149,7 +157,7 @@ class CheckUSBPermissions(Question):
                                            args=[GETFACL, path],
                                            close_fds=True,
                                            env=new_environ,
-                                           stdin=subprocess.DEVNULL,
+                                           stdin=null,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
                 (getfacl_stdout, getfacl_stderr, result) = self.op.run ()
Index: system-config-printer-1.5.7/troubleshoot/ChooseNetworkPrinter.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ChooseNetworkPrinter.py
+++ system-config-printer-1.5.7/troubleshoot/ChooseNetworkPrinter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/ChoosePrinter.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ChoosePrinter.py
+++ system-config-printer-1.5.7/troubleshoot/ChoosePrinter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -19,6 +19,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 from gi.repository import Gtk
 
 class NoPrinter:
@@ -138,7 +139,9 @@ class ChoosePrinter(Question):
                 def each (self, model, path, iter, user_data):
                     dest = model.get_value (iter, 3)
                     if dest != NotListed:
-                        self.dests.append ((dest.name,
+                        self.dests.append ((dest.name.decode ('utf-8') if
+                                             sys.version_info < (3,0,0) and isinstance(dest.name, bytes) else
+                                             dest.name,
                                             dest.instance))
 
             return { 'cups_queue_listed': False,
@@ -146,7 +149,9 @@ class ChoosePrinter(Question):
         else:
             return { 'cups_queue_listed': True,
                      'cups_dest': dest,
-                     'cups_queue': dest.name,
+                     'cups_queue': dest.name.decode ('utf-8') if
+                                             sys.version_info < (3,0,0) and isinstance(dest.name, bytes) else
+                                             dest.name,
                      'cups_instance': dest.instance }
 
     def cancel_operation (self):
Index: system-config-printer-1.5.7/troubleshoot/DeviceListed.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/DeviceListed.py
+++ system-config-printer-1.5.7/troubleshoot/DeviceListed.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/ErrorLogCheckpoint.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ErrorLogCheckpoint.py
+++ system-config-printer-1.5.7/troubleshoot/ErrorLogCheckpoint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/ErrorLogFetch.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ErrorLogFetch.py
+++ system-config-printer-1.5.7/troubleshoot/ErrorLogFetch.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/ErrorLogParse.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ErrorLogParse.py
+++ system-config-printer-1.5.7/troubleshoot/ErrorLogParse.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/LocalOrRemote.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/LocalOrRemote.py
+++ system-config-printer-1.5.7/troubleshoot/LocalOrRemote.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/Locale.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/Locale.py
+++ system-config-printer-1.5.7/troubleshoot/Locale.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/NetworkCUPSPrinterShared.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/NetworkCUPSPrinterShared.py
+++ system-config-printer-1.5.7/troubleshoot/NetworkCUPSPrinterShared.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/PrintTestPage.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/PrintTestPage.py
+++ system-config-printer-1.5.7/troubleshoot/PrintTestPage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -20,6 +20,7 @@
 ## along with this program; if not, write to the Free Software
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+import sys
 import cups
 import dbus
 import dbus.glib
@@ -418,6 +419,8 @@ class PrintTestPage(Question):
                 break
             except cups.IPPError as e:
                 (e, s) = e.args
+                if sys.version_info < (3,0,0) and isinstance(s, bytes):
+                    s = s.decode('utf-8', 'replace')
                 if (e == cups.IPP_DOCUMENT_FORMAT and
                     mimetypes.index (mimetype) < (len (mimetypes) - 1)):
                     # Try next format.
@@ -446,6 +449,8 @@ class PrintTestPage(Question):
                     c.cancelJob (jobid)
                 except cups.IPPError as e:
                     (e, s) = e.args
+                    if sys.version_info < (3,0,0) and isinstance(s, bytes):
+                        s = s.decode('utf-8', 'replace')
                     if e != cups.IPP_NOT_POSSIBLE:
                         self.persistent_answers['test_page_cancel_failure'] = (e, s)
 
Index: system-config-printer-1.5.7/troubleshoot/PrinterStateReasons.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/PrinterStateReasons.py
+++ system-config-printer-1.5.7/troubleshoot/PrinterStateReasons.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -22,6 +22,7 @@
 
 from gi.repository import Gtk
 
+import sys
 import cups
 import ppdcache
 import statereason
@@ -66,7 +67,8 @@ class PrinterStateReasons(Question):
             text += '\n\n'
 
         state_reasons_list = dict['printer-state-reasons']
-        if type (state_reasons_list) == str:
+        if (sys.version_info >= (3,0,0) and type (state_reasons_list) == str) or
+           (sys.version_info < (3,0,0) and type (state_reasons_list) == unicode):
             state_reasons_list = [state_reasons_list]
 
         self.state_message = state_message
Index: system-config-printer-1.5.7/troubleshoot/QueueNotEnabled.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/QueueNotEnabled.py
+++ system-config-printer-1.5.7/troubleshoot/QueueNotEnabled.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/QueueRejectingJobs.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/QueueRejectingJobs.py
+++ system-config-printer-1.5.7/troubleshoot/QueueRejectingJobs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/RemoteAddress.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/RemoteAddress.py
+++ system-config-printer-1.5.7/troubleshoot/RemoteAddress.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/SchedulerNotRunning.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/SchedulerNotRunning.py
+++ system-config-printer-1.5.7/troubleshoot/SchedulerNotRunning.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/ServerFirewalled.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/ServerFirewalled.py
+++ system-config-printer-1.5.7/troubleshoot/ServerFirewalled.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/Shrug.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/Shrug.py
+++ system-config-printer-1.5.7/troubleshoot/Shrug.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/VerifyPackages.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/VerifyPackages.py
+++ system-config-printer-1.5.7/troubleshoot/VerifyPackages.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
@@ -23,7 +23,7 @@ from gi.repository import Gtk
 
 import subprocess
 from .base import *
-import os
+import os, sys
 from timedops import TimedSubprocess
 
 class VerifyPackages(Question):
@@ -45,6 +45,11 @@ class VerifyPackages(Question):
                     "hpijs",
                     "hplip",
                     "system-config-printer"]
+        if sys.version_info < (3,0,0):
+            null = file ("/dev/null", "r+")
+        else:
+            null = subprocess.DEVNULL
+
         parent = self.troubleshooter.get_window ()
 
         new_environ = os.environ.copy()
@@ -57,9 +62,9 @@ class VerifyPackages(Question):
                                            args=verification_args,
                                            close_fds=True,
                                            env=new_environ,
-                                           stdin=subprocess.DEVNULL,
+                                           stdin=null,
                                            stdout=subprocess.PIPE,
-                                           stderr=subprocess.DEVNULL)
+                                           stderr=null)
                 (verif_stdout, verif_stderr, result) = self.op.run ()
             except:
                 # Problem executing command.
Index: system-config-printer-1.5.7/troubleshoot/Welcome.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/Welcome.py
+++ system-config-printer-1.5.7/troubleshoot/Welcome.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/__init__.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/__init__.py
+++ system-config-printer-1.5.7/troubleshoot/__init__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/troubleshoot/base.py
===================================================================
--- system-config-printer-1.5.7.orig/troubleshoot/base.py
+++ system-config-printer-1.5.7/troubleshoot/base.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Printing troubleshooter
 
Index: system-config-printer-1.5.7/udev/udev-add-printer
===================================================================
--- system-config-printer-1.5.7.orig/udev/udev-add-printer
+++ system-config-printer-1.5.7/udev/udev-add-printer
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -sB
+#!/usr/bin/python -sB
 
 ## udev-add-printer
 
@@ -34,7 +34,10 @@ MFG_BLACKLIST=[
 
 def create_queue (c, printers, name, device_uri, ppdname, info, installer):
     # Make sure the name is unique.
-    namel = str (name.lower ())
+    if sys.version_info >= (3,0,0):
+        namel = str (name.lower ())
+    else:
+        namel = unicode (name.lower ())
     unique = False
     suffix = 1
     while not unique:
Index: system-config-printer-1.5.7/userdefault.py
===================================================================
--- system-config-printer-1.5.7.orig/userdefault.py
+++ system-config-printer-1.5.7/userdefault.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## Copyright (C) 2006, 2007, 2008, 2010, 2012, 2014 Red Hat, Inc.
 ## Author: Tim Waugh <twaugh@redhat.com>
@@ -20,6 +20,7 @@
 from gi.repository import Gtk
 import os
 import subprocess
+import sys
 
 class UserDefaultPrinter:
     def __init__ (self):
@@ -73,10 +74,14 @@ class UserDefaultPrinter:
         return None
 
     def set (self, default):
+        if sys.version_info < (3,0,0):
+            null = file ("/dev/null", "r+")
+        else:
+            null = subprocess.DEVNULL
         p = subprocess.Popen ([ "lpoptions", "-d", default ],
                               close_fds=True,
-                              stdin=subprocess.DEVNULL,
-                              stdout=subprocess.DEVNULL,
+                              stdin=null,
+                              stdout=null,
                               stderr=subprocess.PIPE)
         (stdout, stderr) = p.communicate ()
         exitcode = p.wait ()
Index: system-config-printer-1.5.7/xml/validate.py
===================================================================
--- system-config-printer-1.5.7.orig/xml/validate.py
+++ system-config-printer-1.5.7/xml/validate.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 
 ## system-config-printer
 
@@ -60,8 +60,8 @@ class Validator:
 
         for name in names:
             validates = False
-            print(("*** Driver type \"%s\" is never used" %
-                                 name), file=sys.stderr)
+            print >>sys.stderr, ("*** Driver type \"%s\" is never used" %
+                                 name)
 
         return validates
 
Index: system-config-printer-1.5.7/configure
===================================================================
--- system-config-printer-1.5.7.orig/configure
+++ system-config-printer-1.5.7/configure
@@ -6722,13 +6722,13 @@ $as_echo "#define HAVE_DCGETTEXT 1" >>co
 
         if test -n "$PYTHON"; then
       # If the user set $PYTHON, use it and don't search something else.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON version is >= 3" >&5
-$as_echo_n "checking whether $PYTHON version is >= 3... " >&6; }
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON version is >= 2.7" >&5
+$as_echo_n "checking whether $PYTHON version is >= 2.7... " >&6; }
       prog="import sys
 # split strings by '.' and convert to numeric.  Append some zeros
 # because we need at least 4 digits for the hex conversion.
 # map returns an iterator in Python 3.0 and a list in 2.x
-minver = list(map(int, '3'.split('.'))) + [0, 0, 0]
+minver = list(map(int, '2.7'.split('.'))) + [0, 0, 0]
 minverhex = 0
 # xrange is not present in Python 3.0 and range returns an iterator
 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
@@ -6749,8 +6749,8 @@ fi
     else
       # Otherwise, try each interpreter until we find one that satisfies
       # VERSION.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a Python interpreter with version >= 3" >&5
-$as_echo_n "checking for a Python interpreter with version >= 3... " >&6; }
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a Python interpreter with version >= 2.7" >&5
+$as_echo_n "checking for a Python interpreter with version >= 2.7... " >&6; }
 if ${am_cv_pathless_PYTHON+:} false; then :
   $as_echo_n "(cached) " >&6
 else
@@ -6761,7 +6761,7 @@ else
 # split strings by '.' and convert to numeric.  Append some zeros
 # because we need at least 4 digits for the hex conversion.
 # map returns an iterator in Python 3.0 and a list in 2.x
-minver = list(map(int, '3'.split('.'))) + [0, 0, 0]
+minver = list(map(int, '2.7'.split('.'))) + [0, 0, 0]
 minverhex = 0
 # xrange is not present in Python 3.0 and range returns an iterator
 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
Index: system-config-printer-1.5.7/killtimer.py
===================================================================
--- system-config-printer-1.5.7.orig/killtimer.py
+++ system-config-printer-1.5.7/killtimer.py
@@ -21,6 +21,7 @@
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 import threading
+import sys
 
 from gi.repository import GLib
 
openSUSE Build Service is sponsored by