Timothy Wilson wrote:
>
> 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
The error means you're trying to split up a string, but the argument is
no string, but an instance (a Python Object). In many cases this is
caused by an omission of parenthesis, like so
called_object instead of called_object()
in which case the object is referenced instead of called and nothing is
returned (of course). I did not find the culprit in your description,
though.
<snip>
>
> (Object: parseLocation)
> (Info: ((['SB_B208'],), {}, None))
> File <string>, line 2, in parseLocation
> TypeError: (see above)
>
I do not quite get what part you want to parse. Is it 'SB_B208'?
accessing this in python is a bit strange due to the returned value. You
get to the 'SB_B208'part in the following way:
whateverreturnstheresult(<someargument>)[0][0][0], meaning (in this
case):
the first element (of the list) of the first element (of the first
tuple) of the returned tuple
>
> 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.
yep, see above
>
> Here's the code for parseLocation ('l' is the argument):
>
> x = string.split(l, '_')
> return x[0]
I may be reading badly, but can you explain what the l is (or is
supposed to be)? Is it the tuple in the traceback?
>
> (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.
hth
Rik
_______________________________________________
Zope maillist - [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope-dev )