Re: [Zope] not allowed to access a particular tuple

2006-10-20 Thread Dieter Maurer
William Heymann wrote at 2006-10-20 06:55 -0600:
>This is an external method I wrote to make it easier to iterate over the 
>records returned from searching the catalog. However if I have
>
>yield record,item instead of yield item it says that I am not allowed to 
>access a particular tuple during iteration.

Probably, you lack the "object permission" for one of the returned
values. You will not see it in the "External Method" but
when you access it in untrusted code, you get an "Unauthorized".



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] not allowed to access a particular tuple

2006-10-20 Thread William Heymann
On Friday 20 October 2006 07:05, Jonathan wrote:

>
> The 'yield' statement is not allowed within a 'try' clause (see the Python
> Reference manual).
>

Hmm that seems strange, it works just fine in all the places I have done it, 
the only issue is zope not liking the returned object if it is not a single 
item. When it is reading over records it is raising exceptions in the calls 
to getObject() sometimes and on all the tests it just does not return those 
objects which is exactly what it should do.

http://www.python.org/doc/2.4.3/ref/yield.html#l2h-510

According to those docs you can't use yield inside a try finally not a try 
except.


> Why don't you just build a simple list (or list of tuples) and return that?
>

I wanted to use yield because records from a Catalog is already lazy and I did 
not want to load a bunch of objects into ram that I did not need to, that is 
why I did not return a list.

>
> Jonathan
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] not allowed to access a particular tuple

2006-10-20 Thread Jonathan


- Original Message - 
From: "William Heymann" <[EMAIL PROTECTED]>

To: 
Sent: Friday, October 20, 2006 8:55 AM
Subject: [Zope] not allowed to access a particular tuple



This is an external method I wrote to make it easier to iterate over the
records returned from searching the catalog. However if I have

yield record,item instead of yield item it says that I am not allowed to
access a particular tuple during iteration. How can I make it so that the
value that it yields is something that a python script object can iterate
over? I have also tried doing yield tuple((record,item))  yield
list(record,item)  and they give the same problem.


How I use the script is pretty much

for record, doc in catalogIter(context.Catalog(searchterms)):
   print record
   print doc

Of course what is inside is different from that but it will cause the same
problem since the issue happens in the iteration not inside the for loop.

import zExceptions

def catalogIter(records):
   "iterate over a catalog safely"
   for record in records:
   try:
   item = record.getObject()
   if item is not None:
   yield item
   except (zExceptions.Unauthorized, zExceptions.NotFound, KeyError,
AttributeError):
   pass


The 'yield' statement is not allowed within a 'try' clause (see the Python 
Reference manual).


Why don't you just build a simple list (or list of tuples) and return that?


Jonathan 



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )