Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def checkToken(self, typebyte, size):
if self.classname is None:
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("InstanceUnslicer classname must be string")
elif self.attrname is None:
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("InstanceUnslicer keys must be STRINGs")
elif token[0] == "ABORT":
if len(token) == 2:
count = token[1]
else:
count = 0
assert count < 128
b = chr(count) + tokens.ABORT
self.injectData(b)
#self.handleAbort(count)
elif type(token) == int:
assert 0 <= token < 128
b = chr(token) + tokens.INT
self.injectData(b)
elif type(token) == str:
assert len(token) < 128
b = chr(len(token)) + tokens.STRING + token
self.injectData(b)
else:
raise NotImplementedError, "hey, this is just a quick hack"
def checkToken(self, typebyte, size):
if self.numargs is None:
# waiting for positional-arg count
if typebyte != tokens.INT:
raise BananaError("posarg count must be an INT")
return
if len(self.args) < self.numargs:
# waiting for a positional arg
if self.argConstraint:
self.argConstraint.checkToken(typebyte, size)
return
if self.argname is None:
# waiting for the name of a keyword arg
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("kwarg name must be a STRING")
# TODO: limit to longest argument name of the method?
return
# waiting for the value of a kwarg
if self.argConstraint:
self.argConstraint.checkToken(typebyte, size)
SturdyRef = referenceable.SturdyRef
from foolscap import copyable
Copyable = copyable.Copyable
RemoteCopy = copyable.RemoteCopy
registerRemoteCopy = _wrap_function(copyable.registerRemoteCopy,
"registerRemoteCopy")
registerCopier = _wrap_function(copyable.registerCopier,
"registerCopier")
registerRemoteCopyFactory = _wrap_function(copyable.registerRemoteCopyFactory,
"registerRemoteCopyFactory")
import foolscap.ipb
DeadReferenceError = _wrap_class(foolscap.ipb.DeadReferenceError, "DeadReferenceError")
import foolscap.tokens
BananaError = _wrap_class(foolscap.tokens.BananaError, "BananaError")
import foolscap.schema
schema = foolscap.schema
import foolscap.storage
serialize = _wrap_function(foolscap.storage.serialize, "serialize")
unserialize = _wrap_function(foolscap.storage.unserialize, "unserialize")
def checkToken(self, typebyte, size):
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("ClassUnslicer only accepts strings")
def checkToken(self, typebyte, size):
if self.state == 0:
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("MethodUnslicer methodname must be a string")
elif self.state == 1:
if typebyte != tokens.OPEN:
raise BananaError("MethodUnslicer instance must be OPEN")
elif self.state == 2:
if typebyte != tokens.OPEN:
raise BananaError("MethodUnslicer class must be an OPEN")
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 list(copyable.CopyableRegistry.keys())]
)
if size > maxlen:
why = "copyable-classname token is too long, %d>%d" % \
(size, maxlen)
raise Violation(why)
elif typebyte == tokens.VOCAB:
# checking and abandonUnslicer made that unfeasible.
#if self.debug:
# print "receiveToken(%s)" % (token,)
if type(token) == type(()):
if token[0] == "OPEN":
count = token[1]
assert count < 128
b = ( chr(count) + tokens.OPEN )
self.injectData(b)
#self.handleOpen(count, opentype)
elif token[0] == "CLOSE":
count = token[1]
assert count < 128
b = chr(count) + tokens.CLOSE
self.injectData(b)
#self.handleClose(count)
elif token[0] == "ABORT":
if len(token) == 2:
count = token[1]
else:
count = 0
assert count < 128
b = chr(count) + tokens.ABORT
self.injectData(b)
#self.handleAbort(count)
elif type(token) == int:
assert 0 <= token < 128
b = chr(token) + tokens.INT
self.injectData(b)
elif type(token) == str:
def openerCheckToken(self, typebyte, size, opentype):
if typebyte == tokens.STRING:
if size > self.maxIndexLength:
why = "STRING token is too long, %d>%d" % \
(size, self.maxIndexLength)
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))