Consumer

exception supercell.consumer.NoConsumerFound

Raised if no matching consumer for the client’s Content-Type header was found.

class supercell.consumer.ConsumerBase

Base class for content type consumers.

In order to create a new consumer, you must create a new class that inherits from ConsumerBase and sets the ConsumerBase.CONTENT_TYPE variable:

class MyConsumer(s.ConsumerBase):

    CONTENT_TYPE = s.ContentType('application/xml')

    def consume(self, handler, model):
        return model(lxml.from_string(handler.request.body))

See also

supercell.api.consumer.JsonConsumer.consume

consume(handler, model)

This method should return the correct representation as a parsed model.

Parameters:model (schematics.models.Model) – the model to convert to a certain content type
static map_consumer(content_type, handler)

Map a given content type to the correct provider implementation.

If no provider matches, raise a NoProviderFound exception.

Parameters:
  • accept_header (str) – HTTP Accept header value
  • handler – supercell request handler
Raises:

NoConsumerFound

class supercell.consumer.JsonConsumer

Default application/json provider.

consume(handler, model)

Parse the body json via json.loads() and initialize the model.

See also

supercell.api.provider.ProviderBase.provide

Read the Docs v: latest
Versions
latest
v0.4.0
v0.3.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.