Provider

exception supercell.provider.NoProviderFound

Raised if no matching provider for the client’s Accept header was found.

class supercell.provider.ProviderBase

Base class for content type providers.

Creating a new provider is just as simple as creating new consumers:

class MyProvider(s.ProviderBase):

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

    def provide(self, model, handler):
        self.set_header('Content-Type', 'application/xml')
        handler.write(model.to_xml())
static map_provider(accept_header, handler, allow_default=False)

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:

NoProviderFound

provide(model, handler)

This method should return the correct representation as a simple string (i.e. byte buffer) that will be used as return value.

Parameters:model (supercell.schematics.Model) – the model to convert to a certain content type
class supercell.provider.JsonProvider

Default application/json provider.

provide(model, handler)

Simply return the json via json.dumps.

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.