Provider
-
exception supercell.api.provider.NoProviderFound[source]
Raised if no matching provider for the client’s Accept header was
found.
-
class supercell.api.provider.ProviderBase[source]
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())
-
CONTENT_TYPE = None
The target content type for the provider.
Type : | supercell.api.ContentType |
-
static map_provider(accept_header, handler, allow_default=False)[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 : | NoProviderFound
|
-
provide(model, handler)[source]
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.api.provider.JsonProvider[source]
Default application/json provider.
-
provide(model, handler)[source]
Simply return the json via json.dumps.