Skip to content

Commit d709c94

Browse files
committed
WIP python3: fix xmlunwrap and its test to align with the use of bytes
FIXME: I'm quite unsure why xcp.xmlunwrap would want to use bytes and not unicode strings, but the encode/decode calls make it quite clear it wants to work with bytes. That makes the API painful to use in python3.
1 parent e002de0 commit d709c94

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

tests/test_xmlunwrap.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ def test(self):
1818

1919
self.assertEqual([getText(el)
2020
for el in getElementsByTagName(self.top_el, ["fred"])],
21-
["text1", "text2"])
21+
[b"text1", b"text2"])
2222

23-
x = getMapAttribute(self.top_el, ["mode"], [('test', 42), ('stuff', 77)])
23+
x = getMapAttribute(self.top_el, ["mode"], [(b'test', 42), (b'stuff', 77)])
2424
self.assertEqual(x, 42)
25-
x = getMapAttribute(self.top_el, ["made"], [('test', 42), ('stuff', 77)],
26-
default='stuff')
25+
x = getMapAttribute(self.top_el, ["made"], [(b'test', 42), (b'stuff', 77)],
26+
default=b'stuff')
2727
self.assertEqual(x, 77)
2828

2929
x = getStrAttribute(self.top_el, ["mode"])
30-
self.assertEqual(x, "test")
30+
self.assertEqual(x, b"test")
3131
x = getStrAttribute(self.top_el, ["made"])
32-
self.assertEqual(x, "")
32+
self.assertEqual(x, b"")
3333
x = getStrAttribute(self.top_el, ["made"], None)
3434
self.assertEqual(x, None)
3535

xcp/xmlunwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def getElementsByTagName(el, tags, mandatory = False):
4444
raise XmlUnwrapError("Missing mandatory element %s" % tags[0])
4545
return matching
4646

47-
def getStrAttribute(el, attrs, default = '', mandatory = False):
47+
def getStrAttribute(el, attrs, default=b'', mandatory=False):
4848
matching = []
4949
for attr in attrs:
5050
val = el.getAttribute(attr).encode()
51-
if val != '':
51+
if val != b'':
5252
matching.append(val)
5353
if len(matching) == 0:
5454
if mandatory:

0 commit comments

Comments
 (0)