Created
August 20, 2012 23:09
-
-
Save naoyeye/3409064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
import mimetypes | |
class public: | |
def GET(self): | |
public_dir = 'public' | |
try: | |
file_name = web.ctx.path.split('/')[-1] | |
web.header('Content-type', mime_type(file_name)) | |
return open(public_dir + web.ctx.path, 'rb').read() | |
except IOError: | |
raise web.notfound() | |
def mime_type(filename): | |
return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment