6.3. Environment data
Access to the HTTP environment is provided through global variables available in the script's namespace :
- Read-only variables
REQUEST_HANDLERis an object representing the request ; a useful attribute isclient_address, a 2-element tuple with client IP address and port, for example ('127.0.0.1', 1825)ENVIRONis a dictionary with the CGI environment variables :SERVER-SOFTWARE, REQUEST-METHOD, QUERY-STRING,, etc.HEADERSis a dictionary with the HTTP headers sent by the browser : the key is the header name, the value is the header's value. For instanceHEADERS["accept-language"]will return the value of the accept-language headerACCEPTED_LANGUAGESis a list of languages accepted by the user's browser, ordered by preference. The items are two-character strings identifying the language, according to the ISO 639 codification (enfor English,frfor French, etc)COOKIEis a dictionary-like SimpleCookie object (in PythonCookiemodule) that stores the cookies sent by the web browser with the HTTP request (see the section on cookies)Role()is a function that returns the user's role, as defined in the built-in user management framework (see the chapter on authentication)THISis an instance of the classTarget(in k_target.py) representing the current script
- Read-write variables
SET_COOKIEis another SimpleCookie object to which you can set keys and values which will be stored by the web browser as cookies (see the section on cookies)RESPONSEis a dictionary in which you'll set values for the response header that will be sent to the client. This dictionary is insensitive to the case of the keys :RESPONSE['Content-type']andRESPONSE['CONTENT-type']return the same result
The list of built-in names is described in the namespace section