<commit_before>#
# Copyright (c) 2005-2008 rPath, Inc.
# All rights reserved
#

import os, time, socket, tempfile, sys, traceback, shutil
from conary.lib import util as conary_util

from mint.mint_error import MailError
from mint import users

def logErrorAndEmail(req, cfg, exception, e, bt):
    from mod_python import apache
    c = req.connection
    req.add_common_vars()
    info_dict = {
        'local_addr'     : c.local_ip + ':' + str(c.local_addr[1]),
        'local_host'     : c.local_host,
        'protocol'       : req.protocol,
        'hostname'       : req.hostname,
        'request_time'   : time.ctime(req.request_time),
        'status'         : req.status,
        'method'         : req.method,
        'headers_in'     : req.headers_in,
        'headers_out'    : req.headers_out,
        'uri'            : req.uri,
        'subprocess_env' : req.subprocess_env,
        'referer'        : req.headers_in.get('referer', 'N/A')
    }

    timeStamp = time.ctime(time.time())
    realHostName = socket.getfqdn()

    # Format large traceback to file
    (fd, tb_path) = tempfile.mkstemp('.txt', 'mint-error-')
    large = os.fdopen(fd, 'w')
    print >>large, 'Unhandled exception from mint web interface on %s:' \
        % realHostName
    print >>large, 'Time of occurrence: %s' % timeStamp
    print >>large, 'See also: %s' % tb_path
    print >>large
    conary_util.formatTrace(exception, e, bt, stream=large, withLocals=False)
    print >>large
    print >>large, 'Full stack:'
    print >>large
    try:
        conary_util.formatTrace(exception, e, bt, stream=large, withLocals=True)
    except:
        # The extended traceback formatter can crash when uncooperative
        # objects do something special when marshalled. For example,
        # derivatives of Thread may abort before Thread itself is
        # initialized, which causes __repr__ to crash, and<commit_msg>logerror should be opened w+ since we're reading from it<commit_after>#
# Copyright (c) 2005-2008 rPath, Inc.
# All rights reserved
#

import os, time, socket, tempfile, sys, traceback, shutil
from conary.lib import util as conary_util

from mint.mint_error import MailError
from mint import users

def logErrorAndEmail(req, cfg, exception, e, bt):
    from mod_python import apache
    c = req.connection
    req.add_common_vars()
    info_dict = {
        'local_addr'     : c.local_ip + ':' + str(c.local_addr[1]),
        'local_host'     : c.local_host,
        'protocol'       : req.protocol,
        'hostname'       : req.hostname,
        'request_time'   : time.ctime(req.request_time),
        'status'         : req.status,
        'method'         : req.method,
        'headers_in'     : req.headers_in,
        'headers_out'    : req.headers_out,
        'uri'            : req.uri,
        'subprocess_env' : req.subprocess_env,
        'referer'        : req.headers_in.get('referer', 'N/A')
    }

    timeStamp = time.ctime(time.time())
    realHostName = socket.getfqdn()

    # Format large traceback to file
    (fd, tb_path) = tempfile.mkstemp('.txt', 'mint-error-')
    large = os.fdopen(fd, 'w+')
    print >>large, 'Unhandled exception from mint web interface on %s:' \
        % realHostName
    print >>large, 'Time of occurrence: %s' % timeStamp
    print >>large, 'See also: %s' % tb_path
    print >>large
    conary_util.formatTrace(exception, e, bt, stream=large, withLocals=False)
    print >>large
    print >>large, 'Full stack:'
    print >>large
    try:
        conary_util.formatTrace(exception, e, bt, stream=large, withLocals=True)
    except:
        # The extended traceback formatter can crash when uncooperative
        # objects do something special when marshalled. For example,
        # derivatives of Thread may abort before Thread itself is
        # initialized, which causes __repr__ to crash, and
{'fraction_non_alphanumeric': 0.11217616580310881, 'fraction_numerical': 0.00466321243523316, 'mean_word_length': 2.642452830188679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1417221', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1219, 'n_words': 338}