Previous topic

Protocols

Next topic

Http

This Page

Protocol Base Class

class spyne.protocol._base.ProtocolBase(app=None, validator=None, mime_type=None, ignore_uncap=False, ignore_wrappers=False)[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.
  • ignore_uncap – Silently ignore cases when the protocol is not capable of serializing return values instead of raising a TypeError.
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

date_from_string_iso(cls, string)[source]

This is used by protocols like SOAP who need ISO8601-formatted dates no matter what.

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, message)[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.

file_to_string(cls, value, suggested_encoding=None)[source]
Parameters:
  • cls – A spyne.model.File subclass
  • value – Either a sequence of byte chunks or a spyne.model.File.Value instance.
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, message)[source]

Serializes ctx.out_object.

If ctx.out_stream is not None, ctx.out_document and ctx.out_string are skipped and the response is written directly to ctx.out_stream.

Parameters:
  • ctxMethodContext instance.
  • message – One of (ProtocolBase.REQUEST, ProtocolBase.RESPONSE).
set_validator(validator)[source]

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

time_from_string(cls, string)[source]

Expects ISO formatted times.

time_to_string(cls, value)[source]

Returns ISO formatted dates.

type = set([])

Set that contains keywords about a protocol.

validate_document(payload)[source]

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