/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-08-06 19:20:22 UTC
  • mfrom: (197.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 203.
  • Revision ID: argentina@gmail.com-20080806192022-em2ncft1wv1ldxpe
Misplaced fix syntax patch

Show diffs side-by-side

added added

removed removed

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