Exemplo n.º 1
0
    def addContentTypes(self, app, template, content_types, default=None):
        """
        Associate a WSGI app and a template with one or more content-types
        """
        try:
            mediator = self.templates[template].app
        except KeyError:
            from mediator import Mediator
            # create a Mediator inside a normalised environment
            mediator = Mediator(check_response=False)
            self.templates[template] = EnvironNormalise(mediator)

        # Add the specified content types, wrapping them in middleware
        # that adds the content-type header.
        for content_type in content_types:
            wrapp = self.contentWrapper(app, content_type + ';charset=utf-8')
            mediator.add(content_type, wrapp)

        # Add the default content type
        if default:
            wrapp = self.contentWrapper(app, default + ';charset=utf-8')
            mediator.add('*/*', wrapp)
Exemplo n.º 2
0
    def addContentTypes(self, app, template, content_types, default=None):
        """
        Associate a WSGI app and a template with one or more content-types
        """
        try:
            mediator = self.templates[template].app
        except KeyError:
            from mediator import Mediator
            # create a Mediator inside a normalised environment
            mediator = Mediator(check_response=False)
            self.templates[template] = EnvironNormalise(mediator)

        # Add the specified content types, wrapping them in middleware
        # that adds the content-type header.
        for content_type in content_types:
            wrapp = self.contentWrapper(app, content_type+';charset=utf-8')
            mediator.add(content_type, wrapp)

        # Add the default content type
        if default:
            wrapp = self.contentWrapper(app, default+';charset=utf-8')
            mediator.add('*/*', wrapp)
Exemplo n.º 3
0
"The Mediator Use Case Example"
from component import Component
from mediator import Mediator

MEDIATOR = Mediator()
COMPONENT1 = Component(MEDIATOR, "Component1")
COMPONENT2 = Component(MEDIATOR, "Component2")
COMPONENT3 = Component(MEDIATOR, "Component3")
MEDIATOR.add(COMPONENT1)
MEDIATOR.add(COMPONENT2)
MEDIATOR.add(COMPONENT3)

COMPONENT1.notify("data A")
COMPONENT2.notify("data B")
COMPONENT3.notify("data C")