Giter VIP home page Giter VIP logo

soapfish's Introduction

Soapfish

PyPI Version PyPI License PyPI Downloads PyPI Status PyPI Wheel PyPI Python Versions PyPI Implementation

GitHub License GitHub Version GitHub Workflow Status

LGTM Total Alerts LGTM Language Grade: Python

No Maintenance Intended

This project is not actively maintained. If you only need a dynamic client using a predefined WSDL rather than generated code, it is recommended that you check out Zeep.

Introduction

Soapfish is a library to use SOAP services in Python. The server-side component can be used with Django & Flask and other frameworks (including plain WSGI). The library can also be used to implement SOAP clients.

The library can help parsing/serializing a Python class model from/to XML and a bare-bones SOAP client.

Currently the project supports the following:

  • SOAP 1.1 and 1.2
  • WSDL 1.1
  • WS-Addressing

Other notable features include:

  • Support for Python 3.7+
  • Licensed under the 3-clause BSD license
  • Code generation utilities to get started quickly
  • Parsing/serializing a Python class model from/to XML so you can easily work with XML even if you don't use SOAP at all.

soapfish's People

Contributors

bouke avatar dpowazka avatar felixschwarz avatar funkybob avatar iurisilvio avatar ngnpope avatar oskrkal avatar stephane avatar techdragon avatar xavfernandez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

soapfish's Issues

Defaults for minOccurs/maxOccurs on ListElement should match the XML spec

Currently the default values for minOccurs/maxOccurs on the ListElement are none. I think this means the attributes are omitted when rendering a WSDL/XML schema but at least for maxOccurs this means you can add too many items to the element resulting in an invalid state.

We should make sure that our defaults are the same as the XML spec (bonus: try to keep the generated WSDL/XML schema minimal, omitting the attribute if it equals 1). For minOccurs we probably can't enforce the restriction right away because we need a way to start with an empty list and append values but maxOccurs should be always checked.

Maybe we should also warn/raise if we are about to render XML but the amount of items does not match the occurrence constraints?

Round trip through wsdl2py and py2wsdl should be consistent.

Round trips through the code generation and back to the WSDL are inconsistent.

<wsdl:service name="PutOps">
    <wsdl:port name="PutOpsPort" binding="tns:PutOpsBinding">
        <!-- ... --->
    </wsdl:port>
</wsdl:service>

put through code generation becomes:

PutOpsPort_SERVICE = soap.Service(
    name='PutOpsPortType',
    ...
)

which going back incorrectly becomes:

<wsdl:service name="PutOpsPort">
    <wsdl:port name="PutOpsPortPort" binding="tns:PutOpsPortBinding">
        <!-- ... --->
    </wsdl:port>
</wsdl:service>

...and so on...

Also of note is that soapfish.py2wsdl expects SERVICE which isn't available without editing the name of PutOpsPort_SERVICE.

I've put this into the 0.7.0 milestone as whatever fix we come up with will be a breaking change and also because I'm not yet sure how this should be solved.

ability to specify details for SOAP faults

soapfish does not support additional details in soapfaults. Martin Mrose added support for that in f1559ca but that implementation is too hacky. Also the current code is much better suited for that because a service can already return a SOAPError which should be extended to include detail information.

Steps for implementation:

  • extend SOAP 1.1 Fault class (soapfish.soap11.Fault) with detail argument
  • extend SOAP 1.2 Fault class (soapfish.soap12.Fault) with detail argument
  • extend SOAPError with detail attribute
  • render detail tag in SOAPDispatcher
  • SOAP.parse_fault_message() should handle additional details
  • client stub should return fault details

additional information:

django_.django_dispatch fails when request type is ASGI -> request.environ not found.

My Django application uses soapfish to provide a SOAP service. This service provides an async callback mechanism for long running functions for calls made on a remote SOAP server.

I also need to provide feedback to the user when the long running process completes (without refresh). Websockets seemed to me the correct way to go, so I added Channels to my Django application.

This caused the following line to choke since the ASGI request does not have an 'environ' variable:
soap_request = SOAPRequest(DjangoEnvironWrapper(request.environ), body)

I did a lot of Google searching, found a few notes suggesting I use the ASGI to WSGI adapter, but looks like Channels is so new that the adapter doesn't exist yet.

Long story short, found a post stating that request.environ is the same thing as request.META, which the ASGI request does have.

I have modified my local copy to read:
soap_request = SOAPRequest(DjangoEnvironWrapper(request.META), body)

This appears to work, but am wondering if I'm going about this the wrong way and not sure if it warrants a Pull Request.

Thanks!

Remote imports are handled as local files

$ xsd2py https://www.broadband-forum.org/cwmp/cwmp-1-4.xsd
Traceback (most recent call last):
  File "/home/default/.virtualenvs/soapfish/bin/xsd2py", line 9, in <module>
    load_entry_point('soapfish==0.6.0.dev0', 'console_scripts', 'xsd2py')()
  File "/code/soapfish/soapfish/xsd2py.py", line 184, in main
    code = generate_code_from_xsd(xml, encoding='utf-8', cwd=cwd)
  File "/code/soapfish/soapfish/xsd2py.py", line 77, in generate_code_from_xsd
    standalone=standalone)
  File "/code/soapfish/soapfish/xsd2py.py", line 162, in schema_to_py
    return tpl.render(schema=schema, cwd=cwd, base_path=base_path)
  File "/home/default/.virtualenvs/soapfish/local/lib/python2.7/site-packages/Jinja2-2.8-py2.7.egg/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/default/.virtualenvs/soapfish/local/lib/python2.7/site-packages/Jinja2-2.8-py2.7.egg/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/code/soapfish/soapfish/templates/xsd", line 11, in top-level template code
    {{- resolve_import(i, known_paths, known_types, schema.targetNamespace, cwd, base_path) }}
  File "/code/soapfish/soapfish/xsd2py.py", line 46, in resolve_import
    xml = open_document(path)
  File "/code/soapfish/soapfish/utils.py", line 38, in open_document
    with open(path, 'rb') as f:
IOError: [Errno 2] No such file or directory: '/code/soapfish/https:/www.broadband-forum.org/cwmp/../../../../../../../../cwmp/cwmp-1-3.xsd'

The include statement is:

<xs:include schemaLocation="/cwmp/cwmp-1-3.xsd"/>

xsd2py: maxOccurs=1 added to xsd.Element

xsd.Element does not support the maxOccurs property (because maxOccurs=0 is not allowed and maxOccurs > 1 is handled by xsd.ListElement). However the xsd template renders xsd.Element(..., maxOccurs=1) if the maxOccurs attribute was present in the wsdl.

add missing information about soapbox-bsd releases to CHANGES file

Polyconseil released versions 0.4.0, 0.5.0, and 0.5.1 but there are no entries in the CHANGES files.

Also we need to document any changes for the current 0.6 release:

  • soapfish renaming
  • rename: SOAPResponse, SOAPRequest
  • fixes for wsdl2py and xsd2py when using Python 3
  • restored ability to validate parsed XML using a provided soapbox schema in ComplexType
  • fix exception in SOAPDispatcher when the handler does not return a SoapboxResponse (now SOAPResponse, see above)

Wrong value object type for ComplexType

Hi,
I installed this beautiful lib, I used wsdl2py to generate the class python, no errors, all seem ok.
I tested my link to django dispatcher with "?wsdl" option in the path with SoapUI, the project in SoapUI is created correctly, but when I run the test with values this is the error:

Internal Server Error: /SmarTicket/soapfish
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 113, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/django_.py", line 31, in django_dispatch
    soap_response = soap_dispatcher.dispatch(soap_request)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/soap_dispatch.py", line 151, in dispatch
    return self.handle_soap_request(request)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/soap_dispatch.py", line 195, in handle_soap_request
    response.http_content = SOAP.Envelope.response(tagname, response.soap_body, header=response.soap_header)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/soap11.py", line 91, in response
    envelope.Body.message = xsd.NamedType(name=tagname, value=return_object)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/xsd.py", line 1193, in __init__
    self.value = value
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/xsd.py", line 848, in __setattr__
    super(ComplexType, self).__setattr__(attr, field.accept(value))
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/xsd.py", line 542, in accept
    return self._type.accept(value)
  File "/usr/local/lib/python2.7/site-packages/soapfish-0.6dev-py2.7.egg/soapfish/xsd.py", line 866, in accept
    raise ValueError('Wrong value object type %r for %s.' % (value, self.__class__.__name__))
ValueError: Wrong value object type <class 'appTicket.test_soapfish_wsdl_server.NotifyResponse'> for ComplexType.

In this link there is the wsdl file and the original python generated code from wsd2py:
https://drive.google.com/folderview?id=0B0uiGluEWZlOT0x3cWp2c20wdGc&usp=sharing

Please help me, if possible!

thanx
Vale

XSD elements order must not be important

Related to #72 PR failing test.

Soapfish generate invalid code if xsd:restriction and xsd:extension are defined before the base element.

I'm trying to fix it, but I don't know the best approach:

  1. Reorder XSD elements in runtime.
  2. Make EXTENSION and RESTRICTION classes inherit from ComplexType and define the class as a class attribute.
  3. Make EXTENSION and RESTRICTION render after all other types.

All of these options are not easy to implement.

Do you have any other ideas?

I can work on it, but didn't decided how to handle the problem.

Refactor handling of location rewriting.

Currently we have multiple ways of handling rewriting of locations in soapfish.soap.Stub:

  1. Pass the location argument when initialising.
  2. Pass the base_url argument when initialising to extract a scheme and host from.
  3. Alter the SCHEME and HOST class attributes. (Although this means changing generated code.)

See https://github.com/soapteam/soapfish/blob/737fefc/soapfish/soap.py#L98-L118

We should deprecate or remove base_url and allow location to be a string or a callable.

If feasible we should also remove SCHEME and HOST and let people manage rewriting locations entirely within their own callable. This would also remove all the template generation tricks and simplify the code.

The main challenge would be handling the rewriting in the WSDL, but that would benefit from some tidying up to avoid the round-trip through decode() and encode() on Python 3:

https://github.com/soapteam/soapfish/blob/737fefc/soapfish/soap_dispatch.py#L209-L222

come up with new project description

Currently the project description is very much focused on Django integration which is actually not the main point of the project anymore. We need a new description about implementing SOAP services in Python, using pre-existing WSDL and (if necessary) bug-for-bug compatibility with clients.

This needs to be replaced in several places, searching for "django" should reveal most of them.

Named XSD Element with unnamed complexType child generates invalid python.

I'm dealing with a 3rd party vendor and their XSD schema seems to have revealed a shortcoming of soapfish's xsd2py functionality, and by extension, its wsdl2py functionality as well.

The trouble seems to be when an element and complex type are used like this in an XSD.

<xs:element name="fooCreateRequest">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="FooCreateRequestBaseType"/>
        </xs:complexContent>
    </xs:complexType>
</xs:element>

<xs:complexType name="FooCreateRequestType">
    <xs:annotation>
        <xs:documentation>Foo Details to be created</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
        <xs:extension base="FooCreateRequestBaseType">
            <xs:attribute name="version" type="xs:decimal" default="1" />
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

Initially this was just failing to generate at all, throwing a TypeError: 'NoneType' object is not subscriptable, one quick edit to the capitalize function in soapfish/utils.py and I was able to get it to generate the following python.

class FooCreateRequestType(FooCreateRequestBaseType):
    XSI_TYPE = xsd_types.XSDQName('https://www.example.com/ws', 'FooCreateRequestType')
    INHERITANCE = xsd.Inheritance.EXTENSION
    version = xsd.Attribute(xsd.Decimal, use=xsd.Use.OPTIONAL)


class (FooCreateRequestType):
    XSI_TYPE = xsd_types.XSDQName('https://www.example.com/ws', 'fooCreateRequest')
    INHERITANCE = xsd.Inheritance.EXTENSION

So it's not generating the classname.

I've cooked up a quick fix to this in my own local fork, but before I create a pull request that might mess up some of the work that is going on in @oskrkal 's branch over here in https://github.com/oskrkal/soapfish/tree/references , it seemed like I should check that I have actually fixed it correctly in the eyes of some people more familiar with what the code should be doing, not just written something that generates valid python syntax that won't do what it needs to do later.

My implemented fix generates the following code by checking for the existence of the complex type object name and using some extra logic to handle the case when the complex type object name is None

class FooCreateRequestType(FooCreateRequestBaseType):
    XSI_TYPE = xsd_types.XSDQName('https://www.example.com/ws', 'FooCreateRequestType')
    INHERITANCE = xsd.Inheritance.EXTENSION
    version = xsd.Attribute(xsd.Decimal, use=xsd.Use.OPTIONAL)


class FooCreateRequest(FooCreateRequestType):
    XSI_TYPE = xsd_types.XSDQName('https://www.example.com/ws', 'fooCreateRequest')
    INHERITANCE = xsd.Inheritance.EXTENSION

Does this look correct? I'm a little unsure about the capitalisation of the classname FooCreateRequest since it seems like it could be meant to match up with one of the names generated in the operations section, but it could just as easily not be meant to since that part also says "Put your own implementation here."

def FooCreate(request, fooCreateRequest):
    # TODO: Put your implementation here.
    return fooCreateResponse

With fooCreateResponse being undefined, but a FooCreateResponse has been generated.

screen/integrate changes from numion

There is a soapbox fork by "numion" which contains a lot of changes which look interesting. We should screen the repository and integrate whatever commits look sensible.

Licensing note: The code was forked after the OSL relicensing but the author agreed in private email to license all changes.

As for licensing, all changes are originally authored by me, to the best of my
knowledge, no other entity has any copyright interest, you can use them under
the BSD license.

add support for union types

Currently we don't support Union types. Martin Mrose added support for that in 321d896 and 40535bf. These changes could be integrated but the code needs some tests and cleanups.

Soapfish wsdl2py Error

I downloaded the ZIP (soapfish-master.zip) from https://github.com/FelixSchwarz/soapfish

I am on Windows 7 and Python 2.7

I am getting relative imports error when executing wsdl2py

D:\Projects\SOAP\soapfish>python C:\Python27\Lib\site-packages\soapfish-0.6dev-py2.7.egg\soapfish\wsdl2py.py -c Doc.wsdl
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\soapfish-0.6dev-py2.7.egg\soapfish\wsdl2py.py", line 16, in module
from .soap import SOAP_HTTP_Transport, SOAPVersion
ValueError: Attempted relative import in non-package`

So i had to replace at all places where relative import was done

from .soap import SOAP_HTTP_Transport, SOAPVersion
to
from soap import SOAP_HTTP_Transport, SOAPVersion

and

from . import namespaces as ns
to
import namespaces as ns

and likewise.

Following that, the wsdl2py command gives this error. The WSDL I am working with is at http://dpaste.com/2XP4NP6

The Traceback is at http://dpaste.com/1KH7W99 (not pasting in the body of the issue as the markdown is messing it up)

Regards,
Guddu

Add template file extensions.

File extensions enable automatic syntax highlighting in the majority of code editing tools. Many editors only provide the ability to syntax highlight based on a file's extension, so files without an extensions cannot be highlighted in such editors. Providing file extensions to fix this.

I've created PR #101 as a small quality of life improvement.

interoperability with WCF service

Hi!

I'm trying to use soapbox-bsd to acess wcf web service. I have generated client from wsdl with wsdl2py.

It works for methods with simple parameters, but does not works when method require some complex type as parameter.

A i understand, serialization of request is incorrect. WCF requires namespace for some elements:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/AddContract</Action>
  </s:Header>
  <s:Body>
    <AddContract xmlns="http://tempuri.org/">
      <CI xmlns:d4p1="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:ADDRESS i:nil="true" />
        <d4p1:ActCode i:nil="true" />
        <d4p1:BALANCE>0</d4p1:BALANCE>
        <d4p1:BIK i:nil="true" />
        <d4p1:Bank i:nil="true" />
        <d4p1:ClientName i:nil="true" />
        <d4p1:ContactTelefon i:nil="true" />
        <d4p1:ContractID>0</d4p1:ContractID>
        <d4p1:Dogovor i:nil="true" />
        <d4p1:EMAIL i:nil="true" />
        <d4p1:FIO i:nil="true" />
        <d4p1:FioLeader i:nil="true" />
        <d4p1:INN i:nil="true" />
        <d4p1:ISACTIVITY>0</d4p1:ISACTIVITY>
        <d4p1:ISPHYSICAL>0</d4p1:ISPHYSICAL>
        <d4p1:JuridicalAdress i:nil="true" />
        <d4p1:KPP i:nil="true" />
        <d4p1:KSCHET i:nil="true" />
        <d4p1:Login i:nil="true" />
        <d4p1:Organization i:nil="true" />
        <d4p1:PASPORT i:nil="true" />
        <d4p1:Password i:nil="true" />
        <d4p1:PostLeader i:nil="true" />
        <d4p1:RSCHET i:nil="true" />
        <d4p1:ReasonDoc i:nil="true" />
        <d4p1:TARIF>0</d4p1:TARIF>
        <d4p1:TELEFON i:nil="true" />
        <d4p1:TariffName i:nil="true" />
      </CI>
    </AddContract>
  </s:Body>
</s:Envelope>

But namespace 'd4p1' is missing in xml generated by soapbox-bsd.

Is it possible to solve?

Simple type restriction generate invalid Python code

I just get the biggest WSDL I have here and tried wsdl2py. It almost worked. I'm just reporting some issues I found, but it is not critical to me now.

This WSDL generate an invalid Python code.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://example.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <xsd:schema>
            <xsd:complexType name="ComplexType">
                <xsd:sequence>
                    <xsd:element name="RestrictedString">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="60" />
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
</wsdl:definitions>

This is the broken class ComplexType generated:

class ComplexType(xsd.ComplexType):
    INHERITANCE = None
    INDICATOR = xsd.Sequence
    RestrictedString = xsd.Element(xsd.String()

    @classmethod
    def create(cls):
        instance = cls()
        return instance

Relative imports

Imports with relative schemaLocation does not work.

For example:

file1.xsd

<xsd:import schemaLocation="folder/file2.xsd" namespace="http://mynamespace.com/f1" />

folder/file2.xsd

<xsd:import schemaLocation="file3.xsd" namespace="http://mynamespace.com/f2" />

The file3.xsd must load ./folder/file3.xsd, but try to load ./file3.xsd.

I need some way to recover the parent xsd path during imports to fix this issue.

Django integration utterly broken

The Django integration contains bad imports and undefined variable references so it can't possibly work. I think the major regression was added in 0ba2d8a but there might have been errors before.

I assume we need a "unit" test for an extremly simple Django SOAP app and then fix all the issues which crept up.

wsdl2py โ€” ValueError: Unicode strings with encoding declaration are not supported

> wsdl2py.exe -c http://services.rs.ge/WayBillService/WayBillService.asmx?WSDL
Traceback (most recent call last):
  File "D:\repo\rs.ge\venv\Scripts\wsdl2py-script.py", line 9, in <module>
    load_entry_point('soapfish==0.6dev', 'console_scripts', 'wsdl2py')()
  File "D:\repo\rs.ge\venv\lib\site-packages\soapfish\wsdl2py.py", line 112, in main
    code = generate_code_from_wsdl(xml, target, opt.use_wsa, cwd=cwd)
  File "D:\repo\rs.ge\venv\lib\site-packages\soapfish\wsdl2py.py", line 64, in generate_code_from_wsdl
    xmlelement = etree.fromstring(xml)
  File "lxml.etree.pyx", line 3103, in lxml.etree.fromstring (src\lxml\lxml.etree.c:70569)
  File "parser.pxi", line 1823, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:106368)
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

Can be fixed by adding xml.encode(encoding) at wsdl2py.py#L64 but I'm not quite sure what's actually happening there, because if you save file locally and run wsdl2py.exe -c WayBillService.wsdl it works fine.

Jinja2==2.8
MarkupSafe==0.23
argparse==1.4.0
lxml==3.4.4
pythonic-testcase==1.2.1
requests==2.9.1
six==1.10.0
soapfish==0.6dev

Schema imports with same namespace does not work

I have some imports with the same namespace. It is weird, but it is a valid structure.

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions name="IncludeTest"
    targetNamespace="http://www.example.com"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://www.example.com" schemaLocation="service.xsd"/>
        </xsd:schema>
    </wsdl:types>

The soapfish doesn't import the service.xsd because it already visited the namespace="http://www.example.com".

Drop support for Python 2.6

I had dropped support for Python 2.6 but it was still required by @FelixSchwarz so it has been restored.

When we decide to go ahead with this we should:

  • Revert fixes for Python 2.6 in 641d7e7
  • Revert fixes for Python 2.6 in 895cb54
  • Revert fixes for Python 2.6 in 6c4abd3
  • Revert fixes for Python 2.6 in f7c2dd9
  • Revert fixes for Python 2.6 in 364af26
  • Make any other changes as required.

Release soapfish on PyPI

We should release a proper package for soapfish on PyPI.

(Perhaps this should be added to the 0.6 milestone?)

Travis: test against different versions of Django (Flask as well?)

We had a couple of bugs that soapfish's Django integration stopped working due to changes in Django. I'd like to ensure that we support at least the latest django for each Python version (which means to use an older Django for Python 2.6 for example). Ideally we could also test the earliest supported method so we can be sure about the versions which should work.

If other frameworks are problematic as well, let's integrate them in the testing matrix.

Pointers:

Crash in wsdl2py related to <wsdl:part>

Running python -m soapfish.wsdl2py -c 'http://slednev.ru/example.wsdl' results in the following crash:

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/pope1ni/Sources/soapfish/soapfish/wsdl2py.py", line 121, in <module>
    main()
  File "/home/pope1ni/Sources/soapfish/soapfish/wsdl2py.py", line 112, in main
    code = generate_code_from_wsdl(xml, target, opt.use_wsa, cwd=cwd)
  File "/home/pope1ni/Sources/soapfish/soapfish/wsdl2py.py", line 84, in generate_code_from_wsdl
    use_wsa=use_wsa,
  File "/home/pope1ni/.virtualenvs/polaris/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/pope1ni/.virtualenvs/polaris/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "soapfish/templates/wsdl", line 158, in top-level template code
    def {{ operation.name }}(self, {{ inputMessage.part.element|remove_namespace }}, header=None):
  File "/home/pope1ni/.virtualenvs/polaris/lib/python2.7/site-packages/jinja2/environment.py", line 397, in getattr
    return getattr(obj, attribute)
  File "soapfish/wsdl11.py", line 53, in part
    raise ValueError('expected exactly one part', self.name, self.parts)
ValueError: ('expected exactly one part', 'GetManufacturerListMessage', [])

This issue was introduced in e04a585.

Note: This ticket is based on a problem found in flightdataservices/soapbox#23

xsd2py failing

Hello Felix,

I never had to use xsd/wsdl/soap before but I am trying to find a library which can help me implement correctly a tr-069 server (instead of just generating/parsing the XML 'by hand') like many available open source projects.

soapfish seems to be a good contender for the job but before I can even get started I have this issue.
Any help would be welcomed ! Thank you.

# xsd2py https://www.broadband-forum.org/cwmp/cwmp-1-4.xsd
Traceback (most recent call last):
  File "/usr/local/bin/xsd2py", line 9, in <module>
    load_entry_point('soapfish', 'console_scripts', 'xsd2py')()
  File "/Users/thomas/source/tr-69/soapfish/soapfish/xsd2py.py", line 171, in main
    code = generate_code_from_xsd(xmlelement, encoding='utf-8')
  File "/Users/thomas/source/tr-69/soapfish/soapfish/xsd2py.py", line 69, in generate_code_from_xsd
    standalone=True)
  File "/Users/thomas/source/tr-69/soapfish/soapfish/xsd2py.py", line 151, in schema_to_py
    return tpl.render(schema=schema, cwd=cwd, base_path=base_path)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/thomas/source/tr-69/soapfish/soapfish/templates/xsd", line 11, in top-level template code
    {{- resolve_import(i, known_files, schema.targetNamespace, cwd, base_path) }}
  File "/Users/thomas/source/tr-69/soapfish/soapfish/xsd2py.py", line 48, in resolve_import
    location = os.path.relpath(location, base_path)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 430, in relpath
    start_list = [x for x in abspath(start).split(sep) if x]
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 360, in abspath
    if not isabs(path):
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 54, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'

wsdl2py fails if 'operation' element has no 'output' child element

When running the following, an exception is raised in soapfish.wsdl12.Operation.get_OutputMessage:

mads@work:~/test$ wsdl2py -s minimal.wsdl 
Traceback (most recent call last):
  File "/home/mads/.virtualenvs/hvitserk/bin/wsdl2py", line 9, in <module>
    load_entry_point('soapfish==0.6.dev0', 'console_scripts', 'wsdl2py')()
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/soapfish/wsdl2py.py", line 112, in main
    code = generate_code_from_wsdl(xml, target, opt.use_wsa, cwd=cwd)
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/soapfish/wsdl2py.py", line 84, in generate_code_from_wsdl
    use_wsa=use_wsa,
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/soapfish/templates/wsdl", line 41, in top-level template code
    {%- set outputMessage = operation.get_OutputMessage() -%}
  File "/home/mads/.virtualenvs/hvitserk/local/lib/python2.7/site-packages/soapfish/wsdl11.py", line 99, in get_OutputMessage
    messageName = portTypeOperation.output.message
AttributeError: 'NoneType' object has no attribute 'message'

minimal.wsdl

support unittest.expectedFailure in plain nosetests

Using expectedFailure is much better than raising SkipTest because the latter will prevent the code from being executed which will lead to bit-rot. However nosetests (v1) doesn't support that so maybe I should add some support in PythonicTestCase (e.g. custom decorator).

The decorator should

  • translate a failure to SkipTest if the test runner does not support expected failures.
  • emit a message in case an "expectedFailure" test passes so the dev notices and can remove the decorator.

xsd:include support

@FelixSchwarz I was looking for xsd:include support in soapbox and you said soapfish implemented it. I didn't found anything about it in your code.

Can you help me with it?

Do not import base namespaces

Some schemas import XSD namespaces, like http://schemas.xmlsoap.org/soap/envelope/ and http://schemas.xmlsoap.org/soap/encoding/.

What is the right way to avoid import these URLs? Per domain? Any URL in namespaces module? Only these two hard-coded?

<xs:import
    namespace="http://schemas.xmlsoap.org/soap/envelope/"
    schemaLocation="http://schemas.xmlsoap.org/soap/envelope/" />
<xs:import
    namespace="http://schemas.xmlsoap.org/soap/encoding/"
    schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />

As a side note, xsd2py generate broken code with them.

Evaluate generated location

The generated file has some template URLs:

location='%(scheme)s://%(host)s/myservice',

The SOAP dispatcher must render this location.

screen/integrate changes from Martin Mrose

There is a soapbox fork by Martin Mrose which contains several interesting changes. We should screen the repository and integrate whatever commits look sensible.

Licensing note: The code was forked after the OSL relicensing but the author agreed in private email to license all changes.

I allow you to use my changes under BSD.

wsdl2py jinja2 template not found

Hi,

the command: wsdl2py --client mysoap.wsdl return this error:

Traceback (most recent call last):
  File "/Users/user/.virtualenvs/soapfish/bin/wsdl2py", line 11, in <module>
    load_entry_point('soapfish==0.6.0.dev0', 'console_scripts', 'wsdl2py')()
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/soapfish/wsdl2py.py", line 144, in main
    code = generate_code_from_wsdl(xml, opt.target, opt.use_wsa, cwd=cwd)
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/soapfish/wsdl2py.py", line 101, in generate_code_from_wsdl
    schemas = ''.join(schema_to_py(schema, xsd_namespaces, **kw) for schema in schemas)
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/soapfish/wsdl2py.py", line 101, in <genexpr>
    schemas = ''.join(schema_to_py(schema, xsd_namespaces, **kw) for schema in schemas)
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/soapfish/xsd2py.py", line 166, in schema_to_py
    tpl = env.get_template('xsd')
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/Users/user/.virtualenvs/soapfish/lib/python3.4/site-packages/jinja2/loaders.py", line 235, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: xsd

Any idea?

Thanx :)

wsdl2py with imported xsd fails

I am using wsdl2py to generate the wsdl classes from a wsdl that imports three separate .xsd files.

The generated file doesn't parse:

in python2.7:

    class AccNumEx(__name__ + '.BusinessRuleEx'):
TypeError: Error when calling the metaclass bases
    str() takes at most 1 argument (3 given)

in python3.4:

   class AccTypeEx(__name__ + '.BusinessRuleEx'):
TypeError: str() argument 2 must be str, not tuple

As an example, the full generated class looks like this, but it seems to have done this for all the .xsd files.

class AccNumEx(__name__ + '.BusinessRuleEx'):
    INHERITANCE = xsd.Inheritance.EXTENSION

the __name__ + '.class' doesn't seem to be valid python in either 2/3. I assume this is an attempt to make some kind of namespace separation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.