Skip to content

Commit

Permalink
Merge pull request #528 from tianhao64/master
Browse files Browse the repository at this point in the history
Fixes #519, #448, #420, #421 Fix SoapAdapter serializer to support se…
  • Loading branch information
tianhao64 committed Mar 21, 2017
2 parents 3d2e025 + ac455dc commit 912e365
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyVmomi/SoapAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _Serialize(self, val, info, defNS):
# a bug.
val = val.decode(XML_ENCODING)
result = XmlEscape(val)
self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
self.writer.write(u'<{0}{1}>{2}</{0}>'.format(info.name, attr, result))

## Serialize a a data object (internal)
#
Expand Down
11 changes: 11 additions & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# VMware vSphere Python SDK
# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -40,6 +42,14 @@ def test_serialize_float(self):
pc.diskSpaceToAddressSpaceRatio = 1.0
SoapAdapter.Serialize(pc, version='vim.version.version10')

def test_serialize_unicode(self):
self.assertEqual(SoapAdapter.SerializeToUnicode('Ḃ'),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')
self.assertEqual(SoapAdapter.SerializeToUnicode(u'Ḃ'),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')
self.assertEqual(SoapAdapter.SerializeToUnicode(u'\u1e02'),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')

def _base_serialize_test(self, soap_creator, request_matcher):
my_vcr = config.VCR(
custom_patches=(
Expand Down Expand Up @@ -99,3 +109,4 @@ def soap_creator():
self._base_serialize_test(soap_creator, request_matcher)
finally:
GetRequestContext().pop("vcSessionCookie")

0 comments on commit 912e365

Please sign in to comment.