Beispiel #1
0
 def setupRequest(r):
     r.args['_nevow_carryover_'] = ['abc']
     from nevow import rend
     c = components.Componentized()
     c.setComponent(inevow.IHand, returnResult)
     c.setComponent(inevow.IStatusMessage, status)
     rend._CARRYOVER['abc'] = c
     return r
Beispiel #2
0
 def test_setComponent(self):
     """
     C{Componentized.setComponent} stores the given component using the
     given interface as the key.
     """
     componentized = components.Componentized()
     obj = object()
     componentized.setComponent(ITest, obj)
     self.assertIs(componentized.getComponent(ITest), obj)
Beispiel #3
0
 def test_unsetComponent(self):
     """
     C{Componentized.setComponent} removes the cached component for the
     given interface.
     """
     componentized = components.Componentized()
     obj = object()
     componentized.setComponent(ITest, obj)
     componentized.unsetComponent(ITest)
     self.assertIsNone(componentized.getComponent(ITest))
Beispiel #4
0
 def test_addAdapter(self):
     """
     C{Componentized.setAdapter} adapts the instance by wrapping it with
     given adapter class, then stores it using C{addComponent}.
     """
     componentized = components.Componentized()
     componentized.addAdapter(Adept, ignoreClass=True)
     component = componentized.getComponent(IAdept)
     self.assertEqual(component.original, componentized)
     self.assertIsInstance(component, Adept)
Beispiel #5
0
 def test_setAdapter(self):
     """
     C{Componentized.setAdapter} sets a component for an interface by
     wrapping the instance with the given adapter class.
     """
     componentized = components.Componentized()
     componentized.setAdapter(IAdept, Adept)
     component = componentized.getComponent(IAdept)
     self.assertEqual(component.original, componentized)
     self.assertIsInstance(component, Adept)
 def test_getComponentDefaults(self):
     """
     Test that a default value specified to Componentized.getComponent if
     there is no component for the requested interface.
     """
     componentized = components.Componentized()
     default = object()
     self.assertIs(componentized.getComponent(ITest, default), default)
     self.assertIs(componentized.getComponent(ITest, default=default), default)
     self.assertIs(componentized.getComponent(ITest), None)
Beispiel #7
0
    def _getAvatar(self, avatarId):
        comp = components.Componentized()
        user = self.userFactory(comp, avatarId)
        sess = self.sessionFactory(comp)

        sess.transportFactory = self.transportFactory
        sess.chainedProtocolFactory = lambda: self.chainedProtocolFactory(avatarId)

        comp.setComponent(iconch.IConchUser, user)
        comp.setComponent(iconch.ISession, sess)

        return user
Beispiel #8
0
 def _getAvatar(self, avatarId):
     comp = components.Componentized()
     user = self.userFactory(comp, avatarId)
     sess = self.sessionFactory(comp)
     sess.transportFactory = self.transportFactory
     sess.chainedProtocolFactory = self.chainedProtocolFactory
     comp.setComponent(interfaces.IConchUser, user)
     comp.setComponent(interfaces.ISession, sess)
     # XXX this is sensitive information -- we need to make sure that it's
     # not exposed to anyone but admins
     self.userComponents[avatarId] = comp
     return user
Beispiel #9
0
def Application(name, uid=None, gid=None):
    """Return a compound class.

    Return an object supporting the C{IService}, C{IServiceCollection},
    C{IProcess} and C{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    for comp in (Bots(), sob.Persistent(ret, name), service.Process(uid, gid)):
        ret.addComponent(comp, ignoreClass=1)
    service.IService(ret).setName(name)
    return ret
Beispiel #10
0
def Application(name, uid=None, gid=None):
    """
    Return a compound class.
    Return an object supporting the L{IService}, L{IPausable}, L{IReloadable}, L{IServiceCollection},
    L{IProcess} and L{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    availableComponents = [TopLevelService(), Process(uid, gid),
                           sob.Persistent(ret, name)]

    for comp in availableComponents:
        ret.addComponent(comp, ignoreClass=1)
    IService(ret).setName(name)
    return ret  
Beispiel #11
0
 def redirectAfterPost(aspects):
     redirectAfterPost = request.getComponent(iformless.IRedirectAfterPost, None)
     if redirectAfterPost is None:
         ref = request.getHeader('referer') or ''
     else:
         ## Use the redirectAfterPost url
         ref = str(redirectAfterPost)
     from nevow import url
     refpath = url.URL.fromString(ref)
     magicCookie = str(now())
     refpath = refpath.replace('_nevow_carryover_', magicCookie)
     _CARRYOVER[magicCookie] = C = tpc.Componentized()
     for k, v in aspects.iteritems():
         C.setComponent(k, v)
     request.redirect(str(refpath))
     from nevow import static
     return static.Data('You posted a form to %s' % bindingName, 'text/plain'), ()
Beispiel #12
0
        def redirectAfterPost(aspects):
            hand = aspects.get(inevow.IHand)
            refpath = None
            if hand is not None:
                if isinstance(hand, Page):
                    refpath = url.here
                    if 'freeform_hand' not in inevow.IRequest(ctx).prepath:
                        refpath = refpath.child('freeform_hand')
                if isinstance(hand, (url.URL, url.URLOverlay)):
                    refpath, hand = hand, None

            if refpath is None:
                redirectAfterPost = request.getComponent(
                    iformless.IRedirectAfterPost, None)
                if redirectAfterPost is None:
                    ref = request.getHeader('referer')
                    if ref:
                        refpath = url.URL.fromString(ref)
                    else:
                        refpath = url.here
                else:
                    warnings.warn(
                        "[0.5] IRedirectAfterPost is deprecated. Return a URL instance from your autocallable instead.",
                        DeprecationWarning, 2)
                    ## Use the redirectAfterPost url
                    ref = str(redirectAfterPost)
                    refpath = url.URL.fromString(ref)

            if hand is not None or aspects.get(
                    iformless.IFormErrors) is not None:
                magicCookie = '%s%s%s' % (now(), request.getClientIP(),
                                          random.random())
                refpath = refpath.replace('_nevow_carryover_', magicCookie)
                _CARRYOVER[magicCookie] = C = tpc.Componentized()
                for k, v in aspects.items():
                    C.setComponent(k, v)

            destination = flat.flatten(refpath, ctx)
            request.redirect(destination)
            from nevow import static
            return static.Data('You posted a form to %s' % bindingName,
                               'text/plain'), ()
Beispiel #13
0
def Application(name, uid=None, gid=None):
    """
    Return a compound class.

    Return an object supporting the L{IService}, L{IServiceCollection},
    L{IProcess} and L{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    availableComponents = [MultiService(), Process(uid, gid)]

    if not _PY3:
        # FIXME: https://twistedmatrix.com/trac/ticket/7827
        # twisted.persisted is not yet ported to Python 3, so import it here.
        from twisted.persisted import sob
        availableComponents.append(sob.Persistent(ret, name))

    for comp in availableComponents:
        ret.addComponent(comp, ignoreClass=1)
    IService(ret).setName(name)
    return ret