def emailerrors(to_address, olderror, from_address=None):
    """
    Wraps the old `internalerror` handler (pass as `olderror`) to 
    additionally email all errors to `to_address`, to aid in
    debugging production websites.
    
    Emails contain a normal text traceback as well as an
    attachment containing the nice `debugerror` page.
    """
    from_address = from_address or to_address

    def emailerrors_internal():
        error = olderror()
        tb = sys.exc_info()
        error_name = tb[0]
        error_value = tb[1]
        tb_txt = ''.join(traceback.format_exception(*tb))
        path = web.ctx.path
        request = web.ctx.method + ' ' + web.ctx.home + web.ctx.fullpath
        
        message = "\n%s\n\n%s\n\n" % (request, tb_txt)
        
        sendmail(
            "your buggy site <%s>" % from_address,
            "the bugfixer <%s>" % to_address,
            "bug: %(error_name)s: %(error_value)s (%(path)s)" % locals(),
            message,
            attachments=[
                dict(filename="bug.html", content=safestr(djangoerror()))
            ],
        )
        return error
    
    return emailerrors_internal
dataset/ETHPy150Open rouge8/20questions/web/debugerror.py/emailerrors/original