code: def encode(self, response):
          
          encode_as = response.whichEncoding()
          if encode_as == ENCODE_KVFORM:
              wr = self.responseFactory(body=response.encodeToKVForm())
              if isinstance(response, Exception):
                  wr.code = HTTP_ERROR
          elif encode_as == ENCODE_URL:
              location = response.encodeToURL()
              wr = self.responseFactory(code=HTTP_REDIRECT,
                                        headers={'location': location})
          elif encode_as == ENCODE_HTML_FORM:
              wr = self.responseFactory(code=HTTP_OK,
                                        body=response.toHTML())
          else:
              # Can't encode this to a protocol message.  You should probably
              # render it to HTML and show it to the user.
              raise EncodingError(response)
          return wr
docs: Encode a response to a L{WebResponse}.
  
          @raises EncodingError: When I can't figure out how to encode this
              message.