This implements resources for Twisted webservers using the WSGI interface of Django. This alleviates the need of running e.g. an Apache server to serve Evennia’s web presence (although you could do that too if desired).

The actual servers are started inside server.py as part of the Evennia application.

(Lots of thanks to http://github.com/clemesha/twisted-wsgi-django for a great example/aid on how to do this.)

class evennia.server.webserver.LockableThreadPool(*args, **kwargs)[source]

Bases: twisted.python.threadpool.ThreadPool

Threadpool that can be locked from accepting new requests.

__init__(*args, **kwargs)[source]

Create a new threadpool.

@param minthreads: minimum number of threads in the pool @type minthreads: L{int}

@param maxthreads: maximum number of threads in the pool @type maxthreads: L{int}

@param name: The name to give this threadpool; visible in log messages. @type name: native L{str}

callInThread(func, *args, **kwargs)[source]

called in the main reactor thread. Makes sure the pool is not locked before continuing.

class evennia.server.webserver.HTTPChannelWithXForwardedFor[source]

Bases: twisted.web.http.HTTPChannel

HTTP xforward class


Check to see if this is a reverse proxied connection.

class evennia.server.webserver.EvenniaReverseProxyResource(host, port, path, reactor=<twisted.internet.epollreactor.EPollReactor object>)[source]

Bases: twisted.web.proxy.ReverseProxyResource

getChild(path, request)[source]

Create and return a proxy resource with the same proxy configuration as this one, except that its path also contains the segment given by path at the end.

  • path (str) – Url path.

  • request (Request object) – Incoming request.


resource (EvenniaReverseProxyResource) – A proxy resource.


Render a request by forwarding it to the proxied server.


request (Request) – Incoming request.


not_done (char) – Indicator to note request not yet finished.

class evennia.server.webserver.DjangoWebRoot(pool)[source]

Bases: twisted.web.resource.Resource

This creates a web root (/) that Django understands by tweaking the way child instances are recognized.


Setup the django+twisted resource.


pool (ThreadPool) – The twisted threadpool.


Converts our _pending_requests list of deferreds into a DeferredList


deflist (DeferredList) – Contains all deferreds of pending requests.

getChild(path, request)[source]

To make things work we nudge the url tree to make this the root.

  • path (str) – Url path.

  • request (Request object) – Incoming request.


We make sure to save the request queue so that we can safely kill the threadpool on a server reload.

class evennia.server.webserver.Website(resource, requestFactory=None, *args, **kwargs)[source]

Bases: twisted.web.server.Site

This class will only log http requests if settings.DEBUG is True.

noisy = False

How to be named in logs


Conditional logging

class evennia.server.webserver.WSGIWebServer(pool, *args, **kwargs)[source]

Bases: twisted.application.internet.TCPServer

This is a WSGI webserver. It makes sure to start the threadpool after the service itself started, so as to register correctly with the twisted daemon.

call with WSGIWebServer(threadpool, port, wsgi_resource)

__init__(pool, *args, **kwargs)[source]

This just stores the threadpool.

  • pool (ThreadPool) – The twisted threadpool.

  • args (any) – Passed on to the TCPServer.

  • kwargs (any) – Passed on to the TCPServer.


Start the pool after the service starts.


Safely stop the pool after the service stops.

class evennia.server.webserver.PrivateStaticRoot(path: str, defaultType: str = 'text/html', ignoredExts: Sequence[str] = (), registry: Optional[twisted.web.static.Registry, None] = None, allowExt: Literal[0] = 0)[source]

Bases: twisted.web.static.File

This overrides the default static file resource so as to not make the directory listings public (that is, if you go to /media or /static you won’t see an index of all static/media files on the server).


Return a resource that generates an HTML listing of the directory this path represents.

@return: A resource that renders the directory to HTML. @rtype: L{DirectoryLister}