ll.nightshade – Using Oracle with CherryPy
This module provides a class Call that allows you to use Oracle PL/SQL
procedures/functions as CherryPy response handlers. A Call objects
wraps a ll.orasql.Procedure or ll.orasql.Function object from
the ll.orasql module.
For example, you might have the following PL/SQL function:
create or replace function helloworld
(
        who varchar2
)
return varchar2
as
begin
        return '<html><head><h>Hello ' || who || '</h></head><body><h1>Hello, ' || who || '!</h1></body></html>';
end;
Using this function as a CherryPy response handler can be done like this:
import cherrypy
from ll import orasql, nightshade
proc = nightshade.Call(orasql.Function("helloworld"), connectstring="user/pwd")
class HelloWorld:
        @cherrypy.expose
        def default(self, who="World"):
                cherrypy.response.headers["Content-Type"] = "text/html"
                return proc(who=who)
cherrypy.quickstart(HelloWorld())
- ll.nightshade.getnow()[source]
- Get the current date and time as a - datetime.datetimeobject in UTC with timezone info.
- ll.nightshade.httpdate(dt)[source]
- Return a string suitable for a “Last-Modified” and “Expires” header. - dtis a- datetime.datetimeobject. If- dt.tzinfois- None- dtis assumed to be in the local timezone (using the current UTC offset which might be different from the one used by- dt).
- class ll.nightshade.Connect[source]
- Bases: - object- Connectobjects can be used as decorators that wraps a function that needs a database connection.- If calling the wrapped function results in a database exception that has been caused by a lost connection to the database or similar problems, the function is retried with a new database connection. - __init__(connectstring=None, pool=None, retry=3, **kwargs)[source]
- Create a new parameterized - Connectdecorator. Either- connectstringor- pool(a database pool object) must be specified.- retryspecifies how often to retry calling the wrapped function after a database exception.- kwargswill be passed on to the- connect()call.
 
- class ll.nightshade.Call[source]
- Bases: - object- Wrap an Oracle procedure or function in a CherryPy handler. - A - Callobject wraps a procedure or function object from- ll.orasqland makes it callable just like a CherryPy handler.- __init__(callable, connection)[source]
- Create a - Callobject wrapping the function or procedure- callable.
 - __call__(*args, **kwargs)[source]
- Call the procedure/function with the arguments - argsand- kwargsmapping Python function arguments to Oracle procedure/function arguments. On return from the procedure the- c_outparameter is mapped to the CherryPy response body, and the parameters- p_expires(the number of days from now),- p_lastmodified(a date in UTC),- p_mimetype(a string),- p_encoding(a string),- p_etag(a string) and- p_cachecontrol(a string) are mapped to the appropriate CherryPy response headers. If- p_etagis not specified a value is calculated.- If the procedure/function raised a PL/SQL exception with a code between 20200 and 20599, 20000 will be subtracted from this value and the resulting value will be used as the HTTP response code, i.e. 20404 will give a “Not Found” response.