Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-25 Thread Jeremy Hylton
 JPS == Jeffrey P Shell Jeffrey writes:

  JPS What about ``if callable(aq_base(newKeywords)):`` to remove
  JPS potential acquisition wrappers?

callable() returns True for any instance.  Since PersistentList is an
instance, you can't use callable() to determine whether it is
callable.

Jeremy


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-25 Thread Steve Alexander
Jeremy Hylton wrote:


JPS == Jeffrey P Shell  writes:


  JPS What about ``if callable(aq_base(newKeywords)):`` to remove
  JPS potential acquisition wrappers?

callable() returns True for any instance.


Any instance of what?


[steve@localhost]$ python2.2
Python 2.2.2 (#1, Oct 31 2002, 10:45:23)
[GCC 2.96 2731 (Red Hat Linux 7.2 2.96-108.7.2)] on linux2
Type help, copyright, credits or license for more information.
 callable(object())
0
 class Foo:
...   pass
...
 callable(Foo())
0



--
Steve Alexander


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-25 Thread Jeremy Hylton
It must be any instance of an ExtensionClass.  I think Python
instances used to be true-for-callable as well, but that must have
been fixed.

Python 2.1.3 (#5, Aug 15 2002, 10:41:31) 
[GCC 2.95.3 19991030 (prerelease)] on linux2
Type copyright, credits or license for more information.
 from ZODB.PersistentList import *
 callable(PersistentList())
1

Jeremy


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-25 Thread Chris McDonough
There is a workaround for this in the DocumentTemplate package.  It
implements a safe_callable function that seems to do the right thing
with ext class instances:

def safe_callable(ob):
# Works with ExtensionClasses and Acquisition.
if hasattr(ob, '__class__'):
if hasattr(ob, '__call__'):
return 1
else:
return type(ob) in ClassTypes
else:
return callable(ob)


On Mon, 2002-11-25 at 13:01, Jeremy Hylton wrote:
 It must be any instance of an ExtensionClass.  I think Python
 instances used to be true-for-callable as well, but that must have
 been fixed.
 
 Python 2.1.3 (#5, Aug 15 2002, 10:41:31) 
 [GCC 2.95.3 19991030 (prerelease)] on linux2
 Type copyright, credits or license for more information.
  from ZODB.PersistentList import *
  callable(PersistentList())
 1
 
 Jeremy
 
 
 ___
 Zope-Dev maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  **
 (Related lists - 
  http://lists.zope.org/mailman/listinfo/zope-announce
  http://lists.zope.org/mailman/listinfo/zope )



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



[Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-20 Thread Thomas Guettler
Hi!

In KeywordIndex the newKeywords get called
if they are callable:
def _get_object_keywords(self,obj):
newKeywords = getattr(obj, self.id, ())
if callable(newKeywords):   # (*) 
newKeywords = newKeywords()
if hasattr(newKeywords,'capitalize'): # is it string-like ?
newKeywords = (newKeywords, )
return newKeywords

This fails if the newKeywords are stored in a PersistentList. 

Callable is true, but there is no __call__ attribute.

I changed the line marked with (*) to 
 if hasattr(newKeyword, __call__):

and this seems to work

I think this does not break anything and could be included in the
original.

Am I the first how uses PersistentList for an indexed attribute? Is
there a reason not to do so?

 thomas

Please CC to me I am not on the list yet

 


-- 
Thomas Guettler [EMAIL PROTECTED]
http://www.thomas-guettler.de


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-20 Thread Steve Alexander
Thomas Guettler wrote:


Hi!

In KeywordIndex the newKeywords get called
if they are callable:
def _get_object_keywords(self,obj):
newKeywords = getattr(obj, self.id, ())
if callable(newKeywords):   # (*)
			newKeywords = newKeywords()
if hasattr(newKeywords,'capitalize'): # is it string-like ?
newKeywords = (newKeywords, )
return newKeywords

This fails if the newKeywords are stored in a PersistentList.

Callable is true, but there is no __call__ attribute.

I changed the line marked with (*) to
 if hasattr(newKeyword, __call__):

and this seems to work

I think this does not break anything and could be included in the
original.

Am I the first how uses PersistentList for an indexed attribute? Is
there a reason not to do so?



The KeywordIndex should be changed to check for the __call__ attribute, 
rather than relying on 'callable'. You cannot reliably use 'callable' 
when you're also using acquisition wrappers.

See my comment to this Collector report.

  http://collector.zope.org/Zope/578

I suggest you report the bug you have found in the Collector.

--
Steve Alexander




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-20 Thread Casey Duncan
Just a note that this can't be put in Zope 2.6 since functions and methods 
don't have a __call__ in Python 2.1.

-Casey

On Wednesday 20 November 2002 02:33 pm, Steve Alexander wrote:
 Thomas Guettler wrote:
 
  Hi!
 
  In KeywordIndex the newKeywords get called
  if they are callable:
  def _get_object_keywords(self,obj):
  newKeywords = getattr(obj, self.id, ())
  if callable(newKeywords):   # (*)
  newKeywords = newKeywords()
  if hasattr(newKeywords,'capitalize'): # is it string-like ?
  newKeywords = (newKeywords, )
  return newKeywords
 
  This fails if the newKeywords are stored in a PersistentList.
 
  Callable is true, but there is no __call__ attribute.
 
  I changed the line marked with (*) to
   if hasattr(newKeyword, __call__):
 
  and this seems to work
 
  I think this does not break anything and could be included in the
  original.
 
  Am I the first how uses PersistentList for an indexed attribute? Is
  there a reason not to do so?
 
 
 The KeywordIndex should be changed to check for the __call__ attribute, 
 rather than relying on 'callable'. You cannot reliably use 'callable' 
 when you're also using acquisition wrappers.
 
 See my comment to this Collector report.
 
http://collector.zope.org/Zope/578
 
 I suggest you report the bug you have found in the Collector.
 
 --
 Steve Alexander

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] KeywordIndex and PersistentList (Bug?)

2002-11-20 Thread Jeffrey P Shell
What about ``if callable(aq_base(newKeywords)):`` to remove potential 
acquisition wrappers?

On Wednesday, November 20, 2002, at 12:41  PM, Casey Duncan wrote:

Just a note that this can't be put in Zope 2.6 since functions and 
methods
don't have a __call__ in Python 2.1.

-Casey

On Wednesday 20 November 2002 02:33 pm, Steve Alexander wrote:
Thomas Guettler wrote:


Hi!

In KeywordIndex the newKeywords get called
if they are callable:
def _get_object_keywords(self,obj):
newKeywords = getattr(obj, self.id, ())
if callable(newKeywords):   # (*)
			newKeywords = newKeywords()
if hasattr(newKeywords,'capitalize'): # is it string-like ?
newKeywords = (newKeywords, )
return newKeywords

This fails if the newKeywords are stored in a PersistentList.

Callable is true, but there is no __call__ attribute.

I changed the line marked with (*) to
 if hasattr(newKeyword, __call__):

and this seems to work

I think this does not break anything and could be included in the
original.

Am I the first how uses PersistentList for an indexed attribute? Is
there a reason not to do so?



The KeywordIndex should be changed to check for the __call__ 
attribute,
rather than relying on 'callable'. You cannot reliably use 'callable'
when you're also using acquisition wrappers.

See my comment to this Collector report.

   http://collector.zope.org/Zope/578

I suggest you report the bug you have found in the Collector.

--
Steve Alexander

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )