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

« back to all changes in this revision

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

  • Committer: drtomc
  • Date: 2007-12-13 23:22:04 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:52
Some incomplete changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from common import util
28
28
import conf
29
29
 
 
30
import functools
30
31
import mimetypes
31
32
import os
32
33
 
 
34
executable_types = {
 
35
    'text/x-python' : functools.partial(server.cgi.handler, '/usr/bin/python')
 
36
}
 
37
 
33
38
def handle(req):
34
39
    """Handler for the Server application which serves pages."""
35
40
 
36
 
    if req.path.endswith('.py'):
37
 
        raise Exception, "executing python not done yet!"
 
41
    mimetypes.init()
 
42
    (type, encoding) = mimetypes.guess_type(req.path)
 
43
 
 
44
    if type is None:
 
45
        type = 'text/plain'
 
46
 
 
47
    if type in executable_types:
 
48
        return executable_types[type](req)
38
49
 
39
50
    # We're expecting paths are all of the form <usr>/...
40
51
    parts = req.path.split(os.sep)
41
52
    if len(parts) == 0:
 
53
        # FIXME
42
54
        raise Exception, "empty path!"
43
55
 
44
56
    usr = parts[0]
45
57
 
46
 
    # The corresponding file on the filesystem
47
 
    path = os.path.join(conf.student_dir, usr, 'home', req.path)
48
 
 
49
 
    mimetypes.init()
50
 
    (type, encoding) = mimetypes.guess_type(path)
51
 
 
52
 
    if type == None:
53
 
        type = 'text/plain'
54
 
 
55
 
    # Set request attributes
56
58
    req.content_type = type
57
59
    if encoding != None:
58
60
        req.content_encoding = encoding
59
61
 
60
62
    req.write_html_head_foot = False
61
63
 
 
64
    path = os.path.join(conf.student_dir, usr, 'home', req.path)
 
65
 
62
66
    req.sendfile(path)