##// END OF EJS Templates
remove unused import
Manuel Riel -
Show More
@@ -1,57 +1,51 b''
1 """Base Tornado handlers for the notebook server."""
1 """Base Tornado handlers for the notebook server."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import logging
6 import logging
7 import os
7 import os
8 import mimetypes
8 import mimetypes
9 import json
9 import json
10 import base64
10 import base64
11
11
12 try:
13 # py3
14 from http.client import responses
15 except ImportError:
16 from httplib import responses
17
18 from tornado import web
12 from tornado import web
19
13
20 try:
14 try:
21 from tornado.log import app_log
15 from tornado.log import app_log
22 except ImportError:
16 except ImportError:
23 app_log = logging.getLogger()
17 app_log = logging.getLogger()
24
18
25 from IPython.html.base.handlers import IPythonHandler
19 from IPython.html.base.handlers import IPythonHandler
26
20
27 class FilesHandler(IPythonHandler):
21 class FilesHandler(IPythonHandler):
28 """serve files via ContentsManager"""
22 """serve files via ContentsManager"""
29
23
30 @web.authenticated
24 @web.authenticated
31 def get(self, path):
25 def get(self, path):
32 cm = self.settings['contents_manager']
26 cm = self.settings['contents_manager']
33 if cm.is_hidden(path):
27 if cm.is_hidden(path):
34 self.log.info("Refusing to serve hidden file, via 404 Error")
28 self.log.info("Refusing to serve hidden file, via 404 Error")
35 raise web.HTTPError(404)
29 raise web.HTTPError(404)
36
30
37 path, name = os.path.split(path)
31 path, name = os.path.split(path)
38 model = cm.get_model(name, path)
32 model = cm.get_model(name, path)
39
33
40 if model['type'] == 'notebook':
34 if model['type'] == 'notebook':
41 self.set_header('Content-Type', 'application/json')
35 self.set_header('Content-Type', 'application/json')
42 else:
36 else:
43 cur_mime = mimetypes.guess_type(name)[0]
37 cur_mime = mimetypes.guess_type(name)[0]
44 if cur_mime is not None:
38 if cur_mime is not None:
45 self.set_header('Content-Type', cur_mime)
39 self.set_header('Content-Type', cur_mime)
46
40
47 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
41 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
48
42
49 if model['format'] == 'base64':
43 if model['format'] == 'base64':
50 b64_bytes = model['content'].encode('ascii')
44 b64_bytes = model['content'].encode('ascii')
51 self.write(base64.decodestring(b64_bytes))
45 self.write(base64.decodestring(b64_bytes))
52 elif model['format'] == 'json':
46 elif model['format'] == 'json':
53 self.write(json.dumps(model['content']))
47 self.write(json.dumps(model['content']))
54 else:
48 else:
55 self.write(model['content'])
49 self.write(model['content'])
56 self.flush()
50 self.flush()
57
51
General Comments 0
You need to be logged in to leave comments. Login now