[Zope] type(sql_search())?

Terry Hancock hancock@anansispaceworks.com
Sun, 8 Dec 2002 21:34:15 -0800


Can anybody tell me what this mysterious "results object" thing actually is?

I'm working from within a Zope product, and defining an SQL() method
(same as "ZSQLMethod" created within the ZMI). I then call the method
and get a "list of results". Okay, that's a list, but what are its elements?

Aren't they "class instances"?  Why don't they have a __dict__?  What *is*
this beast, and why isn't it something simple?

I was actually trying to forgo the ridiculously cumbersome path of defining
a "pluggable brain" with module and class name and passing it to the
"advanced management" interface of my ZSQLMethod -- i.e. pretending I'm doing 
everything through the web.  It seems like that really ought not to be 
necessary in product code. You ought to be able to just slap the wrapper on 
right in the code, without setting up all that boilerplate, e.g.:

class my_wrapper:
	def __init__(self, sqlres):
		self.__dict__.update(sqlres.__dict__)
		my_form = DTMLFile('www/my_form', globals())

	def some_method(self, foo):
		return self.sql_stuff + foo

wrapped_results = [my_wrapper(r) for r in sql_search()]

However, that "sqlres.__dict__" chokes, because, mysteriously, sqlres doesn't 
have one. I've had a look at RDB.py, and it sure looks like it ought to have 
__dict__, but experimentation says no.

I thought I'd just run type() on it, and see what Python thinks it is, but 
that brings up another pet peeve about Zope: Why doesn't type() work 
correctly in Zope? Or rather, why doesn't it have a repr()?  Running 
debugging code like:

raise ValueError("My type is %s!" % repr(type(buggy_object)))

returns a Zope traceback page which says:
    Error Type: ValueError
    Error Value: My type is! 

>From the Python command line, of course, this will tell me what the type of 
the object is, such as:

>>> raise ValueError("%s" % type(a))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: <type 'class'>

but not in Zope.

Any help would be much appreciated!
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

"Python takes the pain out of programming ...
            ... and Zope puts it back again."