# -*- coding: utf-8 -*-
################################################################################
# Note: Generated by soapbox.wsdl2py at {{ generation_dt }}
#       Try to avoid editing it if you might need to regenerate it.
################################################################################
{# [blank line] #}
{# [blank line] #}
from soapbox import soap, xsd
from soapbox.xsd import UNBOUNDED
{# [blank line] #}
{# [blank line] #}
################################################################################
# Schemas

{% if schema %}{{ schema }}{% endif -%}

{%- for service in definitions.services %}
{%- for port in service.ports %}

{%- set binding = get_by_name(definitions.bindings, port.binding) %}
{%- set XXX = binding.set_definition(definitions) %}
{%- set XXX = binding.feedback_Operations() %}

{%- if binding.binding.transport != SOAPTransport %}{% continue %}{% endif %}

{%- if is_server %}
################################################################################
# Operations
{# [blank line] #}
{# [blank line] #}
{%- for operation in binding.operations -%}
{%- set XXX = operation.set_definition(definitions) -%}
{%- set inputMessage = operation.get_InputMessage() -%}
{%- set outputMessage = operation.get_OutputMessage() -%}
{# [blank line] #}
def {{ operation.name }}(request, {{ inputMessage.part.element|remove_namespace }}):
    '''
    '''
    # TODO: Put your implementation here.
    return {{ outputMessage.part.element|remove_namespace }}
{# [blank line] #}
{# [blank line] #}
{%- endfor %}
{%- endif %}
################################################################################
# Methods
{# [blank line] #}
{# [blank line] #}
{% for operation in binding.operations -%}
{%- set XXX = operation.set_definition(definitions) -%}
{%- set inputMessage = operation.get_InputMessage() -%}
{%- set outputMessage = operation.get_OutputMessage() -%}
{{ operation.name }}_method = xsd.Method(
    {%- if is_server %}function={{ operation.name }},{% endif %}
    soapAction='{{ operation.operation.soapAction }}',
    {%- if inputMessage.part.element %}
    input='{{ inputMessage.part.element|remove_namespace }}',
    inputPartName='{{ inputMessage.part.name }}',
    {%- else %}
    input={{ inputMessage.part.type|remove_namespace|capitalize }},
    {%- endif %}
    {%- if inputMessage.part.element %}
    output='{{ outputMessage.part.element|remove_namespace }}',
    outputPartName='{{ outputMessage.part.name }}',
    {%- else %}
    input={{ outputMessage.part.type|remove_namespace|capitalize }},
    {%- endif %}
    operationName='{{ operation.name }}',
    {%- if operation.operation.style %}
    style='{{ operation.operation.style }}',
    {%- endif %}
)
{# [blank line] #}
{# [blank line] #}
{% endfor -%}
################################################################################
# SOAP Service
{# [blank line] #}
{# [blank line] #}
{{ port.name }}_SERVICE = soap.Service(
    name='{{ port.name }}',
    targetNamespace='{{ definitions.targetNamespace }}',
    location='{{ port.address.location|url_template }}',
    schema=Schema_{{ schema_name(definitions.types.schema.targetNamespace) }},
    version=soap.SOAPVersion.SOAP11,
    methods=[{% for o in binding.operations %}{{ o.name }}_method{% if not loop.last %}, {% endif %}{% endfor %}],
)
{# [blank line] #}
{# [blank line] #}
{%- if is_server %}
################################################################################
# Django Dispatch
{# [blank line] #}
{# [blank line] #}
# Uncomment these lines to turn on dispatching:
#from django.views.decorators.csrf import csrf_exempt
#dispatch = csrf_exempt(soap.get_django_dispatch({{ port.name }}_SERVICE))
{# [blank line] #}
# Put these lines in the urls.py file of your Django project/application:
#urlpatterns += patterns('',
#    (r'{{ service.ports.0.address.location|url_regex }}', '<module>.dispatch'),
#)
{%- else %}
################################################################################
# SOAP Service Stub
{# [blank line] #}
{# [blank line] #}
class {{ port.name }}ServiceStub(soap.Stub):
    '''
    '''
    SERVICE = {{ port.name }}_SERVICE
    SCHEME = '{{ port.address.location|url_component('scheme') }}'
    HOST = '{{ port.address.location|url_component('netloc') }}'
{% for operation in binding.operations %}
{%- set inputMessage = operation.get_InputMessage() %}
    def {{ operation.name }}(self, {{ inputMessage.part.element|remove_namespace }}):
        '''
        '''
        return self.call('{{ operation.name}}', {{ inputMessage.part.element|remove_namespace }})
{% endfor %}
{%- endif %}
{%- endfor %}{# ports #}
{%- endfor %}{# services #}
{# [blank line] #}
{# [blank line] #}
{#- vim:set et ft=django nowrap sts=4 sw=4 ts=4: -#}
################################################################################
# vim:et:ft=python:nowrap:sts=4:sw=4:ts=4
