Juan Hernandez has uploaded a new change for review.

Change subject: sdk: Use alternative imports for Python 3
......................................................................

sdk: Use alternative imports for Python 3

This patch checks for import errors and tries to import alternative
modules that work with Python 3, in particular it tries the following
alternatives:

  urlparse -> urllib.parse
  UserDict -> collections.UserDict
  thread -> _thread

Change-Id: I79748d9dac0961dc290e539ae9f8e555bcd0aa2a
Related: https://bugzilla.redhat.com/1096137
Signed-off-by: Juan Hernandez <[email protected]>
---
M 
generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/EntryPointHeadTemplate
M src/ovirtsdk/api.py
M src/ovirtsdk/utils/ordereddict.py
M src/ovirtsdk/utils/reflectionhelper.py
M src/ovirtsdk/utils/searchhelper.py
5 files changed, 31 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/28/41328/1

diff --git 
a/generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/EntryPointHeadTemplate
 
b/generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/EntryPointHeadTemplate
index e181081..83500f5 100644
--- 
a/generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/EntryPointHeadTemplate
+++ 
b/generator/src/main/java/org/ovirt/engine/sdk/generator/python/templates/EntryPointHeadTemplate
@@ -23,7 +23,11 @@
 $timestamp$
 
 import re
-import urlparse
+
+try:
+    import urlparse
+except ImportError:
+    import urllib.parse as urlparse
 
 from ovirtsdk.infrastructure.errors import UnsecuredConnectionAttemptError
 from ovirtsdk.infrastructure.connectionspool import ConnectionsPool
diff --git a/src/ovirtsdk/api.py b/src/ovirtsdk/api.py
index bc269d3..cdeb280 100644
--- a/src/ovirtsdk/api.py
+++ b/src/ovirtsdk/api.py
@@ -20,10 +20,14 @@
 ############ GENERATED CODE ############
 ########################################
 
-'''Generated at: 2015-05-22 11:32:13.000771'''
+'''Generated at: 2015-05-22 12:10:41.000344'''
 
 import re
-import urlparse
+
+try:
+    import urlparse
+except ImportError:
+    import urllib.parse as urlparse
 
 from ovirtsdk.infrastructure.errors import UnsecuredConnectionAttemptError
 from ovirtsdk.infrastructure.connectionspool import ConnectionsPool
diff --git a/src/ovirtsdk/utils/ordereddict.py 
b/src/ovirtsdk/utils/ordereddict.py
index 187f72a..562201a 100644
--- a/src/ovirtsdk/utils/ordereddict.py
+++ b/src/ovirtsdk/utils/ordereddict.py
@@ -1,6 +1,13 @@
 
-from UserDict import UserDict
-import thread
+try:
+    from UserDict import UserDict
+except ImportError:
+    from collections import UserDict
+
+try:
+    import thread
+except ImportError:
+    import _thread as thread
 
 class OrderedDict(UserDict):
     """A dictionary preserving insert order"""
diff --git a/src/ovirtsdk/utils/reflectionhelper.py 
b/src/ovirtsdk/utils/reflectionhelper.py
index 942f20c..f6fc00d 100644
--- a/src/ovirtsdk/utils/reflectionhelper.py
+++ b/src/ovirtsdk/utils/reflectionhelper.py
@@ -15,7 +15,11 @@
 #
 
 import inspect
-import thread
+
+try:
+    import thread
+except ImportError:
+    import _thread as thread
 
 class ReflectionHelper():
     cache = {}
diff --git a/src/ovirtsdk/utils/searchhelper.py 
b/src/ovirtsdk/utils/searchhelper.py
index 1a7ea3e..44d7e28 100644
--- a/src/ovirtsdk/utils/searchhelper.py
+++ b/src/ovirtsdk/utils/searchhelper.py
@@ -14,9 +14,13 @@
 # limitations under the License.
 #
 
-from urllib import urlencode
-import re
 import fnmatch
+import re
+
+try:
+    from urllib import urlencode
+except ImportError:
+    from urllib.parse import urlencode
 
 class SearchHelper():
 


-- 
To view, visit https://gerrit.ovirt.org/41328
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I79748d9dac0961dc290e539ae9f8e555bcd0aa2a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to