Skip to content

Instantly share code, notes, and snippets.

@aausch
Last active December 27, 2015 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aausch/7284664 to your computer and use it in GitHub Desktop.
Save aausch/7284664 to your computer and use it in GitHub Desktop.
Serves static files from multiple local directories at a single external url
# 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