Switch to unified view

a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
...
...
33
    try:
33
    try:
34
        tg.redirect(url)
34
        tg.redirect(url)
35
    except exc.HTTPFound, err:
35
    except exc.HTTPFound, err:
36
        raise exc.HTTPMovedPermanently(location=err.location)
36
        raise exc.HTTPMovedPermanently(location=err.location)
37
37
38
def cache_forever():
39
    headers = [
40
        (k,v) for k,v in response.headers.items()
41
        if k.lower() not in ('pragma', 'cache-control') ]
42
    delta = CACHE_CONTROL.apply(
43
        headers,
44
        public=True,
45
        max_age=60*60*24*365)
46
    EXPIRES.update(headers, delta=delta)
47
    response.headers.pop('cache-control', None)
48
    response.headers.pop('pragma', None)
49
    response.headers.update(headers)
50
51
class memoize_on_request(object):
52
53
    def __init__(self, *key, **kwargs):
54
        self.key = key
55
        self.include_func_in_key = kwargs.pop(
56
            'include_func_in_key', False)
57
        assert not kwargs, 'Extra args'
58
59
    def __call__(self, func):
60
        def wrapper(*args, **kwargs):
61
            cache = c.memoize_cache
62
            if self.include_func_in_key:
63
                key = (func, self.key, args, tuple(kwargs.iteritems()))
64
            else:
65
                key = (self.key, args, tuple(kwargs.iteritems()))
66
            if key in cache:
67
                result = cache[key]
68
            else:
69
                result = cache[key] = func(*args, **kwargs)
70
            return result
71
        wrapper.__name__ = 'wrap(%s)' % func.__name__
72
        return wrapper
73
38
74
def guess_mime_type(filename):
39
def guess_mime_type(filename):
75
    '''Guess MIME type based on filename.
40
    '''Guess MIME type based on filename.
76
    Applies heuristics, tweaks, and defaults in centralized manner.
41
    Applies heuristics, tweaks, and defaults in centralized manner.
77
    '''
42
    '''
...
...
473
    x = source()
438
    x = source()
474
    while x:
439
    while x:
475
        yield x
440
        yield x
476
        x = source()
441
        x = source()
477
442
478
def index_matching(pred, seq):
479
    '''Return the index of the first item from seq matching the predicate.
480
481
    If no items match the predicate, None is returned instead.'''
482
    for i,x in enumerate(seq):
483
        if pred(x):
484
            return i
485
    return None