'Create the XML tags that hold the http request or response body'

def handle_body(self, parent_node, headers, body):

    action_body_node = self._xml.createElement('body')
    action_body_node.setAttribute('content-encoding', 'text')
    if (INVALID_XML.search(body) or (']]>' in body)):
        encoded = base64.encodestring(xml_str(body, replace_invalid=False))
        action_body_content = self._xml.createTextNode(encoded)
        action_body_node.setAttribute('content-encoding', 'base64')
    else:
        (content_type, _) = headers.iget('Content-Type', '')
        try:
            (mime_type, sub_type) = content_type.split('/', 1)
        except ValueError:
            mime_type = 'application'
            sub_type = 'octet-stream'
        if (mime_type == 'text'):
            action_body_content = self._xml.createTextNode(body)
        elif ((mime_type == 'application') and (sub_type in NON_BIN)):
            action_body_content = self._xml.createCDATASection(body)
        else:
            encoded = base64.encodestring(xml_str(body, replace_invalid=False))
            action_body_content = self._xml.createTextNode(encoded)
            action_body_node.setAttribute('content-encoding', 'base64')
    action_body_node.appendChild(action_body_content)
    parent_node.appendChild(action_body_node)
