Consumer

exception supercell.api.consumer.NoConsumerFound[source]

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

class supercell.api.consumer.ConsumerBase[source]

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))
CONTENT_TYPE = None

The target content type for the consumer.

Type :supercell.api.ContentType
consume(handler, model)[source]

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)[source]

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.api.consumer.JsonConsumer[source]

Default application/json provider.

CONTENT_TYPE = ContentType(content_type='application/json', vendor=None, version=None)

The application/json ContentType.

consume(handler, model)[source]

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

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

Free document hosting provided by Read the Docs.