Skipole WSGI generator.

Topics:

Introduction Getting Started Your Code start_call submit_data end_call PageData SectionData skicall Serving wsgi

Development at GitHub:

github.com/bernie-skipole/skipole

skicall

The skicall object passed to your functions has several attributes, most provide you with information - some you can alter:

skicall.accesstextblocks is the project instance of the AccessTextBlocks class, most users will not need this, but it may be required for certain applications.

skicall.call_data is a dictionary which could contain data you set into it or could contain submitted form data (depending on the Responder handling the call).

skicall.caller_ident is the ident of the page making the call, a tuple ('projname', pagenumber), generally sent with any submitted data, this value could be an empty tuple if the page ident is not known - which will happen if the calling page is external or if no data is submitted.

skicall.environ is the wsgi environ dictionary.

skicall.ident_data is a string which was previously saved onto the page by setting a PageData attribute PageData().ident_data, and has now been sent back together with any submitted data. skicall.ident_data will be None if not present.
This facility can be used to pass data between calls. You need to validate this received string as it can be altered by a malicious caller.

skicall.ident_list is initially an empty list but will have the ident ('projname', pagenumber) of each responder handling the call appended to it. Typically a call will be handled by a single responder, but it is possible for one responder to pass the call on to another, and so several may be involved in a call.

skicall.lang is a read-only tuple of two strings containing the preferred language required by the client in the format (language, default_language).
This attribute is used when requesting TextBlocks.

skicall.language is a string such as 'en' being the preferred language required by the client, initially taken from the client browser's language setting, or from a received language cookie. If changed it will cause a language cookie to be set. It may be that the client browser preferred language is not available, hence this is independent of the Pagedata().lang attribute - which, if used, sets the page html tag 'lang' attribute.

skicall.path is the URL path to the page called.

skicall.proj_data is a project attribute, a dictionary set when creating the skipole.WSGIApplication object. It could be used for your own purpose - for example to input a database password when the program is started.

skicall.project is the project name.

skicall.projectfiles is the string path to the 'projectfiles' directory of data and static files. Each project's specific directory can be found beneath it - that is, in the '..projectfiles/myproject/' directory.

skicall.received_cookies is a dictionary of cookie name:values received from the client. Note, that if skicall.language is set, a cookie value received will appear in this dictionary with key 'language'.

skicall.rootproject will be True if this is the root project, False if it is a sub project.

skicall.submit_list is a list set by a responder.

skicall.submit_dict is a dictionary set by a responder.

METHODS

skicall.update(itemdata) updates skicall from a PageData or SectionData object.

skicall.clear_page_data() clears any data.

skicall.label_value(label, project=None) is a method which given a label, returns the associated ident or URL.
If project is not given assumes the current project, if given, project must exist as either the root, or a sub project of the root. If no label is found, returns None.

skicall.textblock(textref, project=None) is a method which given a reference string returns the text of the associated TextBlock.
If project is None, it assumes the TextBlock is defined in the current project, if project is given it must be the root or a sub project. If no TextBlock is found, it returns None.

skicall.projectpaths() returns a dictionary of project names as keys with the project url paths as values.

skicall.makepath(*foldernames) returns a url path string starting with this project's url, with the given foldernames joined. If no foldernames are given, then just the project url is returned.

skicall.map_url_to_server(urlfolder, serverfolder, mimetype="") maps a url folder to a server folder.
Generally called in the start_call function. Maps a url folder such as "/projecturl/special/css" to a server folder such as "/home/user/thisproject/css"
if a call is made to, say "/projecturl/special/css/myfile.css" this function will return a pathlib.Path object to the file "/home/user/thisproject/css/myfile.css" if such a file exists. If not then None is returned. If start_call returns such a pathlib.Path, then the framework will serve the file. A mimetype can be given, otherwise it will be guessed.
An example of usage is:

    def start_call(called_ident, skicall):
        servedfile = skicall.map_url_to_server("special/css", "/home/user/thisproject/css")
        if servedfile:
            return servedfile
        return called_ident

Note: If the given urlfolder starts with a "/", it is an absolute url, if it does not, as in the above example, then it will be relative, with the project url prepended. Using relative paths makes the code more portable, particularly if this project is to become a sub-project added to a root which may change its project url.