如何使用python suds为工厂创建的simpletype对象赋值?

时间:2012-10-27 18:37:22

标签: python suds

我正在使用python suds使用Cisco AXL库。我试图调用一个函数,我需要使用一个simpleType,它是一个带有名称限制的字符串的特殊实例。

在成功解析WSDL之后,我使用工厂创建了我的对象:

 uuid = client.factory.create('ns0:XUUID')

这是在WSDL附带的XSD中如下定义的以下XUUID对象的实例:

 <xsd:simpleType name="XUUID">
 <xsd:restriction base="xsd:string">
 <xsd:pattern value="\{........-....-....-....-............\}"/>
 </xsd:restriction>
 </xsd:simpleType>

我想现在设置我的uuid对象的值,我尝试了以下所有内容但没有成功:

 uuid.setText('{900AAAAC-E454-0B7E-07FD-FD67D48FF50E}')
 uuid.set('{900AAAAC-E454-0B7E-07FD-FD67D48FF50E}')

很明显,如果这是一个带有子元素的complexType,我可以设置它们,例如在suds文档中的Person.name。我无法弄清楚如何设置此对象的值。

对象的打印目录(uuid)暗示我可能会以错误的方式解决这个问题。

 ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__']

如果我遗漏了一些基本的东西或使用肥皂水完全错误,我会在下面解释一下上下文。

我正在尝试从WSDL中调用以下函数:

 <operation name="getDevicePool">
   <input message="s0:getDevicePoolIn"/>
   <output message="s0:getDevicePoolOut"/>
 </operation>
 <message name="getDevicePoolIn">
   <part element="xsd1:getDevicePool" name="axlParams"/>
 </message>

它反过来引用以下XSD元素:

 <xsd:element name='getDevicePool' type='axlapi:GetDevicePoolReq'></xsd:element>

 <xsd:complexType name='GetDevicePoolReq'>
 <xsd:sequence>
 <xsd:choice>
 <xsd:element name='name' type='axlapi:String100'></xsd:element>
 <xsd:element name='uuid' type='axlapi:XUUID'></xsd:element></xsd:choice>
 <xsd:element name='returnedTags' type='axlapi:RDevicePool' minOccurs='0'></xsd:element></xsd:sequence><xsd:attribute use='optional' name='sequence' type='xsd:unsignedLong'></xsd:attribute></xsd:complexType>

我尝试了一种适用于WSDL中另一个函数的方法:

 searchCriteria = {
         'callManagerGroupName':'Default'
 }
 devicePools = client.service.listDevicePool(searchCriteria)

但它在这里不起作用,我相信这是因为我需要我的UUID搜索字符串是一个XUUID类型。

1 个答案:

答案 0 :(得分:1)

通过对象属性为工厂创建的对象分配值。以我自己的代码为例:

>>> api = gcs.provider.get_api()
>>> client = api.get_client(api.API_DOMAIN)
>>> ident = client.factory.create('ns0:Identification')
>>> ident
(Identification){
   token = None
   user = None
   userPasswd = None
   oper = None
   operPasswd = None
   language = None
 }
>>> ident.user = 'Jeremy'
>>> ident
(Identification){
   token = None
   user = "Jeremy"
   userPasswd = None
   oper = None
   operPasswd = None
   language = None
 }
>>> setattr(ident, 'user', 'Lewis')
>>> ident
(Identification){
   token = None
   user = "Lewis"
   userPasswd = None
   oper = None
   operPasswd = None
   language = None
 }

您应该能够打印uuid对象以查看调用该属性的内容,然后只需指定该值。