Re: [Zope-dev] ZPatterns bug with patch

2000-08-28 Thread Steve Alexander

Steve Alexander wrote:
>  
> What rubbish! I didn't mean that at all!
> 
> I think what I meant was this:
> 
> try:
> dm = self.__dict__[_v_dm_]
> except KeyError:
> if name=='id':
> if self.__dict__.has_key('id') and val==self.__dict__.['id']:
> return
> else:
> self.__dict__['id']=val
> return
> raise

I think what I *really* meant was this:

try:
dm = self.__dict__[_v_dm_]
except KeyError:
if name=='id':
if self.__dict__.has_key('id') and val==self.__dict__['id']:
return
else:
self.__dict__['id']=val
self._p_changed = 1
return
raise

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net

___
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] ZPatterns bug with patch

2000-08-28 Thread Steve Alexander

> "Phillip J. Eby" wrote:
> > 
> > try:
> > dm = self.__dict__[_v_dm_]
> > except KeyError:
> > if name=='id' and val==self.__dict__['id']: return
> > raise
> > 
> > Hopefully this should only perform the extra computations when the first
> > part fails...
>
> Are Python classes derived from DataSkin supposed to call
> DataSkin.__init__ ?
>
> Anyway, perhaps this would be a small improvement:
>
> try:
> dm = self.__dict__[_v_dm_]
> except KeyError:
> if (name=='id' and self.__dict__.has_key('id') 
> and val==self.__dict__['id']): return
> raise

What rubbish! I didn't mean that at all!

I think what I meant was this:

try:
dm = self.__dict__[_v_dm_]
except KeyError:
if name=='id':
if self.__dict__.has_key('id') and val==self.__dict__.['id']:
return
else:
self.__dict__['id']=val
return
raise  


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net

___
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] ZPatterns bug with patch

2000-08-28 Thread Steve Alexander

"Phillip J. Eby" wrote:
> 
> At 10:22 AM 8/27/00 +0100, Steve Alexander wrote:
> >
> >I've fixed this by adding a test to the start of __set_attr__ of
> >DataSkins.py:
> >
> >def __set_attr__(self,name,val,_v_dm_=_v_dm_):
> >+   if name=='id' and val==self.__dict__['id']:
> >+   return
> >dm = self.__dict__[_v_dm_]
> 
> This looks reasonable, and backward-compatible, since __init__ guarantees
> the dict will have an id.  I'm not thrilled with adding more overhead to
> attribute setting, however, so I'll probably do it like this:
> 
> try:
> dm = self.__dict__[_v_dm_]
> except KeyError:
> if name=='id' and val==self.__dict__['id']: return
> raise
> 
> Hopefully this should only perform the extra computations when the first
> part fails...

Are Python classes derived from DataSkin supposed to call
DataSkin.__init__ ?

Anyway, perhaps this would be a small improvement:

try:
dm = self.__dict__[_v_dm_]
except KeyError:
if (name=='id' and self.__dict__.has_key('id') 
and val==self.__dict__['id']): return
raise


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net

___
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] ZPatterns bug with patch

2000-08-27 Thread Phillip J. Eby

At 10:22 AM 8/27/00 +0100, Steve Alexander wrote:
>
>I've fixed this by adding a test to the start of __set_attr__ of
>DataSkins.py:
>
>def __set_attr__(self,name,val,_v_dm_=_v_dm_):
>+   if name=='id' and val==self.__dict__['id']:
>+   return
>dm = self.__dict__[_v_dm_]

This looks reasonable, and backward-compatible, since __init__ guarantees
the dict will have an id.  I'm not thrilled with adding more overhead to
attribute setting, however, so I'll probably do it like this:

try:
dm = self.__dict__[_v_dm_]
except KeyError:
if name=='id' and val==self.__dict__['id']: return
raise

Hopefully this should only perform the extra computations when the first
part fails...


___
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] ZPatterns bug with patch

2000-08-27 Thread Steve Alexander

Zope 2.2.1, ZPatterns 0-4-1snap1

I can't add a Dataskin-derived ZClass beneath a Customizer Folder any
more.

I think the order of something in the initialization of ZClasses has
changed
in Zope. It appears that the DataSkin's datamanager isn't being found
before __set_attr__ is called for the first time.

__set_attr__ is being called with name="id" val="id_of_object"

Interestingly, __init__ in DataSkins.py is also being called with the
value id.

This is because in ZClass.py:createInObjectManager, the id is given to
__init__ in the first statement, and set as an attribute in the second.

def createInObjectManager(self, id, REQUEST, RESPONSE=None):
"""
Create Z instance. If called with a RESPONSE,
the RESPONSE will be redirected to the management
screen of the new instance's parent Folder. Otherwise,
the instance will be returned.
"""
i=mapply(self._zclass_, (), REQUEST)
i._setId(id)


I've fixed this by adding a test to the start of __set_attr__ of
DataSkins.py:

def __set_attr__(self,name,val,_v_dm_=_v_dm_):
+   if name=='id' and val==self.__dict__['id']:
+   return
dm = self.__dict__[_v_dm_]



Here's the traceback before I applied the patch:

Error Type: KeyError
  Error Value: _v_dm_

Traceback (innermost last):
  File lib/python/ZPublisher/Publish.py, line 222, in publish_module
  File lib/python/ZPublisher/Publish.py, line 187, in publish
  File lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
(Object: RoleManager)
  File lib/python/ZPublisher/Publish.py, line 171, in publish
  File lib/python/ZPublisher/mapply.py, line 160, in mapply
(Object: Drug_add)
  File lib/python/ZPublisher/Publish.py, line 112, in call_object
(Object: Drug_add)
  File lib/python/OFS/DTMLMethod.py, line 172, in __call__
(Object: Drug_add)
  File lib/python/DocumentTemplate/DT_String.py, line 528, in __call__
(Object: Drug_add)
  File lib/python/DocumentTemplate/DT_With.py, line 133, in render
(Object: Drug.createInObjectManager(REQUEST['id'], REQUEST))
  File lib/python/DocumentTemplate/DT_Util.py, line 337, in eval
(Object: Drug.createInObjectManager(REQUEST['id'], REQUEST))
(Info: REQUEST)
  File , line 0, in ?
  File lib/python/ZClasses/ZClass.py, line 452, in createInObjectManager
(Object: Drug)
  File lib/python/OFS/CopySupport.py, line 442, in _setId
(Object: asdasd)
  File lib/python/Products/ZPatterns/DataSkins.py, line 208, in
__set_attr__
(Object: asdasd)
KeyError: (see above)

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net

___
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 )