<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def render_error(request, exc):
 '''Default renderer for errors.''' cfg = request.get('pulsar.cfg') debug = cfg.debug if cfg else False response = request.response if not response.content_type: content_type = request.get('default.content_type') response.content_type = request.content_types.best_match( as_tuple(content_type or DEFAULT_RESPONSE_CONTENT_TYPES) ) content_type = None if response.content_type: content_type = response.content_type.split(';')[0] is_html = content_type == 'text/html' if debug: msg = render_error_debug(request, exc, is_html) else: msg = escape(error_messages.get(response.status_code) or exc) if is_html: msg = textwrap.dedent(""" <h1>{0[reason]}</h1> {0[msg]} <h3>{0[version]}</h3> """
).format({"reason": response.status, "msg": msg,
                         "version": request.environ['SERVER_SOFTWARE']})
    #
    if content_type == 'text/html':
        doc = HtmlDocument(title=response.status)
        doc.head.embedded_css.append(error_css)
        doc.body.append(Html('div', msg, cn='pulsar-error'))
        return doc.to_bytes(request)
    elif content_type in JSON_CONTENT_TYPES:
        return json.dumps({'status': response.status_code,
                           'message': msg})
    else:
        return '\n'.join(msg) if isinstance(msg, (list, tuple)) else msg