~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:52:48 UTC
  • mfrom: (1791.2.10 mediahandlers)
  • Revision ID: coles.david@gmail.com-20100728105248-zvbn9g72v1nsskvd
A series of HTML5 based media handlers using the <audio> and <video> tags.  
This replaces the previous page that just showed a download link (which is 
already available on the menu).

Also solves issue where media files were downloaded by the client twice (once 
in an AJAX request intended only for text).

Known issues:
    * Bug #588285: External BHO will not be able to play media due to not
      having IVLE cookie.
    * Bug #610745: Does not correctly preview revisions
    * Bug #610780: Ogg media does not work in Chromium

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
 
35
import ivle.mimetypes
32
36
 
33
37
def determine_file_type(filename):
34
38
    filetype = mimetypes.guess_type(filename)[0]
35
39
    if filetype is None:
36
 
         filetype = ivle.conf.mimetypes.default_mimetype
 
40
        filetype = ivle.mimetypes.DEFAULT_MIMETYPE
37
41
    return filetype
38
42
 
39
43
def throw_error(message, extra={}):
40
44
    error = {'error': message}
41
45
    error.update(extra)
42
 
    print cjson.encode(error)
 
46
    print json.dumps(error)
43
47
    sys.exit(0)
44
48
 
45
49
parser = OptionParser()
111
115
    else:
112
116
        if not download and \
113
117
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
114
 
            throw_error('is-executable', {'path': filename})
 
118
            throw_error('is-executable', {'path': filename.decode('utf-8')})
115
119
 
116
120
        if not download and (
117
121
            (ivle.conf.app.server.blacklist_served_filetypes and \
137
141
    zipfile = StringIO.StringIO()
138
142
    zipmod.make_zip(zipbasepath, paths, zipfile)
139
143
 
140
 
    print cjson.encode({'type': zip_mimetype,
141
 
                        'name': zipfilename})
 
144
    print json.dumps({'type': zip_mimetype,
 
145
                      'name': zipfilename.decode('utf-8'),
 
146
                      'size': len(zipfile.getvalue()),
 
147
                      })
142
148
 
143
149
    stream = zipfile
144
150
    stream.seek(0)
145
151
else:
146
152
 
147
 
    print cjson.encode({'type': determine_file_type(filename),
148
 
                        'name': os.path.basename(filename)})
 
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
                      })
149
157
    stream = open(filename)
150
 
    
 
158
 
151
159
next = stream.read(1024)
152
160
while next:
153
161
    sys.stdout.write(next)