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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: Matt Giuca
  • Date: 2009-02-24 04:44:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1119.
  • Revision ID: matt.giuca@gmail.com-20090224044400-m9mm2ngpt2d2jyv0
title.svg: Changed background colour to blue (for testing purposes)
    - this is the same as the actual background of the site.
    And moved the letters "IVLE" so they are evenly distributed, and appear
    behind the words they stand for.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import StringIO
26
26
from optparse import OptionParser
27
27
 
28
 
try:
29
 
    import json
30
 
except ImportError:
31
 
    import simplejson as json
 
28
import cjson
32
29
 
33
30
from ivle import zip as zipmod
34
31
import ivle.conf.app.server
35
 
import ivle.mimetypes
36
32
 
37
33
def determine_file_type(filename):
38
34
    filetype = mimetypes.guess_type(filename)[0]
39
35
    if filetype is None:
40
 
        filetype = ivle.mimetypes.DEFAULT_MIMETYPE
 
36
         filetype = ivle.conf.mimetypes.default_mimetype
41
37
    return filetype
42
38
 
43
39
def throw_error(message, extra={}):
44
40
    error = {'error': message}
45
41
    error.update(extra)
46
 
    print json.dumps(error)
 
42
    print cjson.encode(error)
47
43
    sys.exit(0)
48
44
 
49
45
parser = OptionParser()
115
111
    else:
116
112
        if not download and \
117
113
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
118
 
            throw_error('is-executable', {'path': filename.decode('utf-8')})
 
114
            throw_error('is-executable', {'path': filename})
119
115
 
120
 
        if not download and (
121
 
            (ivle.conf.app.server.blacklist_served_filetypes and \
 
116
        if (ivle.conf.app.server.blacklist_served_filetypes and \
122
117
                determine_file_type(filename) in \
123
118
                ivle.conf.app.server.served_filetypes_blacklist) or \
124
119
            (ivle.conf.app.server.served_filetypes_whitelist and \
125
120
                determine_file_type(filename) not in \
126
 
                ivle.conf.app.server.served_filetypes_whitelist)):
 
121
                ivle.conf.app.server.served_filetypes_whitelist):
127
122
            throw_error('forbidden')
128
123
 
129
124
if zipmode:
141
136
    zipfile = StringIO.StringIO()
142
137
    zipmod.make_zip(zipbasepath, paths, zipfile)
143
138
 
144
 
    print json.dumps({'type': zip_mimetype,
145
 
                      'name': zipfilename.decode('utf-8'),
146
 
                      'size': len(zipfile.getvalue()),
147
 
                      })
148
 
 
149
 
    stream = zipfile
150
 
    stream.seek(0)
 
139
    print cjson.encode({'type': zip_mimetype,
 
140
                        'name': zipfilename})
 
141
    print zipfile.getvalue()
151
142
else:
152
 
 
153
 
    print json.dumps({'type': determine_file_type(filename),
154
 
                      'name': os.path.basename(filename).decode('utf-8'),
155
 
                      'size': os.path.getsize(filename),
156
 
                      })
157
 
    stream = open(filename)
158
 
 
159
 
next = stream.read(1024)
160
 
while next:
161
 
    sys.stdout.write(next)
162
 
    next = stream.read(1024)
 
143
    print cjson.encode({'type': determine_file_type(filename),
 
144
                        'name': os.path.basename(filename)})
 
145
    print open(filename).read()