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())class UTC(datetime.tzinfo):
Timezone object for UTC
def utcoffset(self, dt):
def dst(self, dt):
def tzname(self, dt):
def getnow():
Get the current date and time as a datetime.datetime object in UTC
with timezone info.
def httpdate(dt):
Return a string suitable for a "Last-Modified" and "Expires" header.
dt is a datetime.datetime object. If :obj:`dt`.tzinfo is
None dt is assumed to be in the local timezone (using the
current UTC offset which might be different from the one used by dt).
class Connect(object):
Connect objects 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.
def __init__(self, connectstring=None, pool=None, retry=3, **kwargs):
Create a new parameterized Connect decorator. Either
connectstring or pool (a database pool object) must be
specified. retry specifies how often to retry calling the wrapped
function after a database exception. kwargs will be passed on to
the connect call.
def _isbadoracleexception(self, exc):
def _getconnection(self):
def _dropconnection(self, connection):
def cursor(self, **kwargs):
def commit(self):
def rollback(self):
def close(self):
def cancel(self):
def __call__(self, func):
class Call(object):
Wrap an Oracle procedure or function in a CherryPy handler.
A Call object wraps a procedure or function object from
ll.orasql and makes it callable just like a CherryPy handler.
def __init__(self, callable, connection):
Create a Call object wrapping the function or procedure
callable.
def __call__(self, *args, **kwargs):
Call the procedure/function with the arguments args and
kwargs mapping Python function arguments to
Oracle procedure/function arguments. On return from the procedure the
c_out parameter 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_etag is 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 substracted from this value and the resulting value will be used as the HTTP response code, i.e. 20404 will give a "Not Found" response.