Re: [Zope] queries and tiny tables and python methods... oh my!
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 buildingbr # '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 )
Re: [Zope] queries and tiny tables and python methods... oh my!
On Fri, 30 Jun 2000, Rik Hoekstra wrote: 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() OK, that makes sense. 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. 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): I was trying to walk the fine line between providing too much detail and not enough. Briefly, 'SB_B208' is an example of the type of string I'm trying to parse. I do a string.split('l', '_') (where 'l' is the argument to the string-splitting Python method) and get ['SB', 'B208']. 'SB' is one of the two-letter codes that gets lookup up in the Tiny Table and 'B208' is an office number. Together, these two strings represent a person's location in our LDAP directory. I don't understand where the weird tuple in the traceback is coming from. 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? 'l' is passed to the Pyton Method. Examples would be: FH_123, SB_A231, DO_111, etc. (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 buildingbr # 'building' comes from the Tiny Table /dtml-in /dtml-in Anyone see where the problem lies? -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/ [EMAIL PROTECTED] | dtml-var pithy_quote | http://linux.com/ ___ 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 )
[Zope] queries and tiny tables and python methods... oh my!
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 buildingbr # '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/ [EMAIL PROTECTED] | dtml-var pithy_quote | http://linux.com/ ___ 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 )