~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-08-06 21:25:24 UTC
  • Revision ID: argentina@gmail.com-20080806212524-nc3m9mfg1yub7z3c
Don't traceback if we can't get last-changed date from a branch. Bug #254794

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import logging
21
21
import mimetypes
22
22
import time
23
 
import urllib
24
23
 
25
24
from paste import httpexceptions
26
25
from paste.request import path_info_pop
27
26
 
28
 
from loggerhead.controllers import TemplatedBranchView
29
 
 
30
27
log = logging.getLogger("loggerhead.controllers")
31
28
 
32
29
 
33
 
class DownloadUI (TemplatedBranchView):
 
30
class DownloadUI (object):
 
31
 
 
32
    def __init__(self, branch, history):
 
33
        self._branch = branch
 
34
        self._history = history
 
35
        self.log = branch.log
34
36
 
35
37
    def __call__(self, environ, start_response):
36
38
        # /download/<rev_id>/<file_id>/[filename]
46
48
            args.append(arg)
47
49
 
48
50
        if len(args) < 2:
49
 
            raise httpexceptions.HTTPMovedPermanently(self._branch.url(
50
 
                      '../changes'))
 
51
            raise httpexceptions.HTTPMovedPermanently(self._branch.url('../changes'))
51
52
 
52
53
        revid = h.fix_revid(args[0])
53
54
        file_id = args[1]
56
57
        if mime_type is None:
57
58
            mime_type = 'application/octet-stream'
58
59
 
59
 
        self.log.info('/download %s @ %s (%d bytes)',
60
 
                      path,
61
 
                      h.get_revno(revid),
62
 
                      len(content))
63
 
        encoded_filename = urllib.quote(filename.encode('utf-8'))
 
60
        self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
64
61
        headers = [
65
62
            ('Content-Type', mime_type),
66
63
            ('Content-Length', len(content)),
67
 
            ('Content-Disposition',
68
 
             'attachment; filename*=utf-8\'\'%s' % encoded_filename),
 
64
            ('Content-Disposition', 'attachment; filename=%s'%(filename,)),
69
65
            ]
70
66
        start_response('200 OK', headers)
71
67
        return [content]