Reputation: 8636
can anyone advice the best way to share Python package resource files with Twisted web server?
Package built using setuptools.
from pkg_resources import resource_listdir
from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor
resource = File('/blah') # !! Wanna ask File use resource_listdir
factory = Site(resource)
reactor.listenTCP(8888, factory)
reactor.run()
Upvotes: 0
Views: 194
Reputation: 48335
You can override listNames
on File
to control directory listings.
For example,
packageName = "..."
class PkgResourcesFile(File):
def listNames(self):
return resource_listdir(packageName, self.path)
resource = PkgResourcesFile(...)
Upvotes: 1