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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: William Grant
  • Date: 2010-07-28 04:12:08 UTC
  • mfrom: (1790.1.8 codemirror-srsly)
  • Revision ID: grantw@unimelb.edu.au-20100728041208-mciagtog1785oje4
Move from CodePress to CodeMirror. It's now an external dependency, too, so you'll need to install it yourself.

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
 
        if (ivle.conf.app.server.blacklist_served_filetypes and \
 
117
        if not download and (
 
118
            (ivle.conf.app.server.blacklist_served_filetypes and \
117
119
                determine_file_type(filename) in \
118
120
                ivle.conf.app.server.served_filetypes_blacklist) or \
119
121
            (ivle.conf.app.server.served_filetypes_whitelist and \
120
122
                determine_file_type(filename) not in \
121
 
                ivle.conf.app.server.served_filetypes_whitelist):
 
123
                ivle.conf.app.server.served_filetypes_whitelist)):
122
124
            throw_error('forbidden')
123
125
 
124
126
if zipmode:
137
139
    zipmod.make_zip(zipbasepath, paths, zipfile)
138
140
 
139
141
    print cjson.encode({'type': zip_mimetype,
140
 
                        'name': zipfilename})
141
 
    print zipfile.getvalue()
 
142
                        'name': zipfilename.decode('utf-8')})
 
143
 
 
144
    stream = zipfile
 
145
    stream.seek(0)
142
146
else:
 
147
 
143
148
    print cjson.encode({'type': determine_file_type(filename),
144
 
                        'name': os.path.basename(filename)})
145
 
    print open(filename).read()
 
149
                        'name': os.path.basename(filename).decode('utf-8')})
 
150
    stream = open(filename)
 
151
    
 
152
next = stream.read(1024)
 
153
while next:
 
154
    sys.stdout.write(next)
 
155
    next = stream.read(1024)