9. Built-in names

This page lists all the names available in Karrigell scripts

9.1 Read-only values

ACCEPTED_LANGUAGES The list of languages accepted by the client (they can be set in the browser)
CONFIG Configuration options, as set in the configuration file

Attributes

  • karrigell_dir
  • root_dir
  • data_dir
  • cache_dir
  • allow_directory_listing
  • hide_extensions
  • ignore
  • logging_file
  • output_encoding
COOKIE The cookies sent by the client to the server. Instance of the SimpleCookie class in Python cookie module
HEADERS The request headers, sent by the user agent (browser) to the server. Instance of the email.Message class
QUERY When a script receives form data, QUERY is a dictionary mapping field names to field values
REQUEST When a script receives form data, REQUEST is a dictionary mapping field names to field values (same as QUERY)
REQUEST_HANDLER An object representing the current request handler

Attributes

client_address A tuple with client IP address and port, for example ('127.0.0.1', 1825)
command The HTTP command or method (usually GET or POST)
version Karrigell version number
THIS An object representing the current script. The examples suppose that the script path in the filesystem is C:\cygwin\home\Karrigell\webapps\demo\thisTest.pih, and that it is called by the url demo/thisTest.pih?arg1=value1

Attributes

url The url used by the client to request the script , including the query string if there was one (/demo/thisTest.pih?arg1=value1)
script_url The part of the url that ends at the script name and extension ; strips the function name for ks scripts, smart urls, query string etc. (/demo/thisTest.pih)
baseurl Part of the url before the script name (demo/)
args If the script is requested with additional arguments separated by /, args is the list of these arguments (see smart urls)
name Full name of the script in the file system (C:\cygwin\home\Karrigell\webapps\demo\thisTest.pih)
cwd Full name of the script directory in the file system (C:\cygwin\home\Karrigell\webapps\demo)
ext Script extention (.pih)
rel() A function used to build correct urls inside functions that receive their arguments with the "smart url" feature (host/script/script.ks/foo/bar)
py_code The script source code (or the conversion into Python code for pih scripts)
parent The script's parent if it was included by the Include() function, or None

9.2 Variables and functions

Include() Function used to include a file or a script in another script
Login([script_url],[role], [valid_in], [redir_to]) Function used to limit access to the script to authenticated users. By default, if the user is not yet logged in, redirects to the script login.ks in the admin directory. Another script url can be specified to customize the authentication test. If the user is already logged in, the function does nothing
role is the list of roles accepted by the script. It defaults to ["admin"] and can include "edit" and "visit" as other values
valid_in specifies the part of the site where the user will be logged. Defaults to the scripts in the same folder as the calling script
redir_to is the path the user will be sent to after a successful login. It defaults to the path of the original script
Logout([script_url], [valid_in], [redir_to]) Logs out the user. The arguments have the same meaning as above
REL() A function to transform a relative path name to an absolute path name, based on the script directory
RESPONSE The response headers sent by the server to the client, such as Content-type. Instance of the email.Message class
Role() Indicates the user role. If he is not yet logged in (see Login()), value is None ; otherwise it is one of "visit", "edit" or "admin"
Session() Function that returns the session object
SET_COOKIE The Cookies sent by the server to the client. Instance of the SimpleCookie class in Python cookie module

9.3 Exceptions

HTTP_REDIRECTION raise HTTP_REDIRECTION,url performs an HTTP redirection (302) to the specified url
SCRIPT_END Exception to stop the script execution