def bindSession(proxy, sessionCreator): ''' Binds a session creator wrapping for the provided proxy. @param proxy: Proxy The proxy to wrap with session creator. @param sessionCreator: class The session creator class that will create the session. ''' registerProxyHandler(SessionBinder(sessionCreator), proxy)
def process(self, chain, bind:Bind, **keyargs): ''' @see: HandlerProcessor.process Binds a session creator wrapping for the provided proxy. ''' assert isinstance(bind, Bind), 'Invalid bind %s' % bind assert not hasProxyHandler(BindSessionHandler, bind.proxy), 'Proxy already has a session %s' % bind.proxy registerProxyHandler(self, bind.proxy)
def testProxyRegister(self): BProxy = createProxy(B) proxy = BProxy(ProxyWrapper(B())) registerProxyHandler(ProxyWrapper(A()), proxy.methodA) self.assertTrue(isinstance(proxy, B)) assert isinstance(proxy, B) self.assertTrue(proxy.methodA() == 'A.methodA') self.assertTrue(proxy.methodB() == 'B.methodB')
def process(self, chain, bind: Bind, **keyargs): ''' @see: HandlerProcessor.process Binds a session creator wrapping for the provided proxy. ''' assert isinstance(bind, Bind), 'Invalid bind %s' % bind assert not hasProxyHandler( BindSessionHandler, bind.proxy), 'Proxy already has a session %s' % bind.proxy registerProxyHandler(self, bind.proxy)
def userServiceUpdate(): class AutoRolesProxy(IProxyHandler): ''' Automatically assign roles to new created users.''' def __init__(self, userRbacService): self.userRbacService = userRbacService def handle(self, execution): userId = execution.invoke() self.userRbacService.addRole(userId, 'Admin') return userId userService = support.entityFor(IUserService) handler = AutoRolesProxy(support.entityFor(IUserRbacService)) handler = ProxyFilter(handler, 'insert') registerProxyHandler(handler, userService)
def process(self, chain, bind:Bind, **keyargs): ''' @see: HandlerProcessor.process Wraps the invoking and all processors after in a single transaction. ''' assert isinstance(bind, Bind), 'Invalid bind %s' % bind if not isinstance(typeFor(bind.proxy), TypeService): return proc = self._processing assert isinstance(proc, Processing), 'Invalid processing %s' % proc arg = proc.execute(FILL_ALL, register=proc.ctx.register(services=[bind.proxy])) assert isinstance(arg.register, Register), 'Invalid register %s' % arg.register if not arg.register.invokers: return assert not hasProxyHandler(ProxyTransalator, bind.proxy), 'Proxy already has a session %s' % bind.proxy invokers = {} for invoker in arg.register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert isinstance(invoker.call, TypeCall), 'Invalid call %s' % invoker.call invokers[invoker.call.name] = invoker if invokers: registerProxyHandler(ProxyTransalator(invokers), bind.proxy)