diff options
-rw-r--r-- | fs/expose/wsgi/dirtemplate.py | 23 | ||||
-rw-r--r-- | fs/expose/wsgi/serve_home.py | 8 | ||||
-rw-r--r-- | fs/expose/wsgi/wsgi.py | 25 |
3 files changed, 33 insertions, 23 deletions
diff --git a/fs/expose/wsgi/dirtemplate.py b/fs/expose/wsgi/dirtemplate.py index 5845b49..c9ae4c4 100644 --- a/fs/expose/wsgi/dirtemplate.py +++ b/fs/expose/wsgi/dirtemplate.py @@ -6,15 +6,16 @@ template = """ <style type="text/css"> body { - font-family:Arial, Verdana; + font-family:Arial, Verdana; margin:0px; - padding:0px; + padding:0px; } table.dirlist { - margin:0 auto; + margin:0 auto; font-size:13px; color:#666; + min-width:960px; } table.dirlist tr.r1 { @@ -31,7 +32,7 @@ table.dirlist td a.link-dir { } table.dirlist td a { - text-decoration:none; + text-decoration:none; } table.dirlist td a:hover { @@ -57,20 +58,22 @@ table.dirlist tr:hover { <div class="dirlist-container"> <table class="dirlist"> - + + <thead> + <tr> + <th>File/Directory</th> + <th>Size</th> + <th>Created Date</th> + </tr> + </thead> <tbody> - % for i, entry in enumerate(dirlist): - <tr class="${entry['type']} r${i%2}"> - <td><a class="link-${entry['type']}" href="${ entry['path'] }">${entry['name']}</a></td> <td>${entry['size']}</td> <td>${entry['created_time']}</td> - </tr> % endfor - </tbody> </table> diff --git a/fs/expose/wsgi/serve_home.py b/fs/expose/wsgi/serve_home.py index c2e476a..17c5063 100644 --- a/fs/expose/wsgi/serve_home.py +++ b/fs/expose/wsgi/serve_home.py @@ -1,4 +1,10 @@ +from wsgiref.simple_server import make_server + from fs.osfs import OSFS from wsgi import serve_fs osfs = OSFS('~/') -application = serve_fs(osfs)
\ No newline at end of file +application = serve_fs(osfs) + +httpd = make_server('', 8000, application) +print "Serving on http://127.0.0.1:8000" +httpd.serve_forever() diff --git a/fs/expose/wsgi/wsgi.py b/fs/expose/wsgi/wsgi.py index 2a47e00..97e2553 100644 --- a/fs/expose/wsgi/wsgi.py +++ b/fs/expose/wsgi/wsgi.py @@ -62,22 +62,24 @@ class WSGIServer(object): serving_file.close() return self.serve_500(request, str(e)) - mime_type = mimetypes.guess_type(basename(path)) + mime_type = mimetypes.guess_type(basename(path))[0] or b'text/plain' file_size = self.serve_fs.getsize(path) - headers = [('Content-Type', mime_type), - ('Content-Length', str(file_size))] + headers = [(b'Content-Type', bytes(mime_type)), + (b'Content-Length', bytes(file_size))] def gen_file(): + chunk_size = self.chunk_size + read = serving_file.read try: - while True: - data = serving_file.read(self.chunk_size) + while 1: + data = read(chunk_size) if not data: break yield data finally: serving_file.close() - request.start_response('200 OK', + request.start_response(b'200 OK', headers) return gen_file() @@ -121,22 +123,21 @@ class WSGIServer(object): # Render the mako template html = self.dir_template.render(**dict(fs=self.serve_fs, path=path, - dirlist=entries)) - - request.start_response('200 OK', [('Content-Type', 'text/html'), - ('Content-Length', '%i' % len(html))]) + dirlist=entries)).encode('utf-8') + request.start_response(b'200 OK', [(b'Content-Type', b'text/html'), + (b'Content-Length', b'%i' % len(html))]) return [html] def serve_404(self, request, msg='Not found'): """Serves a Not found page""" - request.start_response('404 NOT FOUND', [('Content-Type', 'text/html')]) + request.start_response(b'404 NOT FOUND', [(b'Content-Type', b'text/html')]) return [msg] def serve_500(self, request, msg='Unable to complete request'): """Serves an internal server error page""" - request.start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')]) + request.start_response(b'500 INTERNAL SERVER ERROR', [(b'Content-Type', b'text/html')]) return [msg] |