'Encode a response to a L{WebResponse}, signing it first if appropriate.
@raises EncodingError: When I can\'t figure out how to encode this
message.
@raises AlreadySigned: When this response is already signed.
@returntype: L{WebResponse}'

def encode(self, response):

    if ((not isinstance(response, Exception)) and response.needsSigning()):
        if (not self.signatory):
            raise ValueError(('Must    have    a    store    to    sign    this    request:    %s' % (response,)), response)
        if response.fields.hasKey(OPENID_NS, 'sig'):
            raise AlreadySigned(response)
        response = self.signatory.sign(response)
    return super(SigningEncoder, self).encode(response)
