'Encode a buffered response body.'

def encode_string(self, encoding):

    if (encoding in self.attempted_charsets):
        return False
    self.attempted_charsets.add(encoding)
    try:
        body = []
        for chunk in self.body:
            if isinstance(chunk, unicodestr):
                chunk = chunk.encode(encoding, self.errors)
            body.append(chunk)
        self.body = body
    except (LookupError, UnicodeError):
        return False
    else:
        return True
