-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
|
||
setup( | ||
name='django-speedinfo', | ||
version='1.3.7', | ||
packages=['speedinfo', 'speedinfo.migrations'], | ||
version='1.4.0', | ||
packages=['speedinfo', 'speedinfo.migrations', 'speedinfo.conditions'], | ||
include_package_data=True, | ||
license='MIT', | ||
description='Live profiling tool for Django framework to measure views performance', | ||
|
@@ -19,7 +19,6 @@ | |
author='Evgeniy Krysanov', | ||
author_email='[email protected]', | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
'Environment :: Web Environment', | ||
'Framework :: Django', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# coding: utf-8 | ||
|
||
from importlib import import_module | ||
|
||
from speedinfo.settings import speedinfo_settings | ||
|
||
|
||
class ConditionsDispatcher: | ||
def __init__(self): | ||
self.conditions = None | ||
|
||
def import_conditions(self): | ||
self.conditions = [] | ||
|
||
for module_path in speedinfo_settings.SPEEDINFO_PROFILING_CONDITIONS: | ||
path, class_name = module_path.rsplit('.', 1) | ||
|
||
try: | ||
module = import_module(path) | ||
self.conditions.append( | ||
getattr(module, class_name)() | ||
) | ||
except (AttributeError, ImportError) as e: | ||
msg = 'Could not import "{}". {}: {}.'.format(module_path, e.__class__.__name__, e) | ||
raise ImportError(msg) | ||
|
||
def get_conditions(self): | ||
if self.conditions is None: | ||
self.import_conditions() | ||
|
||
return self.conditions | ||
|
||
|
||
conditions_dispatcher = ConditionsDispatcher() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# coding: utf-8 | ||
|
||
|
||
class Condition: | ||
""" | ||
Base class for user-defined profiling condition classes | ||
""" | ||
def process_request(self, request): | ||
""" | ||
:type request: :class:`django.http.HttpRequest` | ||
:return: False if requested page should be excluded from profiling | ||
:rtype: bool | ||
""" | ||
raise NotImplementedError | ||
|
||
def process_response(self, response): | ||
""" | ||
:type response: :class:`django.http.HttpResponse` | ||
:return: False if requested page should be excluded from profiling | ||
:rtype: bool | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# coding: utf-8 | ||
|
||
import re | ||
|
||
from speedinfo.conditions.base import Condition | ||
from speedinfo.settings import speedinfo_settings | ||
|
||
|
||
class ExcludeURLCondition(Condition): | ||
""" | ||
Plugin for conditional profiling based on the list of | ||
urls specified in SPEEDINFO_EXCLUDE_URLS settings | ||
""" | ||
def __init__(self): | ||
self.patterns = None | ||
|
||
def get_patterns(self): | ||
if (self.patterns is None) or speedinfo_settings.SPEEDINFO_TESTS: | ||
self.patterns = [re.compile(pattern) for pattern in speedinfo_settings.SPEEDINFO_EXCLUDE_URLS] | ||
|
||
return self.patterns | ||
|
||
def process_request(self, request): | ||
"""Checks requested page url against the list of excluded urls. | ||
:type request: :class:`django.http.HttpRequest` | ||
:return: False if path matches to any of the exclude urls | ||
:rtype: bool | ||
""" | ||
for pattern in self.get_patterns(): | ||
if pattern.match(request.path): | ||
return False | ||
|
||
return True | ||
|
||
def process_response(self, response): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters