1# -*- test-case-name: foolscap.test.test_banana -*- 2 3from foolscap.tokens import Violation, BananaError 4from foolscap.slicer import BaseSlicer, LeafUnslicer 5from foolscap.constraint import OpenerConstraint 6 7 8class NoneSlicer(BaseSlicer): 9 opentype = ('none',) 10 trackReferences = False 11 slices = type(None) 12 def sliceBody(self, streamable, banana): 13 # hmm, we need an empty generator. I think a sequence is the only way 14 # to accomplish this, other than 'if 0: yield' or something silly 15 return [] 16 17class NoneUnslicer(LeafUnslicer): 18 opentype = ('none',) 19 20 def checkToken(self, typebyte, size): 21 raise BananaError("NoneUnslicer does not accept any tokens") 22 def receiveClose(self): 23 return None, None 24 25 26class Nothing(OpenerConstraint): 27 """Accept only 'None'.""" 28 strictTaster = True 29 opentypes = [("none",)] 30 name = "Nothing" 31 32 def checkObject(self, obj, inbound): 33 if obj is not None: 34 raise Violation("'%s' is not None" % (obj,)) 35