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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: David Coles
  • Date: 2010-07-27 04:52:14 UTC
  • Revision ID: coles.david@gmail.com-20100727045214-p32h1kc0gcv48dpr
Worksheets: Strip off whitespace from the end of exercise attempts.

This solves an issue where accidental whitespace in an attempt will cause 
"IndentationError" syntax error (which don't occur when run in console).

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from ivle import zip as zipmod
31
31
import ivle.conf.app.server
 
32
import ivle.mimetypes
32
33
 
33
34
def determine_file_type(filename):
34
35
    filetype = mimetypes.guess_type(filename)[0]
35
36
    if filetype is None:
36
 
         filetype = ivle.conf.mimetypes.default_mimetype
 
37
         filetype = ivle.mimetypes.DEFAULT_MIMETYPE
37
38
    return filetype
38
39
 
39
40
def throw_error(message, extra={}):
111
112
    else:
112
113
        if not download and \
113
114
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
114
 
            throw_error('is-executable', {'path': filename})
 
115
            throw_error('is-executable', {'path': filename.decode('utf-8')})
115
116
 
116
117
        if not download and (
117
118
            (ivle.conf.app.server.blacklist_served_filetypes and \
138
139
    zipmod.make_zip(zipbasepath, paths, zipfile)
139
140
 
140
141
    print cjson.encode({'type': zip_mimetype,
141
 
                        'name': zipfilename})
 
142
                        'name': zipfilename.decode('utf-8')})
142
143
 
143
144
    stream = zipfile
144
145
    stream.seek(0)
145
146
else:
146
147
 
147
148
    print cjson.encode({'type': determine_file_type(filename),
148
 
                        'name': os.path.basename(filename)})
 
149
                        'name': os.path.basename(filename).decode('utf-8')})
149
150
    stream = open(filename)
150
151
    
151
152
next = stream.read(1024)