bbangert / dozer


WSGI middleware fork of Robert Brewer's Dowser
Clone URL : http://bitbucket.org/bbangert/dozer/ (size: 146.1 KB)
commit 25: afea1d2a0d65
parent 24: 9c7f31a852ba
branch: trunk
ignored paths are configurable via regular expressions now.
Armin Ronacher / mitsuhiko
4 months ago

Changed (Δ168 bytes):

raw changeset »

dozer/profile.py (12 lines added, 6 lines removed)

Up to file-list dozer/profile.py:

@@ -2,6 +2,7 @@ import cPickle
2
2
import cPickle
3
3
import time
4
4
import os
5
import re
5
6
from datetime import datetime
6
7
from pkg_resources import resource_filename
7
8
@@ -12,14 +13,18 @@ from webob import exc
12
13
13
14
here_dir = os.path.dirname(os.path.abspath(__file__))
14
15
16
DEFAULT_IGNORED_PATHS = [r'/favicon\.ico$', r'^/error/document']
17
15
18
class Profiler(object):
16
    def __init__(self, app, global_conf=None, profile_path=None, **kwargs):
19
    def __init__(self, app, global_conf=None, profile_path=None,
20
                 ignored_paths=DEFAULT_IGNORED_PATHS, **kwargs):
17
21
        """Profiles an application and saves the pickled version to a
18
22
        file
19
23
        """
20
24
        self.app = app
21
25
        self.conf = global_conf
22
26
        self.profile_path = profile_path
27
        self.ignored_paths = map(re.compile, ignored_paths)
23
28
        tmpl_dir = os.path.join(here_dir, 'templates')
24
29
        self.mako = TemplateLookup(directories=[tmpl_dir])
25
30
    
@@ -31,12 +36,13 @@ class Profiler(object):
31
36
        req.base_path = req.application_url + '/_profiler'
32
37
        if req.path_info_peek() == '_profiler':
33
38
            return self.profiler(req)(environ, start_response)
34
        elif not environ['PATH_INFO'].startswith('/error/document') and \
35
            not environ['PATH_INFO'].startswith('/favicon.ico'):
39
        for regex in self.ignored_paths:
40
            if regex.match(environ['PATH_INFO']) is not None:
41
                break
42
        else:
36
43
            return self.run_profile(environ, start_response)
37
        else:
38
            return self.app(environ, start_response)
39
    
44
        return self.app(environ, start_response)
45
40
46
    def profiler(self, req):
41
47
        assert req.path_info_pop() == '_profiler'
42
48
        next_part = req.path_info_pop()