Skip to content

Commit cf0028e

Browse files
committed
NodeSet: accept decodable unicode strings
Change typecheck from str to basestring to give a try to any input unicode string (must be decodable). Closes #251. Change-Id: Ia0f6a23dd6809d31320d54dc599150c7f66a0d64
1 parent fbc55b5 commit cf0028e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/ClusterShell/NodeSet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def parse(self, nsobj, autostep):
784784
return nsobj
785785

786786
# or is nsobj a string?
787-
if type(nsobj) is str:
787+
if isinstance(nsobj, basestring):
788788
try:
789789
return self.parse_string(str(nsobj), autostep)
790790
except (NodeUtils.GroupSourceQueryFailed, RuntimeError), exc:

tests/NodeSetTest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,3 +2474,10 @@ def test_nd_fold_axis_multi(self):
24742474
n1.fold_axis = range(3)
24752475
self.assertEqual(str(n1), "da[1-2]c[1-2],ln[0-1],master,slave,x[1-2]y[1-2]z[1-2]")
24762476
self.assertEqual(len(n1), 16)
2477+
2478+
def test_unicode(self):
2479+
"""test NodeSet with unicode string"""
2480+
nodeset = NodeSet(u"node1")
2481+
self._assertNode(nodeset, "node1")
2482+
# not sure about that, can it work if PYTHONIOENCODING is set?
2483+
self.assertRaises(UnicodeEncodeError, NodeSet, u"\u0ad0[000-042]")

0 commit comments

Comments
 (0)