# Path: speedinfo/profiler.py
# class Profiler(object):
#     PROFILER_STATE_CACHE_KEY = "speedinfo.profiler.is_on"
#     def __init__(self):
#     def is_on(self):
#     def is_on(self, value):
#     def storage(self):
# 
# Path: speedinfo/conditions/dispatcher.py
# class ConditionsDispatcher:
#     def __init__(self):
#     def import_conditions(self):
#     def get_conditions(self):
# 
# Path: speedinfo/conf.py
# DEFAULTS = {
#     "SPEEDINFO_TESTS": False,
#     "SPEEDINFO_CACHED_RESPONSE_ATTR_NAME": "_is_cached",
#     "SPEEDINFO_STORAGE": None,
#     "SPEEDINFO_CACHE_STORAGE_CACHE_ALIAS": "default",
#     "SPEEDINFO_PROFILING_CONDITIONS": [],
#     "SPEEDINFO_EXCLUDE_URLS": [],
#     "SPEEDINFO_ADMIN_COLUMNS": (
#         ("View name", "{}", "view_name"),
#         ("HTTP method", "{}", "method"),
#         ("Anonymous calls", "{:.1f}%", "anon_calls_ratio"),
#         ("Cache hits", "{:.1f}%", "cache_hits_ratio"),
#         ("SQL queries per call", "{}", "sql_count_per_call"),
#         ("SQL time", "{:.1f}%", "sql_time_ratio"),
#         ("Total calls", "{}", "total_calls"),
#         ("Time per call", "{:.8f}", "time_per_call"),
#         ("Total time", "{:.4f}", "total_time"),
#     ),
# }
# class SpeedinfoSettings:
#     def __init__(self, defaults=None):
#     def __getattr__(self, name):


from timeit import default_timer
from django.conf import settings
from django.db import connections
from speedinfo import profiler
from speedinfo.conditions.dispatcher import conditions_dispatcher
from speedinfo.conf import speedinfo_settings
    from django.urls import resolve, Resolver404  # Django >= 1.10
    from django.core.urlresolvers import resolve, Resolver404
        :rtype: :class:`django.http.HttpResponse` or :class:`django.http.StreamingHttpResponse`
        """
        if self.is_active:
            if self.can_process_response(response):
                view_execution_time = default_timer() - self.start_time

                # Calculate the execution time and the number of SQL queries.
                # Exclude queries made before the call of our middleware (e.g. in SessionMiddleware).
                sql_count = sum([
                    len(conn.queries) for conn in connections.all()
                ]) - self.initial_sql_count

                sql_time = sum([
                    sum(float(q["time"]) for q in conn.queries)
                    for conn in connections.all()
                ]) - self.initial_sql_time

                # Collects request and response params
                view_name = self.get_view_name(request)
                is_cache_hit = getattr(response, speedinfo_settings.SPEEDINFO_CACHED_RESPONSE_ATTR_NAME, False)

                if not hasattr(request, "user"):
                    is_anon_call = True
                else:
                    if callable(request.user.is_anonymous):
                        is_anon_call = request.user.is_anonymous()
                    else:
                        is_anon_call = request.user.is_anonymous

                # Saves profiler data

# Path: speedinfo/profiler.py
# class Profiler(object):
#     PROFILER_STATE_CACHE_KEY = "speedinfo.profiler.is_on"
#     def __init__(self):
#     def is_on(self):
#     def is_on(self, value):
#     def storage(self):
# 
# Path: speedinfo/conditions/dispatcher.py
# class ConditionsDispatcher:
#     def __init__(self):
#     def import_conditions(self):
#     def get_conditions(self):
# 
# Path: speedinfo/conf.py
# DEFAULTS = {
#     "SPEEDINFO_TESTS": False,
#     "SPEEDINFO_CACHED_RESPONSE_ATTR_NAME": "_is_cached",
#     "SPEEDINFO_STORAGE": None,
#     "SPEEDINFO_CACHE_STORAGE_CACHE_ALIAS": "default",
#     "SPEEDINFO_PROFILING_CONDITIONS": [],
#     "SPEEDINFO_EXCLUDE_URLS": [],
#     "SPEEDINFO_ADMIN_COLUMNS": (
#         ("View name", "{}", "view_name"),
#         ("HTTP method", "{}", "method"),
#         ("Anonymous calls", "{:.1f}%", "anon_calls_ratio"),
#         ("Cache hits", "{:.1f}%", "cache_hits_ratio"),
#         ("SQL queries per call", "{}", "sql_count_per_call"),
#         ("SQL time", "{:.1f}%", "sql_time_ratio"),
#         ("Total calls", "{}", "total_calls"),
#         ("Time per call", "{:.8f}", "time_per_call"),
#         ("Total time", "{:.4f}", "total_time"),
#     ),
# }
# class SpeedinfoSettings:
#     def __init__(self, defaults=None):
#     def __getattr__(self, name):


# Path: speedinfo/middleware.py
from timeit import default_timer
from django.conf import settings
from django.db import connections
from speedinfo import profiler
from speedinfo.conditions.dispatcher import conditions_dispatcher
from speedinfo.conf import speedinfo_settings
    from django.urls import resolve, Resolver404  # Django >= 1.10
    from django.core.urlresolvers import resolve, Resolver404

        :rtype: :class:`django.http.HttpResponse` or :class:`django.http.StreamingHttpResponse`
        """
        if self.is_active:
            if self.can_process_response(response):
                view_execution_time = default_timer() - self.start_time

                # Calculate the execution time and the number of SQL queries.
                # Exclude queries made before the call of our middleware (e.g. in SessionMiddleware).
                sql_count = sum([
                    len(conn.queries) for conn in connections.all()
                ]) - self.initial_sql_count

                sql_time = sum([
                    sum(float(q["time"]) for q in conn.queries)
                    for conn in connections.all()
                ]) - self.initial_sql_time

                # Collects request and response params
                view_name = self.get_view_name(request)
                is_cache_hit = getattr(response, speedinfo_settings.SPEEDINFO_CACHED_RESPONSE_ATTR_NAME, False)

                if not hasattr(request, "user"):
                    is_anon_call = True
                else:
                    if callable(request.user.is_anonymous):
                        is_anon_call = request.user.is_anonymous()
                    else:
                        is_anon_call = request.user.is_anonymous

                # Saves profiler data

                profiler.storage.add(