def parse_output(self, result):
        """ Process the output of :meth:`Application.route_request`. """
        request = self.request

        if not request.auto_finish or request._finish is not None:
            return

        status = None

        if isinstance(result, Response):
            body = result.body
            status = result.status
            headers = result.headers

        elif isinstance(result, tuple):
            if len(result) == 3:
                body, status, headers = result
            else:
                body, status = result
                headers = HTTPHeaders()
                
        else:
            body = result
            headers = HTTPHeaders()

        # If we don't have a body, use a 204.
        if status is None:
            if body is None:
                status = 204
            else:
                status = 200

        # Use the rule headers stuff.
        if request._rule_headers:
            if isinstance(request._rule_headers, HTTPHeaders):
                rule_headers = request._rule_headers.copy()
            else:
                rule_headers = HTTPHeaders(request._rule_headers)

            if isinstance(headers, HTTPHeaders):
                rule_headers._data.update(headers._data)
            else:
                rule_headers.update(headers)

            headers = rule_headers

        # Determine if we're sending a body.
        send_body = request.method.upper() != 'HEAD' and status not in NO_BODY_CODES

        # Convert the body to something that we can send.
        if send_body:
            # Use the rule content-type.
            if request._rule_content_type and not 'Content-Type' in headers:
                headers['Content-Type'] = request._rule_content_type

            try:
                body = body.to_html()
                if not 'Content-Type' in headers:
                    headers['Content-Type'] = 'text/html'
            except AttributeError:
                pass

            # Set a Content-Type header if there isn't one already.
            if not 'Content-Type' in headers:
                if isinstance(body, basestring) and body[:5].lower() in \
                        ('<html', '<!doc'):
                    headers['Content-Type'] = 'text/html'
                elif isinstance(body, (tuple, list, dict)):
                    headers['Content-Type'] = 'application/json'
                else:
                    headers['Content-Type'] = 'text/plain'

            if isinstance(body, unicode):
                encoding = headers['Content-Type']
                if 'charset=' in encoding:
                    before, sep, enc = encoding.partition('charset=')
                else:
                    before = encoding
                    sep = '; charset='
                    enc = 'UTF-8'

                body = body.encode(enc)
                headers['Content-Type'] = before + sep + enc

            elif isinstance(body, (tuple, list, dict)):
                try:
                    body = json.dumps(body, cls=self.json_encoder)
                except Exception as err:
                    body, status, headers = self.handle_500(request, err)
                    body = body.encode('utf-8')
                    headers['Content-Type'] = 'text/html; charset=UTF-8'

            elif body is None:
                body = ''

            elif not isinstance(body, str):
                body = str(body)

            # More headers!
            if not 'Content-Length' in headers:
                headers['Content-Length'] = len(body)

        else:
            # We're not allowed to send the body, so strip out any headers about
            # the content of the body.
            if 'Content-Length' in headers:
                del headers['Content-Length']

            if 'Content-Type' in headers:
                del headers['Content-Type']

            if 'Transfer-Encoding' in headers:
                del headers['Transfer-Encoding']

        # Send the response.
        request.send_status(status)
        request.send_headers(headers)

        if send_body:
            request.write(body)

        request.finish()


###############################################################################
# Private Helper Functions
###############################################################################
dataset/ETHPy150Open ecdavis/pants/pants/web/application.py/Application.parse_output/original