列出使用Python SUDS进行SOAP枚举的所有可能值 [英] Listing all possible values for SOAP enumeration with Python SUDS

查看:150
本文介绍了列出使用Python SUDS进行SOAP枚举的所有可能值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SUDS客户端连接到SOAP服务器,其wsdl包含许多枚举,如下所示:

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)

我得到:

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

我不确定如何从中获取实际的simpleType名称,然后获取可能的值

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.

编辑:我发现了一种通过指定simpleType名称获得枚举的方法,如下所示,因此考虑到type(x)返回suds.sax.text.Text而不是真实名称,因此我的问题仅限于查找给定变量的类型名称

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]


推荐答案

我已经找到了一种相当巧妙的方法来实现这一目标,但是希望有人对我有更好的答案。出于某些原因,从服务器返回的对象具有 suds.sax.text .Text类型的枚举,但是使用工厂创建的对象具有与枚举相关的类型,因此可以使用:

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]

然后我可以做:

 printEnums(foo,'enumInstance')

,即使foo是从服务器返回而不是不是由工厂创建的,也可以获得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.

这篇关于列出使用Python SUDS进行SOAP枚举的所有可能值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆