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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

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
43
40
def throw_error(message, extra={}):
44
41
    error = {'error': message}
45
42
    error.update(extra)
46
 
    print json.dumps(error)
 
43
    print cjson.encode(error)
47
44
    sys.exit(0)
48
45
 
49
46
parser = OptionParser()
115
112
    else:
116
113
        if not download and \
117
114
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
118
 
            throw_error('is-executable', {'path': filename.decode('utf-8')})
 
115
            throw_error('is-executable', {'path': filename})
119
116
 
120
117
        if not download and (
121
118
            (ivle.conf.app.server.blacklist_served_filetypes and \
141
138
    zipfile = StringIO.StringIO()
142
139
    zipmod.make_zip(zipbasepath, paths, zipfile)
143
140
 
144
 
    print json.dumps({'type': zip_mimetype,
145
 
                      'name': zipfilename.decode('utf-8')})
 
141
    print cjson.encode({'type': zip_mimetype,
 
142
                        'name': zipfilename})
146
143
 
147
144
    stream = zipfile
148
145
    stream.seek(0)
149
146
else:
150
147
 
151
 
    print json.dumps({'type': determine_file_type(filename),
152
 
                      'name': os.path.basename(filename).decode('utf-8')})
 
148
    print cjson.encode({'type': determine_file_type(filename),
 
149
                        'name': os.path.basename(filename)})
153
150
    stream = open(filename)
154
 
 
 
151
    
155
152
next = stream.read(1024)
156
153
while next:
157
154
    sys.stdout.write(next)