[molecule] restore Python 3.x compatibility
This commit is contained in:
@@ -170,3 +170,9 @@ def isnumber(obj):
|
||||
return isinstance(obj, int)
|
||||
else:
|
||||
return isinstance(obj, (int, long,))
|
||||
|
||||
def is_python3():
|
||||
"""
|
||||
Return True, if the interpreter is Python 3.x
|
||||
"""
|
||||
return sys.hexversion >= 0x3000000
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
import os
|
||||
import shlex
|
||||
|
||||
from molecule.compat import convert_to_unicode, convert_to_rawstring
|
||||
from molecule.compat import convert_to_unicode, convert_to_rawstring, \
|
||||
is_python3
|
||||
import molecule.utils
|
||||
|
||||
class GenericSpecFunctions(object):
|
||||
@@ -56,8 +57,11 @@ class GenericSpecFunctions(object):
|
||||
return convert_to_unicode(x).strip().split()
|
||||
|
||||
def ve_command_splitter(self, x):
|
||||
x_str = x
|
||||
if not is_python3():
|
||||
x_str = convert_to_rawstring(x)
|
||||
return [convert_to_unicode(y) for y in \
|
||||
shlex.split(convert_to_rawstring(x))]
|
||||
shlex.split(x_str)]
|
||||
|
||||
def ve_integer_converter(self, x):
|
||||
return int(x)
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ sys.path.insert(0,'..')
|
||||
import unittest
|
||||
import tempfile
|
||||
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.compat import get_stringtype, convert_to_rawstring
|
||||
from molecule.utils import md5sum, copy_dir, get_random_number, \
|
||||
remove_path_sandbox, remove_path, mkdtemp, empty_dir, \
|
||||
exec_cmd_get_status_output, exec_cmd, is_exec_available, \
|
||||
@@ -28,7 +28,7 @@ class UtilsTest(unittest.TestCase):
|
||||
def test_md5sum(self):
|
||||
|
||||
tmp_fd, tmp_path = tempfile.mkstemp(dir=os.getcwd())
|
||||
os.write(tmp_fd, "hello")
|
||||
os.write(tmp_fd, convert_to_rawstring("hello"))
|
||||
os.close(tmp_fd)
|
||||
result = md5sum(tmp_path)
|
||||
self.assertEqual(result, "5d41402abc4b2a76b9719d911017c592")
|
||||
|
||||
Reference in New Issue
Block a user