[Zope] queries and tiny tables and python methods... oh my!

Timothy Wilson wilson@visi.com
Thu, 29 Jun 2000 14:07:42 -0500 (CDT)


Hi everyone,

(Please excuse the vague Wizard of Oz reference in the sub., but my brain
may be imploding. :-)

I'm trying to merge several type of Zope objects, and I'm getting lots of
little errors. I wonder if someone could suggest where my problem lies.

1. I'm querying our LDAP server to retrieve the records for a given person
in the directory. No problem there.

2. I'm parsing one of the entries in the LDAP directory to retrieve the
user's location. Python method code is simple.

3. I'm using a Tiny Table to look up a value for one of the parsed strings.
Easy.

The problem is hooking them all together. Passing the query to a
PythonMethod is throwing up the following error:

Error Type: TypeError
Error Value: argument l: expected read-only character buffer, instance found

(BTW, Netscape on Windows doesn't product a traceback, but Netscape on Linux
does.)

<!--
Traceback (innermost last):
  File /usr/local/src/zope/2.1.6/lib/python/ZPublisher/Publish.py, line 214,
in publish_module
  File /usr/local/src/zope/2.1.6/lib/python/ZPublisher/Publish.py, line 179,
in publish
  File /usr/local/src/zope/2.1.6/lib/python/Zope/__init__.py, line 202, in
zpublisher_exception_hook
    (Object: ElementWithAttributes)
  File /usr/local/src/zope/2.1.6/lib/python/ZPublisher/Publish.py, line 165,
in publish
  File /usr/local/src/zope/2.1.6/lib/python/ZPublisher/mapply.py, line 160,
in mapply
    (Object: rpt_contactInfo)
  File /usr/local/src/zope/2.1.6/lib/python/ZPublisher/Publish.py, line 102,
in call_object
    (Object: rpt_contactInfo)
  File /usr/local/src/zope/2.1.6/lib/python/OFS/DTMLMethod.py, line 150, in
__call__
    (Object: rpt_contactInfo)
  File /usr/local/src/zope/2.1.6/lib/python/DocumentTemplate/DT_String.py,
line 502, in __call__
    (Object: rpt_contactInfo)
  File /usr/local/src/zope/2.1.6/lib/python/DocumentTemplate/DT_In.py, line
691, in renderwob
    (Object: qry_person(uid = user_id))
  File /usr/local/src/zope/2.1.6/lib/python/DocumentTemplate/DT_In.py, line
633, in renderwob
    (Object: buildingCodes(parseLocation(l)))
  File /usr/local/src/zope/2.1.6/lib/python/DocumentTemplate/DT_Util.py,
line 335, in eval
    (Object: buildingCodes(parseLocation(l)))
    (Info: parseLocation)
  File <string>, line 0, in ?
  File
/usr/local/src/zope/Zope/lib/python/Products/PythonMethod/PythonMethod.py,
line 168, in __call__
    (Object: parseLocation)
    (Info: ((['SB_B208'],), {}, None))
  File <string>, line 2, in parseLocation
TypeError: (see above)

-->

parseLocation is a Python Method which takes 1 argument (a string) and 
returns the first element of the list that's formed by splitting the string.
That first element is a two-letter code that's looked up in a Tiny Table
called buildingCodes which returns the full name of the building.

OK, it looks to my relatively inexperienced eyes that the Python Method
isn't getting an argument of the type is expects.

Here's the code for parseLocation ('l' is the argument):

x = string.split(l, '_')
return x[0]

(BTW, changing it to x = string.split(`l`, '_') eliminates the error, but
nothing is rendered.

qry_person is an ZLDAP filter method that takes one argument (uid). The
original dtml to display this mess looks like:

<dtml-call "REQUEST.set('user_id', user_id)">
<dtml-in "qry_person(uid = user_id)"><br>
  <dtml-in "buildingCodes(parseLocation(l))">
    <dtml-var building><br>  # 'building' comes from the Tiny Table
  </dtml-in>
</dtml-in>

I'd appreciate it if anyone has any ideas about this. I'm probably making
the whole thing too complicated, but for reasons of code reuse, this seemed
like the most efficient approach.

-Tim

--
Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |                              | http://slashdot.org/
wilson@visi.com |   <dtml-var pithy_quote>     | http://linux.com/