+1 The copy_of_copy_of... stuff has always bugged me but I confess I never really looked at the code.
I don't foresee any compatibility problems (any code that relies on the fact that a copy of 'copy_of_x' is named 'copy_of_copy_of_x' surely deserves to die). Please post this in the Zope collector so that it doesn't get lost. Florent In article <[EMAIL PROTECTED]> you write: > Hello, > > While I was reading the _get_id function, I felt it was really strange : > > #### > def _get_id(self, id): > # Allow containers to override the generation of > # object copy id by attempting to call its _get_id > # method, if it exists. > n=0 > if (len(id) > 8) and (id[8:]=='copy_of_'): > n=1 > orig_id=id > while 1: > if self._getOb(id, None) is None: > return id > id='copy%s_of_%s' % (n and n+1 or '', orig_id) > n=n+1 > #### > > currently, when copying and pasting an object, 'copy[0-9]*_of_' will be > prepended to the id (if the id is already in use in the current > folder). Thus, copying 'x' will create 'copy_of_x', 'copy2_of_x', etc. > and copying 'copy_of_x' will create 'copy_of_copy_of_x', > 'copy2_of_copy_of_x', etc. > > What I don't get, is what the two lines between 'n=0' and 'orig_id=id' > are supposed to do. What they do is this : if an object id is 16 chars > long, and it ends with 'copy_of_' (like 'XXXXXXXXcopy_of_'), its first > copy will be called 'copy2_of_XXXXXXXXcopy_of_' instead of > 'copy_of_XXXXXXXXcopy_of_'... > > What I think the author intended to do, is that, when you copy an object > called 'copy_of_x', the copy will be named 'copy2_of_x' instead of > 'copy_of_copy_of_x'. > > Thus, here's a function that does the job : > > #### > import re > copy_re=re.compile('^copy[0-9]*_of_') > > def _get_id(self, id): > # Allow containers to override the generation of > # object copy id by attempting to call its _get_id > # method, if it exists. > copy_match=self.copy_re.match(id) > if (copy_match) and (copy_match.end() < len(id)): > n=1 > orig_id=self.copy_re.sub('', id) > else: > n=0 > orig_id=id > while 1: > if self._getOb(id, None) is None: > return id > id='copy%s_of_%s' % (n and n+1 or '', orig_id) > n=n+1 > #### > > Then, I don't know what is the preferred naming for new objects, but I > fear that 'copy_of_copy_of_copy_of_copy_of_copy_of_copy_of_object' will > quickly be too long, if objects are copied by an automated process that > doesn't show the Ids to the user or don't allow their modification. > > What are your feelings about this ? > > Regards, > Alexandre Boeglin > _______________________________________________ > 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 ) > -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com [EMAIL PROTECTED] _______________________________________________ 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 )