Skip to content

Commit

Permalink
python3: KeyError uses '%' not format method
Browse files Browse the repository at this point in the history
* Malformed Faults: introduces test for fault handler
* fixes KeyError raises statements to use 'format' instead

partial: vmware#72
partial: vmware#55
  • Loading branch information
hartsock committed Jul 29, 2014
1 parent 297302c commit 6f36a6a
Show file tree
Hide file tree
Showing 4 changed files with 324 additions and 13 deletions.
13 changes: 5 additions & 8 deletions pyVmomi/SoapAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,7 @@ def StartElementHandler(self, tag, attr):
if not self.stack:
if self.isFault:
ns, name = self.SplitTag(tag)
try:
objType = self.LookupWsdlType(ns, name[:-5])
except KeyError:
message = "{0} was not found in the WSDL".format(name[:-5])
raise VmomiMessageFault(message)
objType = self.LookupWsdlType(ns, name[:-5])
# Only top level soap fault should be deserialized as method fault
deserializeAsLocalizedMethodFault = False
else:
Expand Down Expand Up @@ -1257,12 +1253,13 @@ def InvokeMethod(self, mo, info, args, outerStub=None):
fd = GzipReader(resp, encoding=GzipReader.GZIP)
elif encoding == 'deflate':
fd = GzipReader(resp, encoding=GzipReader.DEFLATE)
obj = SoapResponseDeserializer(outerStub).Deserialize(fd, info.result)
except:
deserializer = SoapResponseDeserializer(outerStub)
obj = deserializer.Deserialize(fd, info.result)
except Exception as exc:
conn.close()
# The server might be sick, drop all of the cached connections.
self.DropConnections()
raise
raise exc
else:
resp.read()
self.ReturnConnection(conn)
Expand Down
10 changes: 5 additions & 5 deletions pyVmomi/VmomiSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def _SetWsdlType(ns, wsdlName, typ):
# @return type if found else throws KeyError
def GetWsdlType(ns, name):
if ns is None or name is None:
raise KeyError("%s %s" % (ns, name))
raise KeyError("%s %s".format(ns, name))

with _lazyLock:
# Check if the type is loaded in the map
Expand All @@ -1003,14 +1003,14 @@ def GetWsdlType(ns, name):
try:
return GetWsdlType(ns, name[7:]).Array
except KeyError:
raise KeyError("%s %s" % (ns, name))
raise KeyError("%s %s".format(ns, name))
else:
# Type is not loaded yet, load it
typ = _LoadVmodlType(_wsdlDefMap[(ns, name)][0])
if typ:
return typ

raise KeyError("%s %s" % (ns, name))
raise KeyError("%s %s".format(ns, name))

## Guess the type from wsdlname with no ns
# WARNING! This should not be used in general, as there is no guarantee for
Expand All @@ -1026,7 +1026,7 @@ def GuessWsdlType(name):
try:
return GetWsdlType(ns, name)
except KeyError:
pass
pass
raise KeyError(name)

## Return a map that contains all the wsdl types
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def GetWsdlMethod(ns, wsdlName):
LoadManagedType(*method)
return _wsdlMethodMap[(ns, wsdlName)]
else:
raise KeyError("%s %s" % (ns, name))
raise KeyError("%s %s".format(ns, name))

## Guess the method from wsdlname with no ns
# WARNING! This should not be used in general, as there is no guarantee for
Expand Down
Loading

0 comments on commit 6f36a6a

Please sign in to comment.