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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: Matt Giuca
  • Date: 2010-02-12 10:27:55 UTC
  • Revision ID: matt.giuca@gmail.com-20100212102755-ifsyo4qaqa2myvl5
docs: Added a new help page, Running and Serving.

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={}):
113
114
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
114
115
            throw_error('is-executable', {'path': filename})
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:
138
140
 
139
141
    print cjson.encode({'type': zip_mimetype,
140
142
                        'name': zipfilename})
141
 
    print zipfile.getvalue()
 
143
 
 
144
    stream = zipfile
 
145
    stream.seek(0)
142
146
else:
 
147
 
143
148
    print cjson.encode({'type': determine_file_type(filename),
144
149
                        'name': os.path.basename(filename)})
145
 
    print open(filename).read()
 
150
    stream = open(filename)
 
151
    
 
152
next = stream.read(1024)
 
153
while next:
 
154
    sys.stdout.write(next)
 
155
    next = stream.read(1024)