[Checkins] SVN: zope3org/trunk/src/zorg/live/ Added methods and
tests for location handling
Uwe Oestermeier
uwe_oestermeier at iwm-kmrc.de
Mon May 29 03:08:40 EDT 2006
Log message for revision 68330:
Added methods and tests for location handling
Changed:
U zope3org/trunk/src/zorg/live/page/client.js
U zope3org/trunk/src/zorg/live/page/client.py
U zope3org/trunk/src/zorg/live/page/event.py
U zope3org/trunk/src/zorg/live/page/manager.py
U zope3org/trunk/src/zorg/live/page/page.py
U zope3org/trunk/src/zorg/live/server.py
U zope3org/trunk/src/zorg/live/testing.py
-=-
Modified: zope3org/trunk/src/zorg/live/page/client.js
===================================================================
--- zope3org/trunk/src/zorg/live/page/client.js 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/page/client.js 2006-05-29 07:08:39 UTC (rev 68330)
@@ -52,11 +52,15 @@
},
nextEvent : function () {
+
+
if(LivePage.lastRequest){
-// alert("in nextEvent");
+ alert("in nextEvent");
return;
}
var base_url = LivePage.baseURL + "/@@output/" + LivePage.uuid;
+
+ alert("nextEvent" + base_url);
LivePage.lastRequest = new Ajax.Request(base_url,
{ method: 'get', asynchronous:true});
},
@@ -216,7 +220,7 @@
onUpdate : function(event) {
var id = event['id'];
var html = event['html'];
-// alert("update: " + id + " --- " + html);
+ alert("update: " + id);
$(id).innerHTML = html;
// html.evalScripts();
// id.evalScripts();
Modified: zope3org/trunk/src/zorg/live/page/client.py
===================================================================
--- zope3org/trunk/src/zorg/live/page/client.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/page/client.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -53,10 +53,10 @@
manager = zapi.getUtility(ILivePageManager)
+ self.resolver = page.getLocationResolver()
self.where = page.getLocationId()
self.page_class = page.__class__
self.outbox = Queue.Queue()
-
self.principal = page.request.principal
self.touched = time.time()
manager.register(self, uuid)
Modified: zope3org/trunk/src/zorg/live/page/event.py
===================================================================
--- zope3org/trunk/src/zorg/live/page/event.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/page/event.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -244,7 +244,8 @@
class LoginEvent(LivePageEvent) :
""" A login event that can be used to notify about new users.
- >>> LoginEvent(who='member.uoe', where='location').pprint()
+ >>> LoginEvent(who='member.uoe', where='location', client=42).pprint()
+ client : 42
name : 'login'
recipients : 'all'
where : 'location'
@@ -262,7 +263,8 @@
class LogoutEvent(LivePageEvent) :
""" A logout event that can be used to notify about leaving users.
- >>> LogoutEvent(who='member.uoe', where='location').pprint()
+ >>> LogoutEvent(who='member.uoe', where='location', client=42).pprint()
+ client : 42
name : 'logout'
recipients : 'all'
where : 'location'
Modified: zope3org/trunk/src/zorg/live/page/manager.py
===================================================================
--- zope3org/trunk/src/zorg/live/page/manager.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/page/manager.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -135,7 +135,8 @@
self._location(where)[uuid] = client
if not existing :
- login = LoginEvent(who=client.principal.id, where=where)
+ login = LoginEvent(who=client.principal.id,
+ where=where, client=client)
# we use the zope event here since it's up the concrete
# pages how they represent the online status of members
@@ -153,7 +154,8 @@
print "***Info: client already unregistered."
if not self.isOnline(client.principal.id) :
- logout = LogoutEvent(who=client.principal.id, where=where)
+ logout = LogoutEvent(who=client.principal.id,
+ where=where, client=client)
# we use the zope event here since it's up the concrete
# pages how they represent the online status of members
zope.event.notify(logout)
Modified: zope3org/trunk/src/zorg/live/page/page.py
===================================================================
--- zope3org/trunk/src/zorg/live/page/page.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/page/page.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -15,7 +15,7 @@
$Id: page.py 39651 2005-10-26 18:36:17Z oestermeier $
"""
-
+import zope.component
from zope.interface import implements
from zope.security.checker import defineChecker, NoProxy
@@ -27,6 +27,7 @@
from zope.app import zapi
from zope.app.keyreference.interfaces import IKeyReference
from zope.app.publisher.browser import BrowserView
+from zope.app.intid.interfaces import IIntIds
from zope.app.twisted.interfaces import IServerType
@@ -40,7 +41,7 @@
class LivePage(ComposedAjaxPage) :
- """ A Zope3 substitute for the newov.livepage.LivePage
+ """ A Zope3 substitute for the nevow.livepage.LivePage
The initial call of a LivePage (without parameters) returns a page
that immediately connects a client to the server. After that the client
@@ -52,7 +53,20 @@
>>> from zope.interface.verify import verifyObject
>>> verifyObject(ILivePage, page)
True
+
+ A livepage is registered for a location. The location is represented
+ by an id. It's up to the implementation to provide an id with the
+ getLocationId method that can be resolved by the getLocationResolver method.
+
+ The default implementation of this class uses the IntIds utility:
+ >>> context = object()
+ >>> page = LivePage(context, TestRequest())
+ >>> id = page.getLocationId()
+ >>> resolver = page.getLocationResolver()
+ >>> resolver(id) == context
+ True
+
"""
implements(ILivePage)
@@ -87,15 +101,21 @@
""" Returns a group id that allows to share different livepages
in different contexts.
- The default implementation returns the IKeyReference of the
+ The default implementation returns the int id of the
LivePage context.
"""
- key = IKeyReference(self.context, None)
- if key :
- return key.__hash__()
- return 0
+ intIds = zope.component.getUtility(IIntIds)
+ return intIds.register(self.context)
-
+ def getLocationResolver(self) :
+ """
+ Returns a callable that converts location ids to the corresponding
+ objects.
+ """
+
+ intIds = zope.component.getUtility(IIntIds)
+ return intIds.getObject
+
def output(self, uuid) :
""" Convenience function that accesses a specific client.
Modified: zope3org/trunk/src/zorg/live/server.py
===================================================================
--- zope3org/trunk/src/zorg/live/server.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/server.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -50,7 +50,7 @@
badRequest = object()
securityInputLimit = 64000
-requestTimeOut = 30
+requestTimeOut = 5
timeout = os.getenv('LIVESERVER_TIMEOUT')
if timeout:
@@ -226,7 +226,6 @@
('content-length', len(output))]
print "***LivePage result", self.num, len(output), "bytes", self.uuid, headers
- print "Output", output
self.startWSGIResponse('200 Ok', headers)
self._returnOutput(output)
@@ -385,8 +384,6 @@
# Hm, this shouldn't be required:
req.stream.doStartReading = None
-
- print "LivePrebuffer.uri", req.uri
manager = zapi.getUtility(ILivePageManager)
extractor = Extractor(ctx)
type = None
Modified: zope3org/trunk/src/zorg/live/testing.py
===================================================================
--- zope3org/trunk/src/zorg/live/testing.py 2006-05-29 01:01:53 UTC (rev 68329)
+++ zope3org/trunk/src/zorg/live/testing.py 2006-05-29 07:08:39 UTC (rev 68330)
@@ -23,14 +23,35 @@
import zope.app.testing.placelesssetup
from zope.app import zapi
+from zope.app.keyreference.interfaces import IKeyReference
+from zope.app.intid.interfaces import IIntIds
+from zope.app.intid import IntIds
+
from zorg.edition.interfaces import IUUIDGenerator
from zorg.edition.uuid import UUIDGenerator
from zorg.live.page.page import LivePage
from zorg.live.page.interfaces import IClientEventFactory
+from zorg.live.page.manager import LivePageManager
+from zorg.live.page.interfaces import ILivePageManager
from zorg.live.page import event
+class TestKeyReference(object) :
+
+ implements(IKeyReference)
+
+ def __init__(self, object) :
+ self.object = object
+
+ def __call__(self) :
+ return self.object
+
+ def __hash__(self) :
+ return id(self.object)
+
+
+
class TestUUIDGenerator(object) :
""" A generator that produces always the same sequence of uuids for test
purposes.
@@ -44,14 +65,22 @@
self.count += 1
return "uuid%s" % self.count
-def livePageSetUp(test=None) :
+def livePageSetUp(test=None, manager=False) :
+
+ zope.component.provideAdapter(TestKeyReference, [None], IKeyReference)
+
+ zope.component.provideUtility(IntIds(), IIntIds)
zope.component.provideUtility(TestUUIDGenerator(), IUUIDGenerator)
-
zope.component.provideUtility(event.Append, IClientEventFactory,
name="append")
zope.component.provideUtility(event.Update, IClientEventFactory,
name="update")
+ if manager :
+ lpm = LivePageManager()
+ zope.component.provideUtility(lpm, ILivePageManager)
+ return lpm
+
class PlacelessSetup(zope.app.testing.placelesssetup.PlacelessSetup):
def setUp(self, doctesttest=None):
More information about the Checkins
mailing list