Skip to content

Python neo_cgi

David Jeske edited this page May 17, 2017 · 7 revisions

MODULE neo_cgi

Clearsilver is contained in one neo_cgi.so shared library Python module. However, this one library actually contains three Python modules. Some "magic" is used to export "neo_util" and "neo_cs" into Python from the same library. Because of this trickery, you always need to import neo_cgi once first before you can import neo_util or neo_cs.

neo_cgi contains the Clearsilver CGI Kit functionality. It handles functions such as the HTTP form variable parsing, upload parsing, and http header generation. It also has a set of utility functions which are written in fast C-code for doing string escaping and conversion (since Python is slow as a dog).

def cgiWrap(FILE:stdin,FILE:stdout,DICT:environ)
this causes the Clearsilver CGI kit to go THROUGH the python objects for input, output, etc. If you don't call this, then it'll use the low-level C standard in/out, etc. If you are going to use the Python standard out, then you want to tell Clearsilver to use it also to avoid buffering problems. It also is important if you are running as an apache module, or if your python code is grabbing the python stdout.

def urlEscape(STRING:a_string):STRING
Converts a string into a URL-escaped string, by converting space to +, and specific characters to the %XX.

def urlUnescape(STRING:a_string):STRING
Converts a string from a URL-escaped form into a normal form.

def htmlEscape(STRING:a_string):STRING
Converts a string into a properly html-escaped string. For example, by converting " to " and > to >

def text2html(STRING:a_string):STRING
Parses plain text and attempts to make it nicely turn into HTML. It tries to find paragraph boundaries and make them, and turn URLs into links, etc.

def IgnoreEmptyFormVars(INT:enable)
Causes form variables equal to the empty string not to be placed in the HDF dataset. For example, given the URL /mycgi.py?foo=&bar=1, if you set this setting, foo will not appear in Query.foo, if you don't set this setting, it will appear as the empty string.

def exportDate(HDF:dataset,STRING:hdf_path_prefix, STRING:timezone_name, INT:time_t)
Exports a time_t date value into HDF in a structured form so you can render it into a webpage later.

def CGI():CGI_OBJECT
This creates a CGI object, with it's embedded CS and HDF objects. This also parses the enviroment variables and thus the CGI form data present in those variables. It does NOT parse standard input for HTTP POST data. That happens when you call "parse" on the CGI_OBJECT

def update()
This causes the Clearsilver native library to re-register neo_util and neo_cs with the Python interpreter. This function is only necessary in PyApache when you are using an embedded Python interpreter which is reset every page. This is necessary because on interpreter restart the modules are kept loaded, but their init functions are not re-run.

Clone this wiki locally