evennia.server.webserver

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)[源代码]

基类:twisted.python.threadpool.ThreadPool

Threadpool that can be locked from accepting new requests.

__init__(*args, **kwargs)[源代码]

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}

lock()[源代码]
callInThread(func, *args, **kwargs)[源代码]

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

class evennia.server.webserver.HTTPChannelWithXForwardedFor[源代码]

基类:twisted.web.http.HTTPChannel

HTTP xforward class

allHeadersReceived()[源代码]

Check to see if this is a reverse proxied connection.

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

基类:twisted.web.proxy.ReverseProxyResource

getChild(path, request)[源代码]

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(request)[源代码]

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)[源代码]

基类:twisted.web.resource.Resource

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

__init__(pool)[源代码]

Setup the django+twisted resource.

参数

pool (ThreadPool) – The twisted threadpool.

empty_threadpool()[源代码]

Converts our _pending_requests list of deferreds into a DeferredList

返回

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

getChild(path, request)[源代码]

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)[源代码]

基类:twisted.web.server.Site

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

noisy = False
logPrefix()[源代码]

How to be named in logs

log(request)[源代码]

Conditional logging

class evennia.server.webserver.WSGIWebServer(pool, *args, **kwargs)[源代码]

基类: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)[源代码]

This just stores the threadpool.

参数
  • pool (ThreadPool) – The twisted threadpool.

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

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

startService()[源代码]

Start the pool after the service starts.

stopService()[源代码]

Safely stop the pool after the service stops.

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

基类: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).

directoryListing()[源代码]

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}