'Utility function for disconnecting a selectable.
Supports half-close notification, isRead should be boolean indicating
whether error resulted from doRead().'

def _disconnectSelectable(self, selectable, why, isRead, faildict={error.ConnectionDone: failure.Failure(error.ConnectionDone()), error.ConnectionLost: failure.Failure(error.ConnectionLost())}):

    self.removeReader(selectable)
    f = faildict.get(why.__class__)
    if f:
        if (isRead and (why.__class__ == error.ConnectionDone) and IHalfCloseableDescriptor.providedBy(selectable)):
            selectable.readConnectionLost(f)
        else:
            self.removeWriter(selectable)
            selectable.connectionLost(f)
    else:
        self.removeWriter(selectable)
        selectable.connectionLost(failure.Failure(why))
