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

« back to all changes in this revision

Viewing changes to lib/common/interpret.py

  • Committer: mattgiuca
  • Date: 2008-03-15 09:00:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:703
tutorial: (Python + Javascript)
    Added JS function "set_saved_status", which can activate and deactivate
    the save button.
    Modifying the text field now creates a Save timer which takes 10 seconds
    to elapse, then auto-saves the field.
    The save button is only enabled if the text has been modified since
    saving.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# This can be resolved but needs careful sanitisation. See fixup_environ.
29
29
 
30
30
from common import studpath
 
31
from common import db
31
32
import conf
32
33
import functools
33
34
 
42
43
 
43
44
CGI_BLOCK_SIZE = 65535
44
45
 
 
46
uids = {}
 
47
 
 
48
def get_uid(login):
 
49
    """Get the unix uid corresponding to the given login name.
 
50
       If it is not in the dictionary of uids, then consult the
 
51
       database and retrieve an update of the user table."""
 
52
    global uids
 
53
    if login in uids:
 
54
        return uids[login]
 
55
 
 
56
    conn = db.DB()
 
57
    res = conn.get_all('login', ['login', 'unixid'])
 
58
    def repack(flds):
 
59
        return (flds['login'], flds['unixid'])
 
60
    uids = dict(map(repack,res))
 
61
 
 
62
    return uids[login]
 
63
 
45
64
def interpret_file(req, owner, jail_dir, filename, interpreter):
46
65
    """Serves a file by interpreting it using one of IVLE's builtin
47
66
    interpreters. All interpreters are intended to run in the user's jail. The
54
73
    filename: Absolute filename within the user's jail.
55
74
    interpreter: A function object to call.
56
75
    """
57
 
    # Make sure the file exists (otherwise some interpreters may not actually
58
 
    # complain).
59
 
    # Don't test for execute permission, that will only be required for
60
 
    # certain interpreters.
 
76
    # We can't test here whether or not the target file actually exists,
 
77
    # because the apache user may not have permission. Instead we have to
 
78
    # rely on the interpreter generating an error.
61
79
    if filename.startswith(os.sep):
62
80
        filename_abs = filename
63
81
        filename_rel = filename[1:]
65
83
        filename_abs = os.path.join(os.sep, filename)
66
84
        filename_rel = filename
67
85
 
68
 
    if not os.access(os.path.join(jail_dir, filename_rel), os.R_OK):
69
 
        req.throw_error(req.HTTP_NOT_FOUND)
70
 
 
71
86
    # Get the UID of the owner of the file
72
87
    # (Note: files are executed by their owners, not the logged in user.
73
88
    # This ensures users are responsible for their own programs and also
74
89
    # allows them to be executed by the public).
75
 
    uid = req.user.unixid
 
90
    uid = get_uid(owner)
76
91
 
77
92
    # Split up req.path again, this time with respect to the jail
78
93
    (working_dir, _) = os.path.split(filename_abs)