Exemple #1
0
 def test_startUsesConfiguredLogObserver(self):
     """
     When the C{logger} key is specified in the configuration dictionary
     (i.e., when C{--logger} is passed to twistd), the initial log observer
     will be the log observer returned from the callable which the value
     refers to in FQPN form.
     """
     application = Componentized()
     self._checkObserver(self._setupConfiguredLogger(application))
 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
Exemple #3
0
 def test_configuredLogObserverBeatsLogfile(self):
     """
     C{--logger} takes precedence over a C{--logfile} command line
     argument.
     """
     application = Componentized()
     path = self.mktemp()
     self._checkObserver(self._setupConfiguredLogger(application,
                                                     {"logfile": "path"}))
     self.assertFalse(os.path.exists(path))
Exemple #4
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, [])
Exemple #5
0
 def test_start(self):
     """
     L{app.AppLogger.start} calls L{log.addObserver}, and then writes some
     messages about twistd and the reactor.
     """
     logger = app.AppLogger({})
     observer = []
     logger._getLogObserver = lambda: observer.append
     logger.start(Componentized())
     self._checkObserver(observer)
Exemple #6
0
 def test_configuredLogObserverBeatsSyslog(self):
     """
     C{--logger} takes precedence over a C{--syslog} command line
     argument.
     """
     logs = _setupSyslog(self)
     application = Componentized()
     self._checkObserver(self._setupConfiguredLogger(application,
                                                     {"syslog": True},
                                                     UnixAppLogger))
     self.assertEqual(logs, [])
Exemple #7
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)
Exemple #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
Exemple #9
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
Exemple #10
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)