Re: [Zope-dev] More on the getId issue...
Richard Jones wrote at 2003-7-1 12:03 +1000: ... PageTemplateFile (via Script and SimpleItem) inherits Item. This class has an attribute id set to '' by default. PageTemplateFiles don't use id though, they use __name__. The getId implementation that PageTemplateFiles use has some mention of __name__ in it, but it'll never get used because: id = '' def getId(self): name=getattr(self, 'id', None) if callable(name): return name() if name is not None: return name if hasattr(self, '__name__'): return self.__name__ raise AttributeError, 'This object has no id' This is funny code indeed... Obviously, the code starting with line 4 in the function can only be executed by hackers. Please file a bug report. Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] More on the getId issue...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Saturday, July 5, 2003, at 04:50 AM, Dieter Maurer wrote: Richard Jones wrote at 2003-7-1 12:03 +1000: ... PageTemplateFile (via Script and SimpleItem) inherits Item. This class has an attribute id set to '' by default. PageTemplateFiles don't use id though, they use __name__. The getId implementation that PageTemplateFiles use has some mention of __name__ in it, but it'll never get used because: id = '' def getId(self): name=getattr(self, 'id', None) if callable(name): return name() if name is not None: return name if hasattr(self, '__name__'): return self.__name__ raise AttributeError, 'This object has no id' This is funny code indeed... Obviously, the code starting with line 4 in the function can only be executed by hackers. Please file a bug report. Or I could just fix it with the modified version I posted :) Richard -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (Darwin) iD8DBQE/BiGSrGisBEHG6TARAqEbAJ405Vv/bmCRwRygT1pOAv0CxsEd3gCfZGc6 WQOJT0xo3TElzmeU1gRLLkk= =eYtw -END PGP SIGNATURE- ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
[Zope-dev] More on the getId issue...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 In my last email, I said Also, is there a reason why Item_w__name__ doesn't define getId() when it does define _setId()? This question doesn't really capture the essence of the problem. In a nutshell, the following happened... PageTemplateFile (via Script and SimpleItem) inherits Item. This class has an attribute id set to '' by default. PageTemplateFiles don't use id though, they use __name__. The getId implementation that PageTemplateFiles use has some mention of __name__ in it, but it'll never get used because: id = '' def getId(self): name=getattr(self, 'id', None) if callable(name): return name() if name is not None: return name if hasattr(self, '__name__'): return self.__name__ raise AttributeError, 'This object has no id' Note the default value of None in the getattr at the start, and then the test for None later on. Oh, hang on, except we've got a *class* level default value for id of ''. Ehem. I suspect that the if name is not None test *should* read if name. And there doesn't need to be the default value for the getattr. I have no idea how much code that assumes that objects will at least have an id of '' will break. My proposed new getId() method: def getId(self): name = self.id if callable(name): return name() if name: return name if hasattr(self, '__name__'): return self.__name__ raise AttributeError, 'This object has no id' Richard -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (Darwin) iD8DBQE/AOvurGisBEHG6TARAsXQAJsGEri4RIIWpjrSTbjQUZKU37hfLgCfVZTp jax496YYNjtVosNZHpv8VGc= =lzBT -END PGP SIGNATURE- ___ Zope-Dev maillist - [EMAIL PROTECTED] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )