'Wrap aCallable with its command\'s argument de-serialization
and result serialization logic.
@param aCallable: a callable with a \'command\' attribute, designed to be
called with keyword arguments.
@param command: the command class whose serialization to use.
@return: a 1-arg callable which, when invoked with an AmpBox, will
deserialize the argument list and invoke appropriate user code for the
callable\'s command, returning a Deferred which fires with the result or
fails with an error.'

def _wrapWithSerialization(self, aCallable, command):

    def doit(box):
        kw = command.parseArguments(box, self)
        def checkKnownErrors(error):
            key = error.trap(*command.allErrors)
            code = command.allErrors[key]
            desc = str(error.value)
            return Failure(RemoteAmpError(code, desc, (key in command.fatalErrors), local=error))
        def makeResponseFor(objects):
            try:
                return command.makeResponse(objects, self)
            except:
                originalFailure = Failure()
                raise BadLocalReturn(('%r    returned    %r    and    %r    could    not    serialize    it' % (aCallable, objects, command)), originalFailure)
        return maybeDeferred(aCallable, **kw).addCallback(makeResponseFor).addErrback(checkKnownErrors)
    return doit
