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

« back to all changes in this revision

Viewing changes to src/apps/download/__init__.py

  • Committer: mattgiuca
  • Date: 2007-12-20 03:14:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:93
New directory hierarchy.
Renamed src to www.
Added console, trampoline (currently empty).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE
2
 
# Copyright (C) 2007-2008 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
# App: download
19
 
# Author: Matt Giuca
20
 
# Date: 17/12/2007
21
 
 
22
 
# Serves content to the user (acting as a web server for students files).
23
 
# Unlike "serve", all content is served as a static file, and with the
24
 
# application/octet-stream mime type.
25
 
# Also can serve directories or multiple files, automatically zipping them up.
26
 
 
27
 
from common import (util, studpath)
28
 
import conf
29
 
 
30
 
import functools
31
 
import os
32
 
import mimetypes
33
 
 
34
 
# TODO: Make it work on multiple files, zipping them up.
35
 
# TODO: Make it work on directories, zipping them up.
36
 
 
37
 
# Serve all files as application/octet-stream so the browser presents them as
38
 
# a download.
39
 
default_mimetype = "application/octet-stream"
40
 
 
41
 
def handle(req):
42
 
    """Handler for the Download application which serves files for
43
 
    download."""
44
 
 
45
 
    req.write_html_head_foot = False
46
 
 
47
 
    # Get the username of the student whose work we are browsing, and the path
48
 
    # on the local machine where the file is stored.
49
 
    (user, path) = studpath.url_to_local(req.path)
50
 
 
51
 
    if user is None:
52
 
        # TODO: Nicer 404 message?
53
 
        req.throw_error(req.HTTP_NOT_FOUND)
54
 
 
55
 
    req.content_type = default_mimetype
56
 
    req.sendfile(path)
57