def open(self, opentype): # used for lower-level objects, delegated up from childunslicer.open assert len(self.protocol.receiveStack) > 1 if opentype[0] == 'copyable': if len(opentype) > 1: classname = opentype[1] try: factory = copyable.CopyableRegistry[classname] except KeyError: raise Violation("unknown RemoteCopy class '%s'" \ % classname) child = factory() child.broker = self.broker return child else: return None # still need classname for reg in self.openRegistry: opener = reg.get(opentype) if opener is not None: child = opener() break else: raise Violation("unknown OPEN type %s" % (opentype, )) child.broker = self.broker return child
def openerCheckToken(self, typebyte, size, opentype): if typebyte == tokens.STRING: if len(opentype) == 0: if size > self.maxIndexLength: why = "first opentype STRING token is too long, %d>%d" % \ (size, self.maxIndexLength) raise Violation(why) if opentype == ("copyable", ): # TODO: this is silly, of course (should pre-compute maxlen) maxlen = reduce(max, [len(cname) \ for cname in copyable.CopyableRegistry.keys()] ) if size > maxlen: why = "copyable-classname token is too long, %d>%d" % \ (size, maxlen) raise Violation(why) elif typebyte == tokens.VOCAB: return else: # TODO: hack for testing raise Violation("index token 0x%02x not STRING or VOCAB" % \ ord(typebyte)) raise BananaError("index token 0x%02x not STRING or VOCAB" % \ ord(typebyte))
def testReject2(self): req = TestRequest(12) req.setConstraint(schema.makeConstraint(int)) self.broker.addRequest(req) u = self.newUnslicer() u.checkToken(INT, 0) u.receiveChild(12) self.failUnlessRaises(Violation, u.checkToken, STRING, 42) self.failIf(req.answers) v = Violation("icky") v.setLocation("here") u.reportViolation(BananaFailure(v)) self.failUnlessEqual(len(req.answers), 1) err = req.answers[0] self.failIf(err[0]) f = err[1] self.failUnless(f.check(Violation))
def testReject2(self): # answer a request with a result that violates the constraint req = TestRequest(12) req.setConstraint(schema.makeConstraint(int)) self.broker.addRequest(req) u = self.newUnslicer() u.checkToken(INT, 0) u.receiveChild(12) self.failUnlessRaises(Violation, u.checkToken, STRING, 42) # this does not yet errback the request self.failIf(req.answers) # it gets errbacked when banana reports the violation v = Violation("icky") v.setLocation("here") u.reportViolation(BananaFailure(v)) self.failUnlessEqual(len(req.answers), 1) err = req.answers[0] self.failIf(err[0]) f = err[1] self.failUnless(f.check(Violation))
def getRequest(self, reqID): # invoked by AnswerUnslicer and ErrorUnslicer try: return self.waitingForAnswers[reqID] except KeyError: raise Violation("non-existent reqID '%d'" % reqID)