Mercurial > moin > 1.9
annotate MoinMoin/action/cache.py @ 3872:9eb4ffbe654d
cache action: improve docstrings
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sat, 19 Jul 2008 10:26:47 +0200 |
parents | 6e7ef632d9b3 |
children | e5a9570d3001 |
rev | line source |
---|---|
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1 # -*- coding: iso-8859-1 -*- |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
2 """ |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
3 MoinMoin - Send a raw object from the caching system (and offer utility |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
4 functions to put data into cache, calculate cache key, etc.). |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
5 |
3872
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
6 Sample usage |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
7 ------------ |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
8 Assume we have a big picture (bigpic) and we want to efficiently show some |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
9 thumbnail (thumbpic) for it: |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
10 |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
11 # first calculate a (hard to guess) cache key (this key will change if the |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
12 # original data (bigpic) changes): |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
13 key = cache.key(..., attachname=bigpic, ...) |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
14 |
3872
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
15 # check if we don't have it in cache yet |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
16 if not cache.exists(..., key): |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
17 # if we don't have it in cache, we need to render it - this is an |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
18 # expensive operation that we want to avoid by caching: |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
19 thumbpic = render_thumb(bigpic) |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
20 # put expensive operation's results into cache: |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
21 cache.put(..., key, thumbpic, ...) |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
22 |
3872
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
23 url = cache.url(..., key) |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
24 html = '<img src="%s">' % url |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
25 |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
26 TODO: |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
27 * add secret to wikiconfig |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
28 * add error handling |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
29 * maybe use page local caching, not global: |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
30 + smaller directories |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
31 - but harder to clean |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
32 - harder to backup data_dir |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
33 * move file-like code to caching module |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
34 * add auto-key generation? |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
35 |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
36 @copyright: 2008 MoinMoin:ThomasWaldmann |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
37 @license: GNU GPL, see COPYING for details. |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
38 """ |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
39 |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
40 import hmac, sha |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
41 |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
42 from MoinMoin import log |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
43 logging = log.getLogger(__name__) |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
44 |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
45 # keep both imports below as they are, order is important: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
46 from MoinMoin import wikiutil |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
47 import mimetypes |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
48 |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
49 from MoinMoin import config, caching |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
50 from MoinMoin.util import filesys |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
51 from MoinMoin.action import AttachFile |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
52 |
3855
5e35dd32656f
cache action: calculate action_name, more comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3854
diff
changeset
|
53 action_name = __name__.split('.')[-1] |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
54 |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
55 # Do NOT get this directly from request.form or user would be able to read any cache! |
3855
5e35dd32656f
cache action: calculate action_name, more comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3854
diff
changeset
|
56 cache_arena = 'sendcache' # just using action_name is maybe rather confusing |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
57 cache_scope = 'wiki' |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
58 do_locking = False |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
59 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
60 def key(request, wikiname=None, itemname=None, attachname=None, content=None, secret=None): |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
61 """ |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
62 Calculate a (hard-to-guess) cache key. |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
63 |
3872
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
64 Important key properties: |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
65 * The key must be hard to guess (this is because do=get does no ACL checks, |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
66 so whoever got the key [e.g. from html rendering of an ACL protected wiki |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
67 page], will be able to see the cached content. |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
68 * The key must change if the (original) content changes. This is because |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
69 ACLs on some item may change and even if somebody was allowed to see some |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
70 revision of some item, it does not implicate that he is allowed to see |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
71 any other revision also. There will be no harm if he can see exactly the |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
72 same content again, but there could be harm if he could access a revision |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
73 with different content. |
9eb4ffbe654d
cache action: improve docstrings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3871
diff
changeset
|
74 |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
75 If content is supplied, we will calculate and return a hMAC of the content. |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
76 |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
77 If wikiname, itemname, attachname is given, we don't touch the content (nor do |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
78 we read it ourselves from the attachment file), but we just calculate a key |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
79 from the given metadata values and some metadata we get from the filesystem. |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
80 |
3854
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
81 Hint: if you need multiple cache objects for the same source content (e.g. |
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
82 thumbnails of different sizes for the same image), calculate the key |
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
83 only once and then add some different prefixes to it to get the final |
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
84 cache keys. |
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
85 |
3833
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
86 @param request: the request object |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
87 @param wikiname: the name of the wiki (if not given, will be read from cfg) |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
88 @param itemname: the name of the page |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
89 @param attachname: the filename of the attachment |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
90 @param content: content data as unicode object (e.g. for page content or |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
91 parser section content) |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
92 """ |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
93 secret = secret or 'nobodyexpectedsuchasecret' |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
94 if content: |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
95 hmac_data = content |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
96 elif itemname is not None and attachname is not None: |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
97 wikiname = wikiname or request.cfg.interwikiname or request.cfg.siteid |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
98 fuid = filesys.fuid(AttachFile.getFilename(request, itemname, attachname)) |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
99 hmac_data = u''.join([wikiname, itemname, attachname, repr(fuid)]) |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
100 else: |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
101 raise AssertionError('cache_key called with unsupported parameters') |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
102 |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
103 hmac_data = hmac_data.encode('utf-8') |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
104 key = hmac.new(secret, hmac_data, sha).hexdigest() |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
105 return key |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
106 |
712e5938ec59
sendcached action: new function cache_key to calculate hard-to-guess cache keys from either content (parser sections) or wiki/page/file name and some metadata from filesystem (attachments)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3801
diff
changeset
|
107 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
108 def put(request, key, data, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
109 filename=None, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
110 content_type=None, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
111 content_disposition=None, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
112 content_length=None, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
113 last_modified=None, |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
114 bufsize=8192): |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
115 """ |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
116 Put an object into the cache to send it with cache action later. |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
117 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
118 @param request: the request object |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
119 @param key: non-guessable key into cache (str) |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
120 @param data: content data (str or open file-like obj) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
121 @param filename: filename for content-disposition header and for autodetecting |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
122 content_type (unicode, default: None) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
123 @param content_disposition: type for content-disposition header (str, default: None) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
124 @param content_type: content-type header value (str, default: autodetect from filename) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
125 @param last_modified: last modified timestamp (int, default: autodetect) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
126 @param content_length: data length for content-length header (int, default: autodetect) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
127 """ |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
128 import os.path |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
129 from MoinMoin.util import timefuncs |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
130 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
131 if filename: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
132 # make sure we just have a simple filename (without path) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
133 filename = os.path.basename(filename) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
134 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
135 if content_type is None: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
136 # try autodetect |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
137 mt, enc = mimetypes.guess_type(filename) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
138 if mt: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
139 content_type = mt |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
140 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
141 if content_type is None: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
142 content_type = 'application/octet-stream' |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
143 |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
144 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking) |
3865
4ffd618f2826
caching: support file-like content for update(), new size() function. cache action: use file-like api of caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3855
diff
changeset
|
145 data_cache.update(data) |
4ffd618f2826
caching: support file-like content for update(), new size() function. cache action: use file-like api of caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3855
diff
changeset
|
146 content_length = content_length or data_cache.size() |
4ffd618f2826
caching: support file-like content for update(), new size() function. cache action: use file-like api of caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3855
diff
changeset
|
147 last_modified = last_modified or data_cache.mtime() |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
148 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
149 last_modified = timefuncs.formathttpdate(int(last_modified)) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
150 headers = ['Content-Type: %s' % content_type, |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
151 'Last-Modified: %s' % last_modified, |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
152 'Content-Length: %s' % content_length, |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
153 ] |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
154 if content_disposition and filename: |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
155 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
156 # There is no solution that is compatible to IE except stripping non-ascii chars |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
157 filename = filename.encode(config.charset) |
3854
30240e801a55
cache action: add some hint, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3853
diff
changeset
|
158 headers.append('Content-Disposition: %s; filename="%s"' % (content_disposition, filename)) |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
159 |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
160 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
161 meta_cache.update((last_modified, headers)) |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
162 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
163 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
164 def exists(request, key, strict=False): |
3801
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
165 """ |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
166 Check if a cached object for this key exists. |
3801
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
167 |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
168 @param request: the request object |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
169 @param key: non-guessable key into cache (str) |
3801
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
170 @param strict: if True, also check the data cache, not only meta (bool, default: False) |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
171 @return: is object cached? (bool) |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
172 """ |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
173 if strict: |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
174 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking) |
3801
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
175 data_cached = data_cache.exists() |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
176 else: |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
177 data_cached = True # we assume data will be there if meta is there |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
178 |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
179 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) |
3801
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
180 meta_cached = meta_cache.exists() |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
181 |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
182 return meta_cached and data_cached |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
183 |
7eb4a14108de
sendcached: add missing request param, add is_cached() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3800
diff
changeset
|
184 |
3853
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
185 def remove(request, key): |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
186 """ delete headers/data cache for key """ |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
187 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
188 meta_cache.remove() |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
189 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking) |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
190 data_cache.remove() |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
191 |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
192 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
193 def url(request, key, do='get'): |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
194 """ return URL for the object cached for key """ |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
195 return "%s/?%s" % ( |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
196 request.getScriptname(), |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
197 wikiutil.makeQueryString(dict(action=action_name, do=do, key=key), want_unicode=False)) |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
198 |
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
199 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
200 def _get_headers(request, key): |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
201 """ get last_modified and headers cached for key """ |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
202 meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True) |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
203 last_modified, headers = meta_cache.content() |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
204 return last_modified, headers |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
205 |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
206 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
207 def _get_datafile(request, key): |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
208 """ get an open data file for the data cached for key """ |
3849
d9a525a1450e
cache action: s/sendcached/cache/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3848
diff
changeset
|
209 data_cache = caching.CacheEntry(request, cache_arena, key+'.data', cache_scope, do_locking=do_locking) |
3865
4ffd618f2826
caching: support file-like content for update(), new size() function. cache action: use file-like api of caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3855
diff
changeset
|
210 data_cache.open(mode='r') |
4ffd618f2826
caching: support file-like content for update(), new size() function. cache action: use file-like api of caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3855
diff
changeset
|
211 return data_cache |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
212 |
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
213 |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
214 def _do_get(request, key): |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
215 """ send a complete http response with headers/data cached for key """ |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
216 last_modified, headers = _get_headers(request, key) |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
217 if request.if_modified_since == last_modified: |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
218 request.emit_http_headers(["Status: 304 Not modified"]) |
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
219 else: |
3798
17e94abc5320
sendcached: added a put_cache and get_url function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3785
diff
changeset
|
220 request.emit_http_headers(headers) |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
221 request.send_file(_get_datafile(request, key)) |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
222 |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
223 |
3853
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
224 def _do_remove(request, key): |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
225 """ delete headers/data cache for key """ |
3853
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
226 remove(request, key) |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
227 request.emit_http_headers(["Status: 200 OK"]) |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
228 |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
229 |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
230 def _do(request, do, key): |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
231 if do == 'get': |
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
232 _do_get(request, key) |
3853
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
233 elif do == 'remove': |
3b37036d466d
cache action: add remove() function
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3850
diff
changeset
|
234 _do_remove(request, key) |
3785
651f505bd9f1
sendcached action (completely untested)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
235 |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
236 def execute(pagename, request): |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
237 do = request.form.get('do', [None])[0] |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
238 key = request.form.get('key', [None])[0] |
3850
0324aa222029
action cache: rename some methods, add 'del' subaction
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3849
diff
changeset
|
239 _do(request, do, key) |
3800
07ea9c357b2a
sendcached: made some functions for usage from other modules, added comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3799
diff
changeset
|
240 |