'Make a best-effort attempt to write an error page. If headers are
already sent, we just bung the error into the page.'

def error_page(self, soc, headers_sent, s):

    c = '\n                                                <html>\n                                                                <h1>Internal    Server    Error</h1>\n                                                                <pre>{err}"</pre>\n                                                </html>\n                                '.format(err=s).strip().encode()
    if (not headers_sent):
        soc.write('HTTP/1.1    500    Internal    Server    Error\r\n')
        soc.write('Content-Type:    text/html\r\n')
        soc.write('Content-Length:    {length}\r\n'.format(length=len(c)).encode())
        soc.write('\r\n')
    soc.write(c)
