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

« back to all changes in this revision

Viewing changes to services/serveservice

Quick port of fileservice to the new framework. It's still very much old-style,
though.

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
33
32
 
34
33
def determine_file_type(filename):
35
34
    filetype = mimetypes.guess_type(filename)[0]
36
35
    if filetype is None:
37
 
         filetype = ivle.mimetypes.DEFAULT_MIMETYPE
 
36
         filetype = ivle.conf.mimetypes.default_mimetype
38
37
    return filetype
39
38
 
40
39
def throw_error(message, extra={}):
112
111
    else:
113
112
        if not download and \
114
113
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
115
 
            throw_error('is-executable', {'path': filename.decode('utf-8')})
 
114
            throw_error('is-executable', {'path': filename})
116
115
 
117
 
        if not download and (
118
 
            (ivle.conf.app.server.blacklist_served_filetypes and \
 
116
        if (ivle.conf.app.server.blacklist_served_filetypes and \
119
117
                determine_file_type(filename) in \
120
118
                ivle.conf.app.server.served_filetypes_blacklist) or \
121
119
            (ivle.conf.app.server.served_filetypes_whitelist and \
122
120
                determine_file_type(filename) not in \
123
 
                ivle.conf.app.server.served_filetypes_whitelist)):
 
121
                ivle.conf.app.server.served_filetypes_whitelist):
124
122
            throw_error('forbidden')
125
123
 
126
124
if zipmode:
139
137
    zipmod.make_zip(zipbasepath, paths, zipfile)
140
138
 
141
139
    print cjson.encode({'type': zip_mimetype,
142
 
                        'name': zipfilename.decode('utf-8')})
143
 
 
144
 
    stream = zipfile
145
 
    stream.seek(0)
 
140
                        'name': zipfilename})
 
141
    print zipfile.getvalue()
146
142
else:
147
 
 
148
143
    print cjson.encode({'type': determine_file_type(filename),
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)
 
144
                        'name': os.path.basename(filename)})
 
145
    print open(filename).read()