|
a/Allura/allura/lib/utils.py |
|
b/Allura/allura/lib/utils.py |
|
... |
|
... |
9 |
|
9 |
|
10 |
import tg
|
10 |
import tg
|
11 |
import pylons
|
11 |
import pylons
|
12 |
from formencode import Invalid
|
12 |
from formencode import Invalid
|
13 |
from tg.decorators import before_validate
|
13 |
from tg.decorators import before_validate
|
14 |
from pylons import response
|
14 |
from pylons import response, c
|
15 |
from paste.httpheaders import CACHE_CONTROL, EXPIRES
|
15 |
from paste.httpheaders import CACHE_CONTROL, EXPIRES
|
16 |
from webhelpers.html import literal
|
16 |
from webhelpers.html import literal
|
17 |
|
17 |
|
18 |
from ew import jinja2_ew as ew
|
18 |
from ew import jinja2_ew as ew
|
19 |
from ming.utils import LazyProperty
|
19 |
from ming.utils import LazyProperty
|
|
... |
|
... |
28 |
max_age=60*60*24*365)
|
28 |
max_age=60*60*24*365)
|
29 |
EXPIRES.update(headers, delta=delta)
|
29 |
EXPIRES.update(headers, delta=delta)
|
30 |
response.headers.pop('cache-control', None)
|
30 |
response.headers.pop('cache-control', None)
|
31 |
response.headers.pop('pragma', None)
|
31 |
response.headers.pop('pragma', None)
|
32 |
response.headers.update(headers)
|
32 |
response.headers.update(headers)
|
|
|
33 |
|
|
|
34 |
class memoize_on_request(object):
|
|
|
35 |
|
|
|
36 |
def __init__(self, *key, **kwargs):
|
|
|
37 |
self.key = key
|
|
|
38 |
self.include_func_in_key = kwargs.pop(
|
|
|
39 |
'include_func_in_key', False)
|
|
|
40 |
assert not kwargs, 'Extra args'
|
|
|
41 |
|
|
|
42 |
def __call__(self, func):
|
|
|
43 |
def wrapper(*args, **kwargs):
|
|
|
44 |
cache = c.memoize_cache
|
|
|
45 |
if self.include_func_in_key:
|
|
|
46 |
key = (func, self.key, args, tuple(kwargs.iteritems()))
|
|
|
47 |
else:
|
|
|
48 |
key = (self.key, args, tuple(kwargs.iteritems()))
|
|
|
49 |
if key in cache:
|
|
|
50 |
result = cache[key]
|
|
|
51 |
else:
|
|
|
52 |
result = cache[key] = func(*args, **kwargs)
|
|
|
53 |
return result
|
|
|
54 |
wrapper.__name__ = 'wrap(%s)' % func.__name__
|
|
|
55 |
return wrapper
|
33 |
|
56 |
|
34 |
def guess_mime_type(filename):
|
57 |
def guess_mime_type(filename):
|
35 |
'''Guess MIME type based on filename.
|
58 |
'''Guess MIME type based on filename.
|
36 |
Applies heuristics, tweaks, and defaults in centralized manner.
|
59 |
Applies heuristics, tweaks, and defaults in centralized manner.
|
37 |
'''
|
60 |
'''
|