diff --git a/pyVmomi/SoapAdapter.py b/pyVmomi/SoapAdapter.py
index 910720a..7363317 100644
--- a/pyVmomi/SoapAdapter.py
+++ b/pyVmomi/SoapAdapter.py
@@ -1,5 +1,5 @@
# VMware vSphere Python SDK
-# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
+# Copyright (c) 2008-2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
from __future__ import absolute_import
import six
-from six import PY2
-from six import PY3
from six import reraise
from six.moves import http_client
from six.moves import StringIO
@@ -24,10 +22,6 @@ from six.moves import zip
from six import u
from six import iteritems
-if PY3:
- long = int
- basestring = str
-
import sys
import os
import socket
@@ -497,14 +491,15 @@ class ParserError(KeyError):
# type for all parser faults.
pass
-def ReadDocument(parser, data):
+def ParseData(parser, data):
# NOTE (hartsock): maintaining library internal consistency here, this is
# a refactoring that rolls up some repeated code blocks into a method so
# that we can refactor XML parsing behavior in a single place.
- if not isinstance(data, str):
- data = data.read()
try:
- parser.Parse(data)
+ if isinstance(data, six.binary_type) or isinstance(data, six.text_type):
+ parser.Parse(data)
+ else:
+ parser.ParseFile(data)
except Exception:
# wrap all parser faults with additional information for later
# bug reporting on the XML parser code itself.
@@ -528,7 +523,7 @@ def Deserialize(data, resultType=object, stub=None):
parser = ParserCreate(namespace_separator=NS_SEP)
ds = SoapDeserializer(stub)
ds.Deserialize(parser, resultType)
- ReadDocument(parser, data)
+ ParseData(parser, data)
return ds.GetResult()
@@ -832,7 +827,7 @@ class SoapResponseDeserializer(ExpatDeserializerNSHandlers):
nsMap = {}
self.nsMap = nsMap
SetHandlers(self.parser, GetHandlers(self))
- ReadDocument(self.parser, response)
+ ParseData(self.parser, response)
result = self.deser.GetResult()
if self.isFault:
if result is None:
@@ -1163,7 +1158,7 @@ class GzipReader:
self.chunks = leftoverChunks
self.bufSize = leftoverBytes
- buf = "".join(chunks)
+ buf = b"".join(chunks)
return buf
## SOAP stub adapter object
diff --git a/tests/fixtures/test_unknown_fault.yaml b/tests/fixtures/test_unknown_fault.yaml
deleted file mode 100644
index 8c99ba4..0000000
--- a/tests/fixtures/test_unknown_fault.yaml
+++ /dev/null
@@ -1,274 +0,0 @@
-interactions:
-- request:
- body: '
-
-
-
- <_this type="ServiceInstance">ServiceInstance
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter
- ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware,
- Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware
- VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManager\n\n"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Length: ['3332']
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:40 GMT']
- Set-Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- status: {code: 200, message: OK}
-- request:
- body: '
-
-
-
- <_this type="SessionManager">SessionManagermy_usermy_password
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "\n\n\n52c20b61-24c3-f233-a549-d36d3ae68e14my_usermy_user
- 2014-07-29T18:58:41.001537Z2014-07-29T18:58:41.001537Zenen\n\n"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Length: ['665']
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:41 GMT']
- status: {code: 200, message: OK}
-- request:
- body: '
-
-
-
- <_this type="ServiceInstance">ServiceInstance
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter
- ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware,
- Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware
- VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManager\n\n"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Length: ['3332']
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:41 GMT']
- status: {code: 200, message: OK}
-- request:
- body: '
-
-
-
- <_this type="ServiceInstance">ServiceInstance
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter
- ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware,
- Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware
- VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManager\n\n"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Length: ['3332']
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:41 GMT']
- status: {code: 200, message: OK}
-- request:
- body: '
-
-
-
- <_this type="PropertyCollector">propertyCollectorLicenseManagerfalselicenseAssignmentManagerLicenseManagerfalse1
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "\n\n\nLicenseManagerlicenseAssignmentManagerLicenseAssignmentManager\n\n"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Length: ['652']
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:41 GMT']
- status: {code: 200, message: OK}
-- request:
- body: '
-
-
-
- <_this type="LicenseAssignmentManager">LicenseAssignmentManager
-
- '
- headers:
- Accept-Encoding: ['gzip, deflate']
- Content-Type: [text/xml; charset=UTF-8]
- Cookie: ['vmware_soap_session="52d6ea56-0052-259f-e3f6-8ea7a7f349cb"; Path=/;
- HttpOnly; Secure; ']
- SOAPAction: ['"urn:vim25/4.1"']
- method: POST
- uri: https://vcsa:443/sdk
- response:
- body: {string: "
-
-
-
- ServerFaultCode
-
-
-
- unknownReason
-
-
-
-"}
- headers:
- Cache-Control: [no-cache]
- Connection: [Keep-Alive]
- Content-Type: [text/xml; charset=utf-8]
- Date: ['Tue, 29 Jul 2014 18:58:41 GMT']
- Transfer-Encoding: [chunked]
- status: {code: 500, message: Internal Server Error}
-version: 1
diff --git a/tests/test_fault_deserializer.py b/tests/test_fault_deserializer.py
deleted file mode 100644
index 2a4a8e5..0000000
--- a/tests/test_fault_deserializer.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# VMware vSphere Python SDK
-# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-from tests import fixtures_path
-import unittest
-import vcr
-
-from pyVim import connect
-
-
-class DeserializerTests(unittest.TestCase):
-
- @vcr.use_cassette('test_unknown_fault.yaml',
- cassette_library_dir=fixtures_path, record_mode='once')
- def test_unknown_fault(self):
- # see: http://python3porting.com/noconv.html
- si = connect.Connect(host='vcsa',
- user='my_user',
- pwd='my_password')
- content = si.RetrieveContent()
- lm = content.licenseManager
- # NOTE (hartsock): assertIsNotNone does not work in Python 2.6
- self.assertTrue(lm is not None)
- lam = lm.licenseAssignmentManager
- # NOTE (hartsock): assertIsNotNone does not work in Python 2.6
- self.assertTrue(lam is not None)
- # cassette is altered to raise a fault here:
- fault = None
- try:
- lam.QueryAssignedLicenses()
- except Exception as ex:
- # NOTE (hartsock): not using 'assertRaises' so we can inspect obj
- fault = ex
- # NOTE (hartsock): assertIsNotNone does not work in Python 2.6
- self.assertTrue(fault is not None) # only until 2.6 support is dropped
- # Observe that the malformed XML was reported up the stack to the
- # user so that field reports will contain SOAP message information.
- self.assertTrue(' '
- ' '
- 'unknownReason'
- ' '
- '' in str(fault))