[Zope] sha and newbie db question.

Dieter Maurer dieter@handshake.de
Wed, 19 Jun 2002 20:03:36 +0200


Alejandro Fernandez writes:
 > I have 2 questions:
 > 
 > I'm trying to replicate the following php code in zope: 
 > 
 > $code = $HTTP_POST_VARS["CODE"];
 > $codemd5  = md5($code);
 > 
 > I believe that in straight python, this would be:
 > 
 > hcode = sha.new(code).hexdigest()
 > 
 > (because as far as I know, there's no md5 equivalent of "hexdigest").
There is also an "md5" module in the standard Python library.

 > But when I run this in a python script, which recieves such a value from a
 > dtml method with a form in it, it complains that it's not allowed to run
 > "new". I'm sorry if this is a well known security restriction, and the
 > page of the zope book or of some manual to get around it would be enough
 > for me thanks!
Please read the "README" tab in "Control_Panel -> Product Management -> PythonScripts.

 > Second problem is a lot easier: I've looked at the relational database
 > chapter of the zope book, but have not found exactly how to do a call to a
 > zsql method from within a python script. Is there somewhere where I can
 > get examples of the dtml/python script code behind a database backed
 > website? The code in particular wouldn't be to display something, but for
 > operations such as inserting, deleting, cacheing queries, storing
 > variables, etc.
It's almost the same for DTML and PythonScripts. The only differences
are the magic DTML name lookup and automatic DTML rendering.

ZSQL Methods are functions that either take there arguments (automatically)
from the request object or (exclusively!) get them passed as keyword
(!) parameters.

Thus, in a Python Script, you have something like

      mySQLMethod= context.mySQLMethod	     # explicit name lookup
                                             # of "mySQLMethod", done
					     # automatically in DTML

      mySQLMethod()			     # call, arguments in REQUEST
      mySQLMethod(arg1=val1, arg2=val2, ...) # call, arguments passed as
                                             # keyword parameters

When the ZSQL Method contains a query (rather than only "insert", "update"
and friends), then the result behaves as a sequence of records.
Each record behaves as an object with the result columns as attributes.

That's all about calling Z SQL Methods from Python Scripts.


Dieter