views:

63

answers:

2

I'm connecting with a SUDS client to a SOAP Server whose wsdl contains many enumerations like the following:

</simpleType>
  <simpleType name="FOOENUMERATION">
  <restriction base="xsd:string">
   <enumeration value="ALPHA"><!-- enum const = 0 -->
   <enumeration value="BETA"/><!-- enum const = 1 -->
   <enumeration value="GAMMA"/><!-- enum const = 2 -->
   <enumeration value="DELTA"/><!-- enum const = 3 -->
  </restriction>
</simpleType>

In my client I am receiving sequences which contain elements of these various enumeration types. My need is that given a member variable, I need to know all possible enumeration values. Basically I need a function which takes an instance of one of these enums and returns a list of strings which are all the possible values.

When I have an instance, running:

print type(foo.enumInstance)

I get:

<class 'suds.sax.text.Text'>

I'm not sure how to get the actual simpleType name from this, and then get the possible values from that short of parsing the WSDL myself.

Edit: I've discovered a way to get the enumerations given the simpleType name, as below, so my problem narrows down to findingthe type name for a given variable, given that type(x) returns suds.sax.text.Text instead of the real name

 for l in  client.factory.create('FOOENUMERATION'):
    print l[0]
A: 

See if you can feed in the wsdl into the ElementTree component on python and use it to obtain the enumerations.

Khorkrak
A: 

I have figured out a rather hacky way to pull this off, but hopefully someone still has a better answer for me. For some reason objects returned from the server have enums with the suds.sax.text.Text type, but those created with the factory have types related to the enum, so this works:

def printEnums(obj,field):
     a=client.factory.create(str(getattr(client.factory.create( str(obj.__class__).replace('suds.sudsobject.','')),field).__class__).replace('suds.sudsobject.',''))
     for i in a:
         print i[0]

Then I can do: printEnums(foo,'enumInstance')

and even if foo was returned from the server and not created by a factory get a listing of the possible values for foo.enumInstance, since I factory create a new class of the same type as the one passed in. Still, I can't imagine that this mess is the correct/best way to do this.

bdk