Menu

#251 Keyword in WSDL causes syntax error in generated code

open
None
5
2008-09-16
2008-09-16
No

This is part of my WSDL:

-----------------------------------------------------
<xs:complexType name="echoResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-----------------------------------------------------

And this is the code I use to call my webservice:

-----------------------------------------------------
import sys
from ZSI.ServiceProxy import ServiceProxy

wsdl = 'http://localhost:8080/syringe-syringe/EchoService?wsdl'

service = ServiceProxy(wsdl, tracefile=sys.stdout)
print service.echo("Echoed via ZSI")
-----------------------------------------------------

The auto-generated file .service_proxy_dir/http___localhost_8080_syringe_syringe_EchoService_wsdl_types.py now contains a syntax error: "self.return = None" on line 52 (I've attached the file, as well as my source code and the WSDL). The "return" on that line is the value of the "name" attribute in the WSDL.

I think it's rather strange that ZSI assumes that the name of an <xs:element /> will always be a valid variable name in Python. There should at least be a check and a workaround for this.

Discussion

  • Sybren A. Stüvel

     
  • Sybren A. Stüvel

     
  • Sybren A. Stüvel

    File Added: EchoService.wsdl

     
  • Sybren A. Stüvel

     
  • Sybren A. Stüvel

    File Added: EchoService_wsdl_types.py

     
  • Joshua Boverhof

    Joshua Boverhof - 2008-09-16
    • assigned_to: nobody --> boverhof
     
  • Joshua Boverhof

    Joshua Boverhof - 2008-09-16

    This isn't ZSI as a whole, this is the ServiceProxy module in particular attempting to employ the simplest algo possible. It uses the code generator, and by default shuts off name mangling for simplicity.

    # dont do anything to anames
    if not self._pyclass:
    containers.ContainerBase.func_aname = lambda instnc,n: str(n)

    You could replace this function with whatever you like eg. if n == "return": return "Return"

    ServiceProxy could easily be refactored to give you something that covered keywords..

    It was my intent that people who needed something more would use the pyclass option:

    ServiceProxy(wsdl, pyclass=True, ..)

    and this should solve your problem.

     

Log in to post a comment.