Previous topic

Protocols

Next topic

Http

This Page

Protocol Base Class

class spyne.protocol._base.ProtocolBase(app=None, validator=None, mime_type=None, skip_depth=0)[source]

Bases: object

This is the abstract base class for all protocol implementations. Child classes can implement only the required subset of the public methods.

An output protocol must implement serialize() and create_out_string().

An input protocol must implement create_in_document(), decompose_incoming_envelope() and deserialize().

The ProtocolBase class supports the following events:

  • before_deserialize: Called before the deserialization operation is attempted.
  • after_deserialize: Called after the deserialization operation is finished.
  • before_serialize: Called before after the serialization operation is attempted.
  • after_serialize: Called after the serialization operation is finished.

The arguments the constructor takes are as follows:

Parameters:
  • app – The application this protocol belongs to.
  • validator – The type of validation this protocol should do on incoming data.
  • mime_type – The mime_type this protocol should set for transports that support this. This is a quick way to override the mime_type by default instead of subclassing the releavant protocol implementation.
  • skip_depth – Number of wrapper classes to ignore. This is typically one of (0, 1, 2) but higher numbers may also work for your case.
create_in_document(ctx, in_string_encoding=None)[source]

Uses ctx.in_string to set ctx.in_document.

create_out_string(ctx, out_string_encoding=None)[source]

Uses ctx.out_document to set ctx.out_string

decompose_incoming_envelope(ctx, message)[source]

Sets the ctx.method_request_string, ctx.in_body_doc, ctx.in_header_doc and ctx.service properties of the ctx object, if applicable.

deserialize(ctx)[source]

Takes a MethodContext instance and a string containing ONE document instance in the ctx.in_string attribute.

Returns the corresponding native python object in the ctx.in_object attribute.

fault_to_http_response_code(fault)[source]

Special function to convert native Python exceptions to Http response codes.

generate_method_contexts(ctx)[source]

Generates MethodContext instances for every callable assigned to the given method handle.

The first element in the returned list is always the primary method context whereas the rest are all auxiliary method contexts.

get_call_handles(ctx)[source]

Method to be overriden to perform any sort of custom method mapping using any data in the method context. Returns a list of contexts. Can return multiple contexts if a method_request_string matches more than one function. (This is called the fanout mode.)

serialize(ctx)[source]

Takes a MethodContext instance and the object to be serialized in the ctx.out_object attribute.

Returns the corresponding document structure in the ctx.out_document attribute.

set_method_descriptor(ctx)[source]

DEPRECATED! Use generate_method_contexts() instead.

Method to be overriden to perform any sort of custom matching between the method_request_string and the methods.

set_validator(validator)[source]

You must override this function if you want your protocol to support validation.

validate_document(payload)[source]

Method to be overriden to perform any sort of custom input validation on the parsed input document.