Last active
December 27, 2015 06:49
-
-
Save aausch/7284664 to your computer and use it in GitHub Desktop.
Serves static files from multiple local directories at a single external url
This file contains hidden or 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
# Serves static files from multiple local directories at a single external url | |
# usage demo: https://gist.github.com/aausch/7348230 | |
# | |
# Copyright 2013, Alex Ausch | |
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/ | |
from twisted.web.resource import Resource | |
from twisted.web.static import File | |
class StaticFileScanner(Resource): | |
dirs = [] | |
def __init__(self, *dirs): | |
if (len(dirs) < 1): | |
self.dirs = [File()] | |
else: | |
self.dirs = [File(d) for d in dirs] | |
Resource.__init__(self) | |
def getChild(self, *args): | |
for d in self.dirs: | |
if d.getChild(*args) != d.childNotFound: | |
return d.getChild(*args) | |
return self.dirs[0].childNotFound | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment