grapes
grapes

Reputation: 8636

Using Twisted static web server for sharing python resource files

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

Answers (1)

Jean-Paul Calderone
Jean-Paul Calderone

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

Related Questions