48
by drtomc
Add the beginnings of the app for serving students' pages. |
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 |
||
50
by mattgiuca
conf/apps.py: Added "server" app. |
18 |
# App: server
|
19 |
# Author: Tom Conway
|
|
20 |
# Date: 13/12/2007
|
|
48
by drtomc
Add the beginnings of the app for serving students' pages. |
21 |
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
22 |
# Serves content to the user (acting as a web server for students files).
|
23 |
# For most file types we just serve the static file, but
|
|
24 |
# for python files, we evaluate the python script inside
|
|
25 |
# our safe execution environment.
|
|
48
by drtomc
Add the beginnings of the app for serving students' pages. |
26 |
|
27 |
from common import util |
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
28 |
import conf |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
29 |
|
30 |
import mimetypes |
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
31 |
import os |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
32 |
|
33 |
def handle(req): |
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
34 |
"""Handler for the Server application which serves pages."""
|
48
by drtomc
Add the beginnings of the app for serving students' pages. |
35 |
|
36 |
if req.path.endswith('.py'): |
|
37 |
raise Exception, "executing python not done yet!" |
|
38 |
||
39 |
# We're expecting paths are all of the form <usr>/...
|
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
40 |
parts = req.path.split(os.sep) |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
41 |
if len(parts) == 0: |
42 |
raise Exception, "empty path!" |
|
43 |
||
44 |
usr = parts[0] |
|
45 |
||
46 |
# The corresponding file on the filesystem
|
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
47 |
path = os.path.join(conf.student_dir, usr, 'home', req.path) |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
48 |
|
49 |
mimetypes.init() |
|
50 |
(type, encoding) = mimetypes.guess_type(path) |
|
51 |
||
50
by mattgiuca
conf/apps.py: Added "server" app. |
52 |
if type == None: |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
53 |
type = 'text/plain' |
54 |
||
55 |
# Set request attributes
|
|
56 |
req.content_type = type |
|
50
by mattgiuca
conf/apps.py: Added "server" app. |
57 |
if encoding != None: |
48
by drtomc
Add the beginnings of the app for serving students' pages. |
58 |
req.content_encoding = encoding |
59 |
||
60 |
req.write_html_head_foot = False |
|
61 |
||
62 |
req.sendfile(path) |