~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

  • Committer: Robey Pointer
  • Date: 2007-05-21 07:46:30 UTC
  • Revision ID: robey@lag.net-20070521074630-afkk5g3x2654wfpm
bug 113313: remove 0x0C (page break) from the list of characters that
identify a file as binary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
 
20
import datetime
20
21
import logging
21
22
import mimetypes
 
23
import os
 
24
import posixpath
 
25
import textwrap
22
26
import time
23
27
 
24
 
from paste import httpexceptions
25
 
from paste.request import path_info_pop
 
28
import turbogears
 
29
from cherrypy import HTTPRedirect, response, session
 
30
 
 
31
from loggerhead import util
 
32
 
26
33
 
27
34
log = logging.getLogger("loggerhead.controllers")
28
35
 
29
36
 
30
37
class DownloadUI (object):
31
38
 
32
 
    def __init__(self, branch, history):
 
39
    def __init__(self, branch):
 
40
        # BranchView object
33
41
        self._branch = branch
34
 
        self._history = history
35
42
        self.log = branch.log
36
43
 
37
 
    def __call__(self, environ, start_response):
 
44
    @turbogears.expose()
 
45
    def default(self, *args, **kw):
38
46
        # /download/<rev_id>/<file_id>/[filename]
39
47
        z = time.time()
40
 
 
41
 
        h = self._history
42
 
 
43
 
        args = []
44
 
        while 1:
45
 
            arg = path_info_pop(environ)
46
 
            if arg is None:
47
 
                break
48
 
            args.append(arg)
49
 
 
 
48
        h = self._branch.get_history()
 
49
        
50
50
        if len(args) < 2:
51
 
            raise httpexceptions.HTTPMovedPermanently(self._branch.url('../changes'))
52
 
 
 
51
            raise HTTPRedirect(self._branch.url('/changes'))
 
52
        
53
53
        revid = h.fix_revid(args[0])
54
54
        file_id = args[1]
55
55
        path, filename, content = h.get_file(file_id, revid)
58
58
            mime_type = 'application/octet-stream'
59
59
 
60
60
        self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
61
 
        headers = [
62
 
            ('Content-Type', mime_type),
63
 
            ('Content-Length', len(content)),
64
 
            ('Content-Disposition', 'attachment; filename=%s'%(filename,)),
65
 
            ]
66
 
        start_response('200 OK', headers)
67
 
        return [content]
 
61
        response.headers['Content-Type'] = mime_type
 
62
        response.headers['Content-Length'] = len(content)
 
63
        response.body = content
 
64
        return response.body