socktools.webwrap - web.py WSGI wrapper¶
Often it makes sense to run an internal webserver for administration purposes, it also makes sense to use the existing implementation.
This module provides a simple wrapper around web.py inside eventlet. The wrapper is intended to be used inside of daemon processses but is useful in other places too.
-
class
socktools.webwrap.WebWrap(urls={}, physical_sock=None, listen_on=('0.0.0.0', 8080))[source]¶ Bases:
objectA light wrapper around web.py and eventlet.wsgi
This class is intended for providing a simple embedded webserver inside of daemon processes (or elsewhere).
After configuring URLs, simply run start_server() to start it up.
Warning
You must not use a physical socket from one of the socktools classes here.
Keyword Arguments: - urls (dict) – Map URL paths to URL handlers, see web.py documentation
- physical_sock (socket.socket) – If not None, the existing physical socket to listen on
- listen_on (tuple) – A tuple of (interface_ip,port) that the webserver should listen on
-
get_default_urls()[source]¶ Return the default URL mappings
Override this in your app. The default implementation returns a single URL for / which returns a bit of static text
Returns: a dict mapping web.py URLs to web.py URL handlers Return type: dict
-
get_url_map()[source]¶ Generates a URL map for this webserver
To integrate better with the rest of socktools, WebWrap offers a get_default_urls() method that returns a dict.
Unfortunately web.py requires a tuple, so this method generates that tuple.
Returns: the web.py compatible URL map Return type: tuple
-
socktools.webwrap.static_page(page_content, mime_type='text/html')[source]¶ Generate and return a URL handler for static content
This function uses a bit of metaprogramming black magic and returns a web.py URL handler for arbitrary static content
Returns: the URL handler Return type: object