Python Script Engines for Beesnest
The Python script engine is called BnPython
, this is the name of the
library (dll/sa) and of the module you will import from Python. Place your
Python code inside the <bnscript BnPython> ... </bnscript>
tag (you can use other names as well). Don't forget to put the engine short
configuration file in the Beesnest directory. You have to install the Python
interpreter on your computer, and have the Python executable in the system
search path. I used Python version 2.4 to build this script engine, but version
2.3 will work as well. This is a Storable
Beesnest - Python Functions
Here is the list of Beesnest C++ functions, a Python script can use. All
functions are already imported into the current module, but if you use other
modules, you need to import them from BnPython
- bn_print: Prints string to the Beesnest buffer. This is the way to
generate content to the client. the function takes any number of objects, try to
convert them to strings, and prints them to the script engine buffer. If the
buffer reach some pre-defined size limit, the script terminates with an error.
bn_print("foo ", 1, 2, " bar")
bn_get_hdr: Returns an HTTP request header. if the header does not exist,
it returns an empty string.
bn_get_var: Returns an HTTP request variable. if the variable does not
exist, it will return an empty string.
bn_set_var: Sets an HTTP request variable. The script can also set request
variables, these can then be read by another script. Returns None.
bn_set_var("MyRequestVariable", "My Data")
bn_get_vars: Returns all the names of the HTTP request variables. Use this
function to get all the names of the request variables as a string separated by
a separator you specify.
bn_set_hdr: Sets an HTTP response header. It does not check the syntax of the
header name or value. Returns None.
bn_set_cookie: Sets an HTTP response cookie. The third argument is the number
of days the cookie will be valid (optional, default is 1). The fourth argument
is the path of this cookie (optional, default is "/"). Returns None.
bn_set_cookie("MyCookie", "My Value", 3, "/MyFolder")
bn_clear: Clears the response. It clears everything that wasn't sent to
the client yet, using bn_flush, content as well as headers. Returns None.
bn_flush: Flushes the response. It sends whatever is already in the buffer,
to the client using chunk response. If you will not call bn_flush, the response
will not be a chunk response. Returns None.
bn_adapter: Gets an adapter ID by name. If the adapter name does not
exist, it returns 0. The adapter can be either newly created, or from the user
adapters storage. Whenever using an adapter you should use this ID.
bn_read: Reads from an adapter. Returns a string.
bn_write: Writes to an adapter. Returns None.
bn_write(adapter_id, "SomeAddressToWriteTo", "My Value")
bn_free: Releases an adapter by ID. Call this function just if you done
with the adapter, and do not want to store it any more. Every adapter that
cannot be stored, and you will not free, the script engine will free for you.
exit: Will terminate the script (without an error). It overloads the
regular exit command, but it doesn't overload the sys.exit command
DO NOT USE sys.exit !!!
In addition you can use the Python print
command. All print commands
though, will be always added to the end of the buffer, will not be sent with
or clear with bn_clear
, and will not terminate the script
if the buffer size goes over the limit. On the other hand, with Python print you
can write the content of complex objects. If you don't need all the "fancy"
stuff, you can use print