TiddlyWeb web routines.
The routines, modules, etc that are involved in the presentation and handling of content over the web.
This is the part that makes it Tiddly_Web, not Tiddly something else.
WSGI App for running the base challenge system, which lists and links the available challengers. If there is only one, redirect to it.
The basic listing page that shows all available challenger systems. If there is only one, we redirect to that instead of listing.
Dispatch a GET request to the chosen challenger.
Dispatch a POST request to the chosen challenger.
A place for handling the extraction of user credentials from incoming requests. UserExtract passes to a stack of extractors. If an extractor returns something other than None, we have found valid data with which to set tiddlyweb.usersign.
Bases: object
WSGI Middleware to set the User, if it can be found in the request.
Common code used for listing bags and recipes.
Get a list of all the bags or recipes the current user can read.
WSGI Middleware to do pseudo-content negotiation and put the type in tiddlyweb.type. If extensions are provided on a GET URI that match extension_types, they win over the Accept header.
Bases: object
Perform a form of content negotiation to provide information to the environment that will later be used to choose serializers.
Determine either the content-type (for POST, PUT, DELETE) or accept header (for GET) and put that information in tiddlyweb.type in the environment.
WSGI Middleware that extracts CGI parameters from the QUERY_STRING and puts them in tiddlyweb.query in the same structure that cgi.py users (dictionary of lists). If the current request is a POST of form data, parse that stuff too.
Send a bag or recipe out HTTP, first serializing to the correct type. This consolidates common code for bags and recipes.
Send a bag or recipe out HTTP, first serializing to the correct type. If the incoming etag matches, raise 304.
Routines related to sending a list of tiddlers out to the web, including filter those tiddlers and validating request cache headers.
Output the tiddlers contained in the provided Tiddlers collection in a Negotiated representation. Often, but not always, a wiki.
Functions and Classes for running a TiddlyWeb server, including optionally a built in web server.
Bases: object
WSGI middleware to handle setting a config dict for every request.
Bases: object
WSGI middleware that logs basic request information and cleans PATH_INFO in the environment.
Clean PATH_INFO in the environment.
This is necessary because WSGI servers tend to decode the URI before putting it in PATH_INFO. This means that uri encoded data, such as the %2F encoding of / will be decoded before we get to route dispatch handling, by which time the / is treated as a separator. People say that the right thing to do here is not use %2F. This is hogwash. The right thing to do is not decode PATH_INFO. In this solution if REQUEST_URI is present we use a portion of it to set PATH_INFO.
Create our application from a series of layers. The innermost layer is a selector application based on urls_map in config. This is surround by wrappers, which either set something in the environment, modify the request, or transform output.
Start a simple webserver to run our app.
General utility routines shared by various web related modules.
Construct an etag for a bag.
Construct a URL for a bag.
Check to see if the bag allows the current user to perform the requested action. Lets NoBagError raise.
This is a web util because user and store come from environ.
Raise 304 if the provided etag is the same as that found in the If-None-Match header of the incoming request.
Return incoming_etag to indicate that an etag was there but did not match.
Raise HTTP304 if If-Modified-Since header matches last_modified_string
To PUT or POST we must have content-length and content-type headers. Raise 400 if we cannot get these things.
Turn an HTTP formatted date into a datetime object. Returns None if date string is invalid.
Encode a unicode as utf-8 and then url encode that string. Use for entity titles in URLs.
Construct an etag from the JSON rep of an entity.
escape common character entities, incuding double quotes in attribute values
This assumes values are enclosed in double quotes (key=”value”).
Retrieve and decode from UTF-8 data provided in WSGI route.
If name is not present in the route, allow KeyError to raise.
If the provided data is not URI escaped UTF-8, raise an HTTP400
Look in the environ to determine which serializer we should use for this request.
If collection is True, then the presence of an extension which does not match any serializer should lead to a 415.
Look for an extension on the provided resource_name and trim it off to give the “real” resource_name.
Encode &, < and > entities in text that will be used in/as HTML.
Return the header and footer from the current HTML serialization.
Turn a modifier or created tiddler timestamp into a proper formatted HTTP date. If the timestamp is invalid use now as the timestamp.
Create a cookie string, optionally with a MAC, path and expires value. Expires is in seconds.
Read the wsgi.input representing the request body. Length is required because it is tested for existence earlier in the process so we don’t want to bother recalculating.
Construct an etag for a recipe.
Construct a URL for a recipe.
Using information in tiddlyweb.config, construct the base URL of the server, sans the trailing /.
Generate the scheme and host portion of our server url.
Construct an etag for a tiddler from the tiddler’s attributes, but not its text.
Construct a URL for a tiddler.
A collection of routines for validating, santizing and otherwise messing with content coming in from the web to be tiddlers, bags or recipes.
The validators can be extended by adding functions to the BAG_VALIDATORS, RECIPE_VALIDATORS and TIDDLER_VALIDATORS. The functions take an entity object, and an optional environ dict.
Bases: exceptions.Exception
The provided bag has not passed a validation routine and has been rejected. The caller should stop processing and return an error to calling code or user-agent.
Bases: exceptions.Exception
The provided recipe has not passed a validation routine and has been rejected. The caller should stop processing and return an error to calling code or user-agent.
Bases: exceptions.Exception
The provided tiddler has not passed a validation routine and has been rejected. The caller should stop processing and return an error to calling code or user-agent.
Strip any bad HTML which may be present in a bag or recipe description.
Santize an html fragment, returning a copy of the fragment, cleaned up.
Pass the bag to each of the functions in BAG_VALIDATORS, in order, either changing the content of the bags’s attributes, or if some aspect of the bag can not be accepted raising InvalidBagError.
BAG_VALIDATORS is an empty list which should be extended by TiddlyWeb administrators.
validate_bag is called whenever a bag is PUT via the web.
Pass the recipe to each of the functions in RECIPE_VALIDATORS, in order, either changing the content of the recipes’s attributes, or if some aspect of the recipe can not be accepted raising InvalidRecipeError.
RECIPE_VALIDATORS is an empty list which should be extended by TiddlyWeb administrators.
validate_recipe is called whenever a recipe is PUT via the web.
Pass the tiddler to each of the functions in TIDDLER_VALIDATORS, in order, either changing the content of the tiddler’s attributes, or if some aspect of the tiddler can not be accepted raising InvalidTiddlerError.
TIDDLER_VALIDATORS is an empty list which should be extended by TiddlyWeb administrators.
validate_tiddler is called from web handlers, when the the accept constraint on the bag containing the tiddler does not pass.
WSGI Middleware apps that haven’t gotten around to being extracted to their own modules.
Bases: object
WSGI Middleware to ensure that the content we send out the pipe is encoded as UTF-8. Within the application content is _unicode_ (i.e. not encoded).
Bases: object
If REQUEST_METHOD is HEAD, change it to GET and consume the output for lower requests.
Bases: object
Trap permissions exceptions and turn them into HTTP exceptions so the errors are propagated to client code.
Bases: object
WSGI Middleware to write a very simple log to stdout.
Borrowed from Paste Translogger
Print the log info out in a formatted form to logging.info.
This is rather more complex than desirable because there is a mix of str and unicode in the gathered data and we need to make it acceptable for output.
Bases: object
WSGI Middleware that sets our choice of Store (tiddlyweb.store) in the environment.
Bases: object
WSGI Middleware to add a Cache-Control no-transform so that mobile companies that transcode content over their 3G (etc) networks don’t, as it will break various JavaScript things, including TiddlyWiki.