# Path: src/foolscap/tokens.py
# class BananaError(Exception):
#     """This exception is raised in response to a fundamental protocol
#     violation. The connection should be dropped immediately.
# 
#     .where is an optional string that describes the node of the object graph
#     where the failure was noticed.
#     """
#     where = None
# 
#     def __str__(self):
#         if self.where:
#             return "BananaError(in %s): %s" % (self.where, self.args)
#         else:
#             return "BananaError: %s" % (self.args,)
# 
# class Violation(Exception):
#     """This exception is raised in response to a schema violation. It
#     indicates that the incoming token stream has violated a constraint
#     imposed by the recipient. The current Unslicer is abandoned and the
#     error is propagated upwards to the enclosing Unslicer parent by
#     providing an BananaFailure object to the parent's .receiveChild method.
#     All remaining tokens for the current Unslicer are to be dropped.
#     """
# 
#     """.where: this string describes which node of the object graph was
#     being handled when the exception took place."""
#     where = ""
# 
#     def setLocation(self, where):
#         self.where = where
#     def getLocation(self):
#         return self.where
#     def prependLocation(self, prefix):
#         if self.where:
#             self.where = prefix + " " + self.where
#         else:
#             self.where = prefix
#     def appendLocation(self, suffix):
#         if self.where:
#             self.where = self.where + " " + suffix
#         else:
#             self.where = suffix
# 
#     def __str__(self):
#         if self.where:
#             return "Violation (%s): %s" % (self.where, self.args)
#         else:
#             return "Violation: %s" % (self.args,)


import six
from twisted.python import failure, reflect, log as twlog
from twisted.internet import defer
from foolscap import copyable, slicer, tokens
from foolscap.copyable import AttributeDictConstraint
from foolscap.constraint import ByteStringConstraint
from foolscap.slicers.list import ListConstraint
from .tokens import BananaError, Violation
from foolscap.util import AsyncAND
from foolscap.logging import log
        AttributeDictConstraint.__init__(self, *attrs)

    def checkObject(self, obj, inbound):
        if not isinstance(obj, self.klass):
            raise Violation("is not an instance of %s" % self.klass)


class PendingRequest(object):
    # this object is a local representation of a message we have sent to
    # someone else, that will be executed on their end.
    active = True

    def __init__(self, reqID, rref, interface_name, method_name):
        self.reqID = reqID
        self.rref = rref # keep it alive
        self.broker = None # if set, the broker knows about us
        self.deferred = defer.Deferred()
        self.constraint = None # this constrains the results
        self.failure = None
        self.interface_name = interface_name # for error messages
        self.method_name = method_name # same

    def setConstraint(self, constraint):
        self.constraint = constraint

    def getMethodNameInfo(self):
        return (self.interface_name, self.method_name)

    def complete(self, res):
        if self.broker:

# Path: src/foolscap/tokens.py
# class BananaError(Exception):
#     """This exception is raised in response to a fundamental protocol
#     violation. The connection should be dropped immediately.
# 
#     .where is an optional string that describes the node of the object graph
#     where the failure was noticed.
#     """
#     where = None
# 
#     def __str__(self):
#         if self.where:
#             return "BananaError(in %s): %s" % (self.where, self.args)
#         else:
#             return "BananaError: %s" % (self.args,)
# 
# class Violation(Exception):
#     """This exception is raised in response to a schema violation. It
#     indicates that the incoming token stream has violated a constraint
#     imposed by the recipient. The current Unslicer is abandoned and the
#     error is propagated upwards to the enclosing Unslicer parent by
#     providing an BananaFailure object to the parent's .receiveChild method.
#     All remaining tokens for the current Unslicer are to be dropped.
#     """
# 
#     """.where: this string describes which node of the object graph was
#     being handled when the exception took place."""
#     where = ""
# 
#     def setLocation(self, where):
#         self.where = where
#     def getLocation(self):
#         return self.where
#     def prependLocation(self, prefix):
#         if self.where:
#             self.where = prefix + " " + self.where
#         else:
#             self.where = prefix
#     def appendLocation(self, suffix):
#         if self.where:
#             self.where = self.where + " " + suffix
#         else:
#             self.where = suffix
# 
#     def __str__(self):
#         if self.where:
#             return "Violation (%s): %s" % (self.where, self.args)
#         else:
#             return "Violation: %s" % (self.args,)


# Path: src/foolscap/call.py
import six
from twisted.python import failure, reflect, log as twlog
from twisted.internet import defer
from foolscap import copyable, slicer, tokens
from foolscap.copyable import AttributeDictConstraint
from foolscap.constraint import ByteStringConstraint
from foolscap.slicers.list import ListConstraint
from .tokens import BananaError, Violation
from foolscap.util import AsyncAND
from foolscap.logging import log

        AttributeDictConstraint.__init__(self, *attrs)

    def checkObject(self, obj, inbound):
        if not isinstance(obj, self.klass):
            raise Violation("is not an instance of %s" % self.klass)


class PendingRequest(object):
    # this object is a local representation of a message we have sent to
    # someone else, that will be executed on their end.
    active = True

    def __init__(self, reqID, rref, interface_name, method_name):
        self.reqID = reqID
        self.rref = rref # keep it alive
        self.broker = None # if set, the broker knows about us
        self.deferred = defer.Deferred()
        self.constraint = None # this constrains the results
        self.failure = None
        self.interface_name = interface_name # for error messages
        self.method_name = method_name # same

    def setConstraint(self, constraint):
        self.constraint = constraint

    def getMethodNameInfo(self):
        return (self.interface_name, self.method_name)

    def complete(self, res):
        if self.broker:

            self.broker.removeRequest(self)