Exemplo n.º 1
0
"""
    solace.utils.ctxlocal
    ~~~~~~~~~~~~~~~~~~~~~

    The context local that is used in the application and i18n system.  The
    application makes this request-bound.

    :copyright: (c) 2010 by the Solace Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from werkzeug import Local, LocalManager


local = Local()
local_mgr = LocalManager([local])


class LocalProperty(object):
    """Class/Instance property that returns something from the local."""

    def __init__(self, name):
        self.__name__ = name

    def __get__(self, obj, type=None):
        return getattr(local, self.__name__, None)


# make sure the request local is removed at the end of the request
from solace.signals import after_request_shutdown
after_request_shutdown.connect(local_mgr.cleanup)
Exemplo n.º 2
0
    if settings.TRACK_QUERIES:
        count = len(request.sql_queries)
        sql_time = 0.0
        for stmt, param, time in request.sql_queries:
            sql_time += time
        response.headers['X-SQL-Query-Count'] = str(count)
        response.headers['X-SQL-Query-Time'] = str(sql_time)


def request_track_query(cursor, statement, parameters, time):
    """If there is an active request, it logs the query on it."""
    if settings.TRACK_QUERIES:
        from solace.application import Request
        request = Request.current
        if request is not None:
            request.sql_queries.append((statement, parameters, time))


# make sure the session is removed at the end of the request and that
# query logging for the request works.
from solace.signals import after_request_shutdown, before_response_sent, \
     after_cursor_executed, before_cursor_executed, before_models_committed, \
     after_models_committed
after_request_shutdown.connect(session.remove)
before_response_sent.connect(add_query_debug_headers)
after_cursor_executed.connect(request_track_query)


# circular dependencies
from solace import settings
Exemplo n.º 3
0
    """Add headers with the SQL info."""
    if settings.TRACK_QUERIES:
        count = len(request.sql_queries)
        sql_time = 0.0
        for stmt, param, time in request.sql_queries:
            sql_time += time
        response.headers['X-SQL-Query-Count'] = str(count)
        response.headers['X-SQL-Query-Time'] = str(sql_time)


def request_track_query(cursor, statement, parameters, time):
    """If there is an active request, it logs the query on it."""
    if settings.TRACK_QUERIES:
        from solace.application import Request
        request = Request.current
        if request is not None:
            request.sql_queries.append((statement, parameters, time))


# make sure the session is removed at the end of the request and that
# query logging for the request works.
from solace.signals import after_request_shutdown, before_response_sent, \
     after_cursor_executed, before_cursor_executed, before_models_committed, \
     after_models_committed
after_request_shutdown.connect(session.remove)
before_response_sent.connect(add_query_debug_headers)
after_cursor_executed.connect(request_track_query)

# circular dependencies
from solace import settings