[python-bugzilla] [PATCH 13/13] Make imports python3 compatible

abn at redhat.com abn at redhat.com
Tue Oct 29 13:22:32 UTC 2013


From: Arun Babu Neelicattu <abn at redhat.com>

---
 bin/bugzilla           |  8 +++++++-
 bugzilla/__init__.py   |  8 +++++++-
 bugzilla/base.py       | 18 ++++++++++++++----
 tests/__init__.py      |  6 ++++--
 tests/rw_functional.py |  6 +++++-
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/bin/bugzilla b/bin/bugzilla
index da0b52e..5190d11 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -23,7 +23,13 @@ import socket
 import sys
 import tempfile
 
-from xmlrpclib import Fault, ProtocolError
+if sys.version_info.major >= 3:
+    # pylint: disable=F0401,W0622
+    from xmlrpc.client import Fault, ProtocolError
+    basestring = (str, bytes)
+else:
+    from xmlrpclib import Fault, ProtocolError
+
 from requests.exceptions import SSLError
 
 import bugzilla
diff --git a/bugzilla/__init__.py b/bugzilla/__init__.py
index 1f9edb9..e6fdeef 100644
--- a/bugzilla/__init__.py
+++ b/bugzilla/__init__.py
@@ -12,8 +12,14 @@
 __version__ = "0.9.0"
 version = __version__
 
+import sys
 from logging import getLogger
-from xmlrpclib import Fault, ServerProxy
+
+if sys.version_info.major >= 3:
+    # pylint: disable=F0401
+    from xmlrpc.client import Fault, ServerProxy
+else:
+    from xmlrpclib import Fault, ServerProxy
 
 log = getLogger("bugzilla")
 
diff --git a/bugzilla/base.py b/bugzilla/base.py
index 024c839..774a5a6 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -13,11 +13,21 @@ import locale
 import os
 import sys
 
-from ConfigParser import SafeConfigParser
-from cookielib import LoadError, LWPCookieJar, MozillaCookieJar
 from io import BytesIO
-from urlparse import urlparse, parse_qsl
-from xmlrpclib import Binary, Fault, ProtocolError, ServerProxy, Transport
+
+if sys.version_info.major >= 3:
+    # pylint: disable=F0401,E0611
+    from configparser import SafeConfigParser
+    from http.cookiejar import LoadError, LWPCookieJar, MozillaCookieJar
+    from urllib.parse import urlparse, parse_qsl
+    from xmlrpc.client import (
+        Binary, Fault, ProtocolError, ServerProxy, Transport)
+else:
+    from ConfigParser import SafeConfigParser
+    from cookielib import LoadError, LWPCookieJar, MozillaCookieJar
+    from urlparse import urlparse, parse_qsl
+    from xmlrpclib import (
+        Binary, Fault, ProtocolError, ServerProxy, Transport)
 
 import requests
 
diff --git a/tests/__init__.py b/tests/__init__.py
index 38c252b..0cc7108 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -2,14 +2,16 @@
 from __future__ import print_function
 
 import atexit
-import commands
 import difflib
 import imp
 import os
 import shlex
 import sys
 
-from StringIO import StringIO
+if sys.version_info.major >= 3:
+    from io import StringIO
+else:
+    from StringIO import StringIO
 
 
 _cleanup = []
diff --git a/tests/rw_functional.py b/tests/rw_functional.py
index ffcb640..a71dffe 100644
--- a/tests/rw_functional.py
+++ b/tests/rw_functional.py
@@ -17,7 +17,11 @@ import random
 import sys
 import unittest
 
-from urlparse import urlparse
+if sys.version_info.major >= 3:
+    # pylint: disable=F0401,E0611
+    from urllib.parse import urlparse
+else:
+    from urlparse import urlparse
 
 import bugzilla
 from bugzilla import Bugzilla
-- 
1.8.3.1



More information about the python-bugzilla mailing list