'Encode a body using an optionally specified encoding.
The encoding can be specified by name, and is looked up in
self.codecs. self.codecs uses strings as its keys which specify
the name of the encoding, and then the value is an instantiated
object that can provide encoding/decoding of that type through
encode and decode methods.
:param body: The body to be encoded.
:type body: str
:keyword encoding: The encoding type to be used. Must be a supported
codec listed in self.codecs.
:type encoding: str
:return: If encoding is specified, return a tuple with the first
position being the encoded body, and the second position the
encoding used. If encoding is not specified, the body is passed
through unchanged.
:rtype: tuple'

def encode_body(self, body, encoding=None):

    if encoding:
        return (self.codecs.get(encoding).encode(body), encoding)
    return (body, encoding)
