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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: David Coles
  • Date: 2010-07-28 10:45:53 UTC
  • mfrom: (1829 trunk)
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: coles.david@gmail.com-20100728104553-5z3nxt0l6kyfqfh5
MergeĀ fromĀ trunk

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
 
import cjson
 
28
try:
 
29
    import json
 
30
except ImportError:
 
31
    import simplejson as json
29
32
 
30
33
from ivle import zip as zipmod
31
34
import ivle.conf.app.server
40
43
def throw_error(message, extra={}):
41
44
    error = {'error': message}
42
45
    error.update(extra)
43
 
    print cjson.encode(error)
 
46
    print json.dumps(error)
44
47
    sys.exit(0)
45
48
 
46
49
parser = OptionParser()
138
141
    zipfile = StringIO.StringIO()
139
142
    zipmod.make_zip(zipbasepath, paths, zipfile)
140
143
 
141
 
    print cjson.encode({'type': zip_mimetype,
142
 
                        'name': zipfilename.decode('utf-8'),
143
 
                        'size': len(zipfile.getvalue()),
144
 
                        })
 
144
    print json.dumps({'type': zip_mimetype,
 
145
                      'name': zipfilename.decode('utf-8'),
 
146
                      'size': len(zipfile.getvalue()),
 
147
                      })
145
148
 
146
149
    stream = zipfile
147
150
    stream.seek(0)
148
151
else:
149
152
 
150
 
    print cjson.encode({
151
 
                        'type': determine_file_type(filename),
152
 
                        'name': os.path.basename(filename).decode('utf-8'),
153
 
                        'size': os.path.getsize(filename),
154
 
                        })
 
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
                      })
155
157
    stream = open(filename)
156
 
    
 
158
 
157
159
next = stream.read(1024)
158
160
while next:
159
161
    sys.stdout.write(next)