예제 #1
0
 def test_configuredLogObserverBeatsComponent(self):
     """
     C{--logger} takes precedence over a ILogObserver component set on
     Application.
     """
     nonlogs = []
     application = Componentized()
     application.setComponent(ILogObserver, nonlogs.append)
     self._checkObserver(self._setupConfiguredLogger(application))
     self.assertEqual(nonlogs, [])
예제 #2
0
 def test_startUsesApplicationLogObserver(self):
     """
     When the L{ILogObserver} component is available on the application,
     that object will be used as the log observer instead of constructing a
     new one.
     """
     application = Componentized()
     logs = []
     application.setComponent(ILogObserver, logs.append)
     logger = app.AppLogger({})
     logger.start(application)
     self._checkObserver(logs)
예제 #3
0
 def test_startUsesApplicationLogObserver(self):
     """
     When the L{ILogObserver} component is available on the application,
     that object will be used as the log observer instead of constructing a
     new one.
     """
     application = Componentized()
     logs = []
     application.setComponent(ILogObserver, logs.append)
     logger = app.AppLogger({})
     logger.start(application)
     self._checkObserver(logs)
예제 #4
0
        def decorator(functionWithRequirements):
            # type: (Any) -> Callable
            injectionComponents = Componentized()
            lifecycle = RequestLifecycle()
            injectionComponents.setComponent(IRequestLifecycle, lifecycle)

            injectors = {}      # type: Dict[str, IDependencyInjector]

            for parameterName, required in requiredParameters.items():
                injectors[parameterName] = required.registerInjector(
                    injectionComponents, parameterName, lifecycle
                )

            for prereq in self._prerequisites:
                prereq(lifecycle)

            for v in injectors.values():
                v.finalize()

            @modified("dependency-injecting route", functionWithRequirements)
            @bindable
            @inlineCallbacks
            def router(instance, request, *args, **routeParams):
                # type: (Any, IRequest, *Any, **Any) -> Any
                injected = routeParams.copy()
                try:
                    yield lifecycle.runPrepareHooks(instance, request)
                    for (k, injector) in injectors.items():
                        injected[k] = yield injector.injectValue(
                            instance, request, routeParams
                        )
                except EarlyExit as ee:
                    result = ee.alternateReturnValue
                else:
                    result = yield _call(
                        instance, functionWithRequirements, *args,
                        **injected
                    )
                returnValue(result)

            functionWithRequirements.injectionComponents = injectionComponents
            routeDecorator(router)
            return functionWithRequirements
예제 #5
0
    def indirect(self, interface):
        """
        Create an L{IConchUser} avatar which will use L{ShellServer} to
        interact with the connection.
        """
        if interface is IConchUser:
            componentized = Componentized()

            user = _BetterTerminalUser(componentized, None)
            session = _BetterTerminalSession(componentized)
            session.transportFactory = TerminalSessionTransport
            session.chainedProtocolFactory = lambda: ServerProtocol(ShellServer, self.store)

            componentized.setComponent(IConchUser, user)
            componentized.setComponent(ISession, session)

            return user

        raise NotImplementedError(interface)
예제 #6
0
 def _getAvatar(self, avatarId):
     comp = Componentized()
     user = UrwidUser(comp, avatarId)
     comp.setComponent(IConchUser, user)
     sess = UrwidTerminalSession(comp)
     comp.setComponent(ISession, sess)
     mind = self.mind_factory(comp)
     comp.setComponent(IUrwidMind, mind)
     return user
예제 #7
0
 def _getAvatar(self, avatarId):
     comp = Componentized()
     user = UrwidUser(comp, avatarId)
     comp.setComponent(IConchUser, user)
     sess = UrwidTerminalSession(comp)
     comp.setComponent(ISession, sess)
     mind = self.mind_factory(comp)
     comp.setComponent(IUrwidMind, mind)
     return user
예제 #8
0
 def _getAvatar(self, avatarId):
     comp = Componentized()
     user = UrwidUser(comp, avatarId)
     comp.setComponent(IConchUser, user)
     sess = UrwidTerminalSession(comp)
     comp.setComponent(ISession, sess)
     self.mind = self.mind_factories[avatarId](comp)
     #instead get correct mind from dictionary using mind = self.mind_factories[avatarId](comp)
     ##add user to mind connections
     self.mind.connections[user.uuid] = {"user": user, "log": []}
     comp.setComponent(IUrwidMind, self.mind)
     return user