[Zope3-checkins] CVS: Zope3/lib/python/Zope/ObjectHub - HubEvent.py:1.2 IHubEvent.py:1.3 ObjectHub.py:1.9
Jim Fulton
jim@zope.com
Thu, 3 Oct 2002 16:53:24 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/ObjectHub
In directory cvs.zope.org:/tmp/cvs-serv6678/lib/python/Zope/ObjectHub
Modified Files:
HubEvent.py IHubEvent.py ObjectHub.py
Log Message:
Refactored Object events:
- All ObjectEvents now have an object attribute, which is the
the subject of the event.
- Changed the getLocation and getFromLocation methods to location and
fromLocation attributes.
Refactored HubEvents:
- Changed getObject, getRuid, and getLocation methods to object, hid,
and location attributes.
=== Zope3/lib/python/Zope/ObjectHub/HubEvent.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/ObjectHub/HubEvent.py:1.1 Thu Aug 22 13:05:24 2002
+++ Zope3/lib/python/Zope/ObjectHub/HubEvent.py Thu Oct 3 16:53:22 2002
@@ -17,6 +17,8 @@
$Id$
"""
+__metaclass__ = type
+
from IHubEvent import IObjectRegisteredHubEvent
from IHubEvent import IObjectAddedHubEvent
from IHubEvent import IObjectUnregisteredHubEvent
@@ -26,27 +28,26 @@
class HubEvent:
"""Convenient mix-in for HubEvents"""
+
+ location = None
+ hid = None
- def __init__(self, objecthub, ruid, location):
+ def __init__(self, objecthub, hid, location):
# we keep all three, to avoid unnecessary lookups
# and to give the objecthub an opportunity to do
# caching of objects
self.__objecthub = objecthub
- self.__ruid = ruid
- self.__location = location
-
- def getRuid(self):
- return self.__ruid
-
- def getLocation(self):
- return self.__location
+ self.hid = hid
+ self.location = location
- def getObject(self):
+ def __getObject(self):
if hasattr(self, '_v_object'):
return self._v_object
- obj = self._v_object = self.__objecthub.getObject(self.__ruid)
+ obj = self._v_object = self.__objecthub.getObject(self.hid)
return obj
+ object = property(__getObject)
+
class ObjectRegisteredHubEvent(HubEvent):
"""An ruid has been freshly created and mapped against an object."""
@@ -85,16 +86,9 @@
__implements__ = IObjectRemovedHubEvent
- def __init__(self, obj, ruid, location):
- self.__object = obj
- self.__ruid = ruid
- self.__location = location
-
- def getRuid(self):
- return self.__ruid
-
- def getLocation(self):
- return self.__location
+ object = None
- def getObject(self):
- return self.__object
+ def __init__(self, obj, hid, location):
+ self.object = obj
+ self.hid = hid
+ self.location = location
=== Zope3/lib/python/Zope/ObjectHub/IHubEvent.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/ObjectHub/IHubEvent.py:1.2 Tue Sep 3 16:16:50 2002
+++ Zope3/lib/python/Zope/ObjectHub/IHubEvent.py Thu Oct 3 16:53:22 2002
@@ -17,6 +17,7 @@
$Id$
"""
from Zope.Event.IEvent import IEvent
+from Interface.Attribute import Attribute
class IHubEvent(IEvent):
"""Internal Object Hub Event : something has happened to an object for
@@ -24,14 +25,11 @@
An ruid is a way of refering to an object independent of location.
"""
- def getRuid():
- """Returns the object's ruid."""
-
- def getLocation():
- """Returns the object's current location."""
-
- def getObject():
- """Returns the object."""
+ object = Attribute("The subject of the event.")
+
+ hid = Attribute("the object's hub-unique id")
+
+ location = Attribute("An optional object location.")
class IRegistrationHubEvent(IHubEvent):
@@ -59,9 +57,7 @@
"""An object with an ruid has had its context changed. Typically, this
means that it has been moved."""
- def getFromLocation():
- """Returns the location before the move
- """
+ fromLocation = Attribute("The old location for the object.")
class IObjectRemovedHubEvent(IHubEvent):
"""An object with an ruid has been removed."""
=== Zope3/lib/python/Zope/ObjectHub/ObjectHub.py 1.8 => 1.9 ===
--- Zope3/lib/python/Zope/ObjectHub/ObjectHub.py:1.8 Thu Aug 22 13:05:24 2002
+++ Zope3/lib/python/Zope/ObjectHub/ObjectHub.py Thu Oct 3 16:53:22 2002
@@ -95,14 +95,14 @@
# generate NotificationHubEvents only if object is known
# ie registered
if IObjectMovedEvent.isImplementedBy(event):
- canonical_location = locationAsUnicode(event.getFromLocation())
+ canonical_location = locationAsUnicode(event.fromLocation)
ruid = self._lookupRuid(canonical_location)
if ruid is not None:
- self._objectMoved(event.getFromLocation(),
- event.getLocation())
+ self._objectMoved(event.fromLocation,
+ event.location)
return
- canonical_location = locationAsUnicode(event.getLocation())
+ canonical_location = locationAsUnicode(event.location)
ruid = self._lookupRuid(canonical_location)
if ruid is not None:
if IObjectAddedEvent.isImplementedBy(event):
@@ -114,7 +114,7 @@
elif IObjectRemovedEvent.isImplementedBy(event):
self._objectRemoved(canonical_location,
ruid,
- event.getObject())
+ event.object)
# otherwise, ignore the event
def lookupRuid(self, location):