Mercurial > hg > FileServer
comparison fileserver/web.py @ 20:1eb5e82605a5
* flush out README
* other minor fixes
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Wed, 29 Feb 2012 16:38:39 -0800 |
| parents | 27bd18f0a359 |
| children | eb15c8321ad8 |
comparison
equal
deleted
inserted
replaced
| 19:c6e459be8534 | 20:1eb5e82605a5 |
|---|---|
| 12 import os | 12 import os |
| 13 import sys | 13 import sys |
| 14 from webob import Request, Response, exc | 14 from webob import Request, Response, exc |
| 15 from wsgiref.simple_server import make_server | 15 from wsgiref.simple_server import make_server |
| 16 | 16 |
| 17 __all__ = ['get_mimetype', 'file_response', 'FileApp', 'DirectoryServer'] | 17 __all__ = ['get_mimetype', 'file_response', 'FileApp', 'DirectoryServer', 'main'] |
| 18 | 18 |
| 19 def get_mimetype(filename): | 19 def get_mimetype(filename): |
| 20 type, encoding = mimetypes.guess_type(filename) | 20 type, encoding = mimetypes.guess_type(filename) |
| 21 # We'll ignore encoding, even though we shouldn't really | 21 # We'll ignore encoding, even though we shouldn't really |
| 22 return type or 'application/octet-stream' | 22 return type or 'application/octet-stream' |
| 23 | 23 |
| 24 def file_response(filename): | 24 def file_response(filename): |
| 25 """return a webob response object appropriate to a file name""" | |
| 25 res = Response(content_type=get_mimetype(filename)) | 26 res = Response(content_type=get_mimetype(filename)) |
| 26 res.body = open(filename, 'rb').read() | 27 res.body = open(filename, 'rb').read() |
| 27 return res | 28 return res |
| 28 | 29 |
| 29 class FileApp(object): | 30 class FileApp(object): |
