~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/fileservice/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-09 23:35:09 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:147
conf: Moved "default_mimetype" configuration constant from conf/app/server.py
        to conf/mimetypes.py. (Used by fileservice now too, so general).
fileservice: Now guesses mimetype of files being served instead of serving
    them all with the same mimetype.
    The Content-Type returned will be used by file browser for viewing certain
    types of files.
server: Fixed directory problem (previously served with just a "0"). Now
    directories return a 403 Forbidden error. (Not allowed to browse
    directories since this is viewable by the public).

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
import os
83
83
import stat
84
84
import time
 
85
import mimetypes
85
86
 
86
87
import cjson
87
88
import pysvn
88
89
 
89
90
from common import (util, studpath)
 
91
import conf.mimetypes
90
92
 
91
93
DEFAULT_LOGMESSAGE = "No log message supplied."
92
94
 
98
100
# debugging because Firefox just tries to download it
99
101
mime_dirlisting = "text/plain"
100
102
#mime_dirlisting = "application/json"
101
 
mime_filedump = "text/plain"
102
103
 
103
104
def handle(req):
104
105
    """Handler for the File Services application."""
178
179
        req.write(cjson.encode(list))
179
180
    else:
180
181
        # It's a file. Return the file contents.
181
 
        req.content_type = mime_filedump
 
182
        # First get the mime type of this file
 
183
        # (Note that importing common.util has already initialised mime types)
 
184
        (type, _) = mimetypes.guess_type(path)
 
185
        if type is not None:
 
186
            req.content_type = type
 
187
        else:
 
188
            req.content_type = conf.mimetypes.default_mimetype
182
189
        req.headers_out['X-IVLE-Return'] = 'File'
183
190
 
184
191
        req.sendfile(path)