<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Dieter Maurer wrote:
<blockquote cite="mid17096.24260.962652.170095@gargle.gargle.HOWL"
type="cite">
<pre wrap="">Jørgen Frøjk Kjærsgaard wrote at 2005-7-1 23:28 +0200:
</pre>
<blockquote type="cite">
<pre wrap="">I need to be able to access a Postgresql database directly from Zope
Python scripts (Z SQL Methods is not an option as the SQL code occurs in
modules that must be re-usable in a non-Zope context).
...
import psycopg
dbcon = psycopg.connect('host=%s dbname=%s user=%s' % ('dbhost',
'dbname', 'username'))
</pre>
</blockquote>
<pre wrap=""><!---->
You should *NOT* do this because you move outside of Zope's
transaction handling.
Fetch the connection from the DA. It looks somehow like:
db = DA()        # low level connection object
db._register() # register with Zope's transaction system
conn = db.db # this is the "psycopg" connection
Pass the "conn" into your code.
</pre>
</blockquote>
Thanks! This is exactly what I would like to do in the end. The code
above was just a first attempt to get started.<br>
<blockquote cite="mid17096.24260.962652.170095@gargle.gargle.HOWL"
type="cite">
<blockquote type="cite">
<pre wrap="">...
When run outside Zope, it opens a connection as expected. When run in
Zope, however, I get "thrown out" - the browser asks me to enter my user
name and password again. I get no error message!
</pre>
</blockquote>
<pre wrap=""><!---->
Cancel the login dialog and you will get the error message :-)
</pre>
</blockquote>
Good to know :-)<br>
<blockquote cite="mid17096.24260.962652.170095@gargle.gargle.HOWL"
type="cite">
<blockquote type="cite">
<pre wrap="">Does Zope somehow create a restricted environment
</pre>
</blockquote>
<pre wrap=""><!---->
PythonScripts are a restricted environment where "import" is
restricted as well as access to attributes.
</pre>
</blockquote>
I didn't read the Zope book very carefully on that point - I have been
using Python mod_python for years but am new to "advanced" Zope
programming.<br>
<br>
Another question: When I define an external method to process form
data, I have to do it like this:<br>
<br>
def process_form_data(self, name, address, zip, ...):<br>
...<br>
<br>
What I would like to do is:<br>
<br>
def process_form_data(self, **args):<br>
...<br>
<br>
so that I don't have to alter the argument list if I add or remove
fields. However, args always comes out empty, presumeably because Zope
inspects the argument list and passes only those arguments that have a
matching name in the list. Is there any way to tell Zope to pass "the
rest" in **args?<br>
<br>
<pre class="moz-signature" cols="160">--
med venlig hilsen / regards
Jørgen Frøjk Kjærsgaard
Systemudvikler
Metation ApS
systemudvikling * hosting * IT rådgivning</pre>
</body>
</html>