~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/action/cache.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
action_name = __name__.split('.')[-1]
43
43
 
44
 
# Do NOT get this directly from request.form or user would be able to read any cache!
 
44
# Do NOT get this directly from request.values or user would be able to read any cache!
45
45
cache_arena = 'sendcache'  # just using action_name is maybe rather confusing
46
46
 
47
47
# We maybe could use page local caching (not 'wiki' global) to have less directory entries.
146
146
    last_modified = last_modified or data_cache.mtime()
147
147
 
148
148
    httpdate_last_modified = timefuncs.formathttpdate(int(last_modified))
149
 
    headers = ['Content-Type: %s' % content_type,
150
 
               'Last-Modified: %s' % httpdate_last_modified,
151
 
               'Content-Length: %s' % content_length,
 
149
    headers = [('Content-Type', content_type),
 
150
               ('Last-Modified', httpdate_last_modified),
 
151
               ('Content-Length', content_length),
152
152
              ]
153
153
    if content_disposition and filename:
154
154
        # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
155
155
        # There is no solution that is compatible to IE except stripping non-ascii chars
156
156
        filename = filename.encode(config.charset)
157
 
        headers.append('Content-Disposition: %s; filename="%s"' % (content_disposition, filename))
 
157
        headers.append(('Content-Disposition', '%s; filename="%s"' % (content_disposition, filename)))
158
158
 
159
159
    meta_cache = caching.CacheEntry(request, cache_arena, key+'.meta', cache_scope, do_locking=do_locking, use_pickle=True)
160
160
    meta_cache.update({
196
196
 
197
197
def url(request, key, do='get'):
198
198
    """ return URL for the object cached for key """
199
 
    return "%s/?%s" % (
200
 
        request.getScriptname(),
201
 
        wikiutil.makeQueryString(dict(action=action_name, do=do, key=key), want_unicode=False))
202
 
 
 
199
    return request.href(action=action_name, do=do, key=key)
203
200
 
204
201
def _get_headers(request, key):
205
202
    """ get last_modified and headers cached for key """
220
217
    try:
221
218
        last_modified, headers = _get_headers(request, key)
222
219
        if request.if_modified_since == last_modified:
223
 
            request.emit_http_headers(["Status: 304 Not modified"])
 
220
            request.status_code = 304
224
221
        else:
 
222
            for k, v in headers:
 
223
                request.headers.add(k, v)
225
224
            data_file = _get_datafile(request, key)
226
 
            request.emit_http_headers(headers)
227
225
            request.send_file(data_file)
228
226
    except caching.CacheError:
229
 
        request.emit_http_headers(["Status: 404 Not found"])
 
227
        request.status_code = 404
230
228
 
231
229
 
232
230
def _do_remove(request, key):
233
231
    """ delete headers/data cache for key """
234
232
    remove(request, key)
235
 
    request.emit_http_headers(["Status: 200 OK"])
236
233
 
237
234
 
238
235
def _do(request, do, key):
242
239
        _do_remove(request, key)
243
240
 
244
241
def execute(pagename, request):
245
 
    do = request.form.get('do', [None])[0]
246
 
    key = request.form.get('key', [None])[0]
 
242
    do = request.values.get('do')
 
243
    key = request.values.get('key')
247
244
    _do(request, do, key)
248
245