【问题标题】:How can I assign a value to a factory created simpletype object with python suds?如何使用 python suds 为工厂创建的 simpletype 对象赋值?
【发布时间】:2012-10-27 18:37:22
【问题描述】:

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

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

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

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

 <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 类型。

【问题讨论】:

    标签: python suds


    【解决方案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 对象以查看调用的属性,然后简单地分配值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 2010-11-10
      相关资源
      最近更新 更多