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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2007-12-13 03:26:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:50
conf/apps.py: Added "server" app.
apps/server: Some minor fixes for robustness. Also now looks in student_dir
instead of root_dir + '/jails'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
# App: dummy
19
 
# Author: Matt Giuca
20
 
# Date: 12/12/2007
 
18
# App: server
 
19
# Author: Tom Conway
 
20
# Date: 13/12/2007
21
21
 
22
 
# This is an IVLE application.
23
 
# A sample / testing application for IVLE.
 
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.
24
26
 
25
27
from common import util
26
 
from conf
 
28
import conf
27
29
 
28
30
import mimetypes
 
31
import os
29
32
 
30
33
def handle(req):
31
 
    """Handler for the Server application which serves pages.
32
 
       For most file types we just serve the static file, but
33
 
       for python files, we evaluate the python script inside
34
 
       our safe execution environment."""
 
34
    """Handler for the Server application which serves pages."""
35
35
 
36
36
    if req.path.endswith('.py'):
37
37
        raise Exception, "executing python not done yet!"
38
38
 
39
39
    # We're expecting paths are all of the form <usr>/...
40
 
    parts = req.path.split('/')
 
40
    parts = req.path.split(os.sep)
41
41
    if len(parts) == 0:
42
42
        raise Exception, "empty path!"
43
43
 
44
44
    usr = parts[0]
45
45
 
46
46
    # The corresponding file on the filesystem
47
 
    path = conf.root_dir + '/jails/' + user + '/home/' + req.path
 
47
    path = os.path.join(conf.student_dir, usr, 'home', req.path)
48
48
 
49
49
    mimetypes.init()
50
50
    (type, encoding) = mimetypes.guess_type(path)
51
51
 
52
 
    if type is None:
 
52
    if type == None:
53
53
        type = 'text/plain'
54
54
 
55
55
    # Set request attributes
56
56
    req.content_type = type
57
 
    if encoding is not None:
 
57
    if encoding != None:
58
58
        req.content_encoding = encoding
59
59
 
60
60
    req.write_html_head_foot = False