# Path: pypi_portal/extensions.py
# LOG = getLogger(__name__)
# def _on_connect(dbapi_connection, **_):
# 
# Path: pypi_portal/models/redis.py
# EMAIL_THROTTLE = 'pypi_portal:email_throttle:{md5}'  # Lock.


from contextlib import contextmanager
from logging import getLogger
from flask import current_app
from flask.ext.mail import Message
from werkzeug.debug import tbtools
from pypi_portal.extensions import mail, redis
from pypi_portal.models.redis import EMAIL_THROTTLE
import hashlib
    tbtools.PAGE_HTML = page_html
    tbtools.SUMMARY_HTML = summary_html
    tbtools.FRAME_HTML = frame_html
    yield  # Let `with` block execute.
    # Revert changes.
    tbtools.PAGE_HTML = old_page_html
    tbtools.SUMMARY_HTML = old_summary
    tbtools.FRAME_HTML = old_frame


def send_exception(subject):
    """Send Python exception tracebacks via email to the ADMINS list.

    Use the same HTML styling as Flask tracebacks in debug web servers.

    This function must be called while the exception is happening. It picks up the raised exception with sys.exc_info().

    Positional arguments:
    subject -- subject line of the email (to be prepended by 'Application Error: ').
    """
    # Generate and modify html.
    tb = tbtools.get_current_traceback()  # Get exception information.
    with _override_html():
        html = tb.render_full().encode('utf-8', 'replace')
    html = html.replace('<blockquote>', '<blockquote style="margin: 1em 0 0; padding: 0;">')
    subject = 'Application Error: {}'.format(subject)

    # Apply throttle.
    md5 = hashlib.md5('{}{}'.format(subject, html)).hexdigest()
    seconds = int(current_app.config['MAIL_EXCEPTION_THROTTLE'])

# Path: pypi_portal/extensions.py
# LOG = getLogger(__name__)
# def _on_connect(dbapi_connection, **_):
# 
# Path: pypi_portal/models/redis.py
# EMAIL_THROTTLE = 'pypi_portal:email_throttle:{md5}'  # Lock.


# Path: pypi_portal/core/email.py
from contextlib import contextmanager
from logging import getLogger
from flask import current_app
from flask.ext.mail import Message
from werkzeug.debug import tbtools
from pypi_portal.extensions import mail, redis
from pypi_portal.models.redis import EMAIL_THROTTLE
import hashlib

    tbtools.PAGE_HTML = page_html
    tbtools.SUMMARY_HTML = summary_html
    tbtools.FRAME_HTML = frame_html
    yield  # Let `with` block execute.
    # Revert changes.
    tbtools.PAGE_HTML = old_page_html
    tbtools.SUMMARY_HTML = old_summary
    tbtools.FRAME_HTML = old_frame


def send_exception(subject):
    """Send Python exception tracebacks via email to the ADMINS list.

    Use the same HTML styling as Flask tracebacks in debug web servers.

    This function must be called while the exception is happening. It picks up the raised exception with sys.exc_info().

    Positional arguments:
    subject -- subject line of the email (to be prepended by 'Application Error: ').
    """
    # Generate and modify html.
    tb = tbtools.get_current_traceback()  # Get exception information.
    with _override_html():
        html = tb.render_full().encode('utf-8', 'replace')
    html = html.replace('<blockquote>', '<blockquote style="margin: 1em 0 0; padding: 0;">')
    subject = 'Application Error: {}'.format(subject)

    # Apply throttle.
    md5 = hashlib.md5('{}{}'.format(subject, html)).hexdigest()
    seconds = int(current_app.config['MAIL_EXCEPTION_THROTTLE'])

    lock = redis.lock(EMAIL_THROTTLE.format(md5=md5), timeout=seconds)