[CMF-checkins] CVS: CMF/CMFUid - UniqueIdGeneratorTool.py:1.2
UniqueIdHandlerTool.py:1.2 interfaces.py:1.2
Grégoire Weber
zope.org at incept.ch
Tue Jul 20 20:02:15 EDT 2004
Update of /cvs-repository/CMF/CMFUid
In directory cvs.zope.org:/tmp/cvs-serv12926
Modified Files:
UniqueIdGeneratorTool.py UniqueIdHandlerTool.py interfaces.py
Log Message:
- moved properties 'remove_on_add' and 'remove_on_clone' to generator tool
- replaced all exceptions raised by 'UniqueIdError' exception
=== CMF/CMFUid/UniqueIdGeneratorTool.py 1.1.1.1 => 1.2 ===
--- CMF/CMFUid/UniqueIdGeneratorTool.py:1.1.1.1 Tue Jul 20 18:06:15 2004
+++ CMF/CMFUid/UniqueIdGeneratorTool.py Tue Jul 20 20:01:45 2004
@@ -44,9 +44,6 @@
IAnnotatedUniqueId,
)
- remove_on_add = True
- remove_on_clone = True
-
def __init__(self, uid):
"""See IAnnotatedUniqueId.
"""
@@ -74,10 +71,11 @@
# the uid object may already be removed by the 'manage_afterAdd'.
# To be independent of the implementation of 'manage_afterAdd'
# the unique id object probably gets removed another time.
- if self.remove_on_clone:
+ generator = getToolByName(item, 'portal_uidgenerator')
+ if generator.remove_on_clone:
try:
delattr(item, self.id)
- except AttributeError:
+ except KeyError, AttributeError:
pass
def manage_beforeDelete(self, item, container):
@@ -85,7 +83,8 @@
"""
# This helps in distinguishing renaming from copying/adding and
# importing in 'manage_afterAdd' (see below)
- if self.remove_on_add:
+ generator = getToolByName(item, 'portal_uidgenerator')
+ if generator.remove_on_add:
self._cmf_uid_is_rename = True
def manage_afterAdd(self, item, container):
@@ -96,10 +95,12 @@
# a rename operation.
# This way I the unique id gets deleted on imports.
_is_rename = getattr(aq_base(self), '_cmf_uid_is_rename', None)
- if self.remove_on_add and self.remove_on_clone and not _is_rename:
+ generator = getToolByName(item, 'portal_uidgenerator')
+ if generator.remove_on_add and generator.remove_on_clone \
+ and not _is_rename:
try:
delattr(item, self.id)
- except AttributeError:
+ except KeyError, AttributeError:
pass
if _is_rename is not None:
del self._cmf_uid_is_rename
@@ -119,13 +120,17 @@
id = 'portal_uidgenerator'
alternative_id = 'portal_standard_uidgenerator'
meta_type = 'Unique Id Generator Tool'
-
+
# make AnnotatedUniqueId class available through the tool
# not meant to be altered on runtime !!!
_uid_implementation = AnnotatedUniqueId
-
+
security = ClassSecurityInfo()
-
+
+ # XXX properties
+ remove_on_add = True
+ remove_on_clone = True
+
security.declarePrivate('__init__')
def __init__(self):
"""Initialize the generator
=== CMF/CMFUid/UniqueIdHandlerTool.py 1.1.1.1 => 1.2 ===
--- CMF/CMFUid/UniqueIdHandlerTool.py:1.1.1.1 Tue Jul 20 18:06:15 2004
+++ CMF/CMFUid/UniqueIdHandlerTool.py Tue Jul 20 20:01:45 2004
@@ -30,6 +30,7 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFUid.interfaces import IUniqueIdHandler
+from Products.CMFUid.interfaces import UniqueIdError
UID_ATTRIBUTE_NAME = 'cmf_uid'
@@ -49,6 +50,9 @@
# not meant to be altered!!!
_UID_ATTRIBUTE_NAME = UID_ATTRIBUTE_NAME
+ # make the exception class available through the tool
+ UniqueIdError = UniqueIdError
+
security = ClassSecurityInfo()
security.declarePublic('quersUid')
@@ -71,7 +75,7 @@
"""
uid = self.queryUid(obj, None)
if uid is None:
- raise KeyError, "Missing unique id on '%s'" % obj
+ raise UniqueIdError, "No unique id available on '%s'" % obj
return uid
@@ -101,7 +105,8 @@
"""
UID_ATTRIBUTE_NAME = self._UID_ATTRIBUTE_NAME
if getattr(aq_base(obj), UID_ATTRIBUTE_NAME, None) is None:
- return
+ raise UniqueIdError, \
+ "No unique id available to be unregistered on '%s'" % obj
# delete the uid
delattr(obj, UID_ATTRIBUTE_NAME)
@@ -142,7 +147,7 @@
"""
brain = self.queryBrain(obj, default=None)
if brain is None:
- raise KeyError, "No object found with '%s' as uid." % uid
+ raise UniqueIdError, "No object found with '%s' as uid." % uid
return brain
security.declarePublic('queryObject')
@@ -160,7 +165,7 @@
"""
brain = self.queryBrain(uid, default=None)
if brain is None:
- raise KeyError, "No object found with '%s' as uid." % uid
+ raise UniqueIdError, "No object found with '%s' as uid." % uid
return brain.getObject()
InitializeClass(UniqueIdHandlerTool)
=== CMF/CMFUid/interfaces.py 1.1.1.1 => 1.2 ===
--- CMF/CMFUid/interfaces.py:1.1.1.1 Tue Jul 20 18:06:15 2004
+++ CMF/CMFUid/interfaces.py Tue Jul 20 20:01:45 2004
@@ -25,6 +25,8 @@
from Products.CMFCore.interfaces.IOpaqueItems \
import ICallableOpaqueItem, ICallableOpaqueItemEvents
+class UniqueIdError(Exception): pass
+
class IUniqueIdQuery(Interface):
"""Querying unique ids.
"""
@@ -37,7 +39,7 @@
def getUid(obj):
"""Return the unique id of the object.
- If the object doesn't have a unique, a KeyError is raised.
+ If the object doesn't have a unique, a UniqueIdError is raised.
"""
def queryObject(uid, default=None):
@@ -50,7 +52,7 @@
def getObject(uid):
"""Return the object with the given uid.
- If no object exist with the given unique id, a KeyError is raised.
+ If no object exist with the given unique id, a UniqueIdError is raised.
"""
@@ -75,7 +77,7 @@
def getBrain(uid):
"""Return a brain of the object with the given uid.
- If no object exist with the given unique id, a KeyError is raised.
+ If no object exist with the given unique id, a UniqueIdError is raised.
Returning a brain is more efficient than returning the object.
A brain usually exposes only parts of the object and should only
@@ -100,7 +102,7 @@
def unregister(obj):
"""Remove the object from the indexes.
- KeyError is raised if object was not registered previously.
+ UniqueIdError is raised if object was not registered previously.
"""
class IUniqueIdHandler(IUniqueIdSet, IUniqueIdQuery, IUniqueIdBrainQuery):
More information about the CMF-checkins
mailing list