Table Of Contents

Previous topic

Client Transports

Next topic

Auxiliary Processors

This Page

Server Transports

Server Base Class

class spyne.server._base.ServerBase(app)[source]

This class is the abstract base class for all server transport implementations. Unlike the client transports, this class does not define a pure-virtual method that needs to be implemented by all base classes.

If there needs to be a call to start the main loop, it’s called serve_forever() by convention.

generate_contexts(ctx, in_string_charset=None)[source]

Calls create_in_document and decompose_incoming_envelope to get method_request string in order to generate contexts.

get_in_object(ctx)[source]

Uses the ctx.in_string to set ctx.in_body_doc, which in turn is used to set ctx.in_object.

get_out_object(ctx)[source]

Calls the matched user function by passing it the ctx.in_object to set ctx.out_object.

get_out_string(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_pull(ctx)[source]

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

serve_forever()[source]

Implement your event loop here, if needed.

transport = None

The transport type, which is a URI string to its definition by convention.

HTTP (WSGI)

A server that uses http as transport via wsgi. It doesn’t contain any server logic.

class spyne.server.wsgi.WsgiApplication(app, chunked=True, max_content_length=2097152, block_length=8192)[source]

A PEP-3333 compliant callable class.

If you want to have a hard-coded URL in the wsdl document, this is how to do it:

wsgi_app = WsgiApplication(...)
wsgi_app.doc.wsdl11.build_interface_document("http://example.com")

This is not strictly necessary – if you don’t do this, Spyne will get the URL from the first request, build the wsdl on-the-fly and cache it as a string in memory for later requests. However, if you want to make sure you only have this url on the WSDL, this is how to do it. Note that if your client takes the information in the Wsdl document seriously (not all do), all requests will go to the designated url above even when you get the Wsdl from another location, which can make testing a bit difficult. Use in moderation.

Supported events:
  • wsdl

    Called right before the wsdl data is returned to the client.

  • wsdl_exception

    Called right after an exception is thrown during wsdl generation. The exception object is stored in ctx.transport.wsdl_error attribute.

  • wsgi_call

    Called first when the incoming http request is identified as a rpc request.

  • wsgi_return

    Called right before the output stream is returned to the WSGI handler.

  • wsgi_exception

    Called right before returning the exception to the client.

  • wsgi_close

    Called after the whole data has been returned to the client. It’s called both from success and error cases.

decompose_incoming_envelope(prot, ctx, message)[source]

This function is only called by the HttpRpc protocol to have the wsgi environment parsed into ctx.in_body_doc and ctx.in_header_doc.

generate_contexts(ctx, in_string_charset=None)

Calls create_in_document and decompose_incoming_envelope to get method_request string in order to generate contexts.

generate_map_adapter(ctx)[source]

This function runs on first request because it needs the ‘SERVER_NAME’ from the wsgi request environment.

get_in_object(ctx)

Uses the ctx.in_string to set ctx.in_body_doc, which in turn is used to set ctx.in_object.

get_out_object(ctx)

Calls the matched user function by passing it the ctx.in_object to set ctx.out_object.

get_out_string(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_pull(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_push(*args, **kwargs)
handle_error(p_ctx, others, error, start_response)[source]

Serialize errors to an iterable of strings and return them.

Parameters:
  • p_ctx – Primary (non-aux) context.
  • others – List if auxiliary contexts (can be empty).
  • error – One of ctx.{in,out}_error.
  • start_response – See the WSGI spec for more info.
handle_rpc(req_env, start_response)[source]
handle_wsdl_request(req_env, start_response, url)[source]
has_patterns None
is_wsdl_request(req_env)[source]
match_pattern(ctx, method='', path='', host='')

Sets ctx.method_request_string if there’s a match. It’s O(n) which means you should keep your number of patterns as low as possible.

Parameters:
  • ctx – A MethodContext instance
  • method – The verb in the HTTP Request (GET, POST, etc.)
  • host – The contents of the Host: header
  • path – Path but not the arguments. (i.e. stuff before ‘?’, if it’s there)
run_push(ret, p_ctx, others, gen)
serve_forever()

Implement your event loop here, if needed.

transport = 'http://schemas.xmlsoap.org/soap/http'
class spyne.server.wsgi.WsgiMethodContext(transport, req_env, content_type)[source]

The WSGI-Specific method context. WSGI-Specific information is stored in the transport attribute using the WsgiTransportContext class.

close()
copy()
default_transport_context

alias of HttpTransportContext

descriptor None
frozen = False
get_descriptor()
get_out_protocol()
method_name None

The public name of the method the method_request_string was matched to.

out_protocol None
service_class None
set_descriptor(descriptor)
set_out_protocol(what)
transport = None

Holds the WSGI-specific information

class spyne.server.wsgi.WsgiTransportContext(parent, transport, req_env, content_type)[source]

The class that is used in the transport attribute of the WsgiMethodContext class.

content_type None
get_mime_type()
mime_type None
req_env = None

WSGI Request environment

req_method = None

HTTP Request verb, as a convenience to users.

respond(resp_code, **kwargs)
set_mime_type(what)

Http (Twisted)

Http (Django)

Http (Pyramid)

ZeroMQ

The spyne.server.zeromq module contains a server implementation that uses ZeroMQ (zmq.REP) as transport.

class spyne.server.zeromq.ZeroMQServer(app, app_url, wsdl_url=None, ctx=None, socket=None)[source]

The ZeroMQ server transport.

generate_contexts(ctx, in_string_charset=None)

Calls create_in_document and decompose_incoming_envelope to get method_request string in order to generate contexts.

get_in_object(ctx)

Uses the ctx.in_string to set ctx.in_body_doc, which in turn is used to set ctx.in_object.

get_out_object(ctx)

Calls the matched user function by passing it the ctx.in_object to set ctx.out_object.

get_out_string(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_pull(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_push(*args, **kwargs)
run_push(ret, p_ctx, others, gen)
serve_forever()[source]

Runs the ZeroMQ server.

transport = 'http://rfc.zeromq.org/'
class spyne.server.zeromq.ZeroMQThreadPoolServer(app, app_url, pool_size, wsdl_url=None, ctx=None, socket=None)[source]

Create a ZeroMQ server transport with several background workers, allowing asynchronous calls.

More details on the pattern http://zguide.zeromq.org/page:all#Shared-Queue-DEALER-and-ROUTER-sockets

create_worker(i, be_url)[source]
serve_forever()[source]

Runs the ZeroMQ server.

class spyne.server.zeromq.ZmqMethodContext(app)[source]
close()
copy()
descriptor None
frozen = False
get_descriptor()
get_out_protocol()
method_name None

The public name of the method the method_request_string was matched to.

out_protocol None
service_class None
set_descriptor(descriptor)
set_out_protocol(what)

NullServer

The spyne.server.null module contains the NullServer class and its helper objects.

The name comes from the “null modem connection”. Look it up.

class spyne.server.null.NullServer(app, ostr=False, locale='C')[source]

A server that doesn’t support any transport at all – it’s implemented to test services without having to run a server.

It implicitly uses the ‘sync’ auxiliary processing mode.

Note that:
  1. **kwargs overwrite *args.

  2. You can do:

    logging.getLogger('spyne.server.null').setLevel(logging.CRITICAL)
    

to hide context delimiters in logs.

generate_contexts(ctx, in_string_charset=None)

Calls create_in_document and decompose_incoming_envelope to get method_request string in order to generate contexts.

get_in_object(ctx)

Uses the ctx.in_string to set ctx.in_body_doc, which in turn is used to set ctx.in_object.

get_out_object(ctx)

Calls the matched user function by passing it the ctx.in_object to set ctx.out_object.

get_out_string(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_pull(ctx)

Uses the ctx.out_object to set ctx.out_document and later ctx.out_string.

get_out_string_push(*args, **kwargs)
get_wsdl()[source]
run_push(ret, p_ctx, others, gen)
serve_forever()

Implement your event loop here, if needed.

set_options(**kwargs)[source]
transport = 'noconn://null.spyne'