Re: [Zope-dev] connecting server code to the ZODB
Replying to myself in case anyone is interested in the answer to my problems... Tim Hicks said: Nope, I don't have a reference to a persistent object. I'm looking at the code in smtpserver.SMTPServer and trying to figure out what I need to adjust. As far as I can tell, the only point in that code at which a 'link' to zope/zodb objects is made is in the following call in SMTPChannel.process_message: handle(self.server.module, request, response) My immediate problem is that I don't understand how the result of this call gets dealt with. It just seems to get discarded in the smtpserver code. If this is the way to interact with the publisher, how do I get hold of the return value? I'm assuming that by adjusting the REQUEST['PATH_INFO'] value before calling handle(), I can affect which ZODB object/method gets called, but I want to know the result of this call. The REQUEST['PATH_INFO'] part is correct: that is how you determine which method gets traversed to and called. I discovered that you get hold of the return value from this method by passing a callback method into the response constructor. This gives you access to whatever arguments you arrange to have the callback called with *plus* the response object, which you can use to have a look at status codes etc. cheers, tim ___ 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] connecting server code to the ZODB
Paul Winkler said: Ok, so I could simply drop the Zope.startup() line and things would be fine (and quick), right? I haven't tried it, but I think doing Zope.app() will try to acquire a lock on the database and it is already locked by the running Zope (or ZEO). So I don't think you can do that. Ok, I think I follow that. I think you should use the existing publisher machinery. Given an SMTPRequest instance foo, you should be able to do foo.traverse(path, response) and get back an object. This monster method is defined in ZPublisher/BaseRequest.py What does using foo.traverse() buy me over simply accessing the ZODB objects 'by hand', as in root = Zope.app()? Well, for one thing it might actually work ;-) Good point :-). The only thing is that I'm not sure that I actually am able to call foo.traverse() before it gets passed into handle() (see below) because I don't think that it will be populated with 'PARENTS' before it's been 'sent to zope'. Note, I'm not sure what your code looks like - if you already have a reference to any persistent object (as long as it's Traversable which basically anything of interest to you would be), you can get the root by doing root = someObject.getPhysicalRoot(). Nope, I don't have a reference to a persistent object. I'm looking at the code in smtpserver.SMTPServer and trying to figure out what I need to adjust. As far as I can tell, the only point in that code at which a 'link' to zope/zodb objects is made is in the following call in SMTPChannel.process_message: handle(self.server.module, request, response) My immediate problem is that I don't understand how the result of this call gets dealt with. It just seems to get discarded in the smtpserver code. If this is the way to interact with the publisher, how do I get hold of the return value? I'm assuming that by adjusting the REQUEST['PATH_INFO'] value before calling handle(), I can affect which ZODB object/method gets called, but I want to know the result of this call. Any ideas? tim ___ 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] connecting server code to the ZODB
Paul Winkler said: What I really want to be able to do from the server code is something like:: root = magic_that_gets_me_zodb_root() That magic is basically (from memory): import Zope Zope.startup() root = Zope.app() But note that starting up a zope is slow, so you don't want to do that very often. Well, in this case zope is already running. Ok, so I could simply drop the Zope.startup() line and things would be fine (and quick), right? I think you should use the existing publisher machinery. Given an SMTPRequest instance foo, you should be able to do foo.traverse(path, response) and get back an object. This monster method is defined in ZPublisher/BaseRequest.py What does using foo.traverse() buy me over simply accessing the ZODB objects 'by hand', as in root = Zope.app()? It seems I get security by using foo.traverse() - although I'm not sure whether that is really necessary for my purposes. Would it also deal with any ZODB transaction stuff for me that I would otherwise have to sort out - get_transaction().commit(). If I'm just reading ZODB objects (not writing), does the transaction stuff even matter? thanks, tim ___ 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] connecting server code to the ZODB
On Mon, Nov 08, 2004 at 11:22:13AM -, Tim Hicks wrote: Paul Winkler said: What I really want to be able to do from the server code is something like:: root = magic_that_gets_me_zodb_root() That magic is basically (from memory): import Zope Zope.startup() root = Zope.app() But note that starting up a zope is slow, so you don't want to do that very often. Well, in this case zope is already running. Ok, so I could simply drop the Zope.startup() line and things would be fine (and quick), right? I haven't tried it, but I think doing Zope.app() will try to acquire a lock on the database and it is already locked by the running Zope (or ZEO). So I don't think you can do that. I think you should use the existing publisher machinery. Given an SMTPRequest instance foo, you should be able to do foo.traverse(path, response) and get back an object. This monster method is defined in ZPublisher/BaseRequest.py What does using foo.traverse() buy me over simply accessing the ZODB objects 'by hand', as in root = Zope.app()? Well, for one thing it might actually work ;-) Note, I'm not sure what your code looks like - if you already have a reference to any persistent object (as long as it's Traversable which basically anything of interest to you would be), you can get the root by doing root = someObject.getPhysicalRoot(). It seems I get security by using foo.traverse() - although I'm not sure whether that is really necessary for my purposes. Would it also deal with any ZODB transaction stuff for me that I would otherwise have to sort out - get_transaction().commit(). If I'm just reading ZODB objects (not writing), does the transaction stuff even matter? I'm afraid I don't know either of those, I've never tried to hook into zope from within a ZServer server. Generally a transaction runs for the duration of one request, but I am not clear on who manages that: is it ZPublisher? It looks like transactions are managed in ZPublisher/Publish.py, but I have never looked at that code and don't have time to figure it out now. Sorry. -- Paul Winkler http://www.slinkp.com ___ 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] connecting server code to the ZODB
In article [EMAIL PROTECTED] you write: Hi, I'm trying to figure out how to adjust Nikolay Kim's smtpserver code http://cvs.sourceforge.net/viewcvs.py/collective/smtpserver/ so that objects within the ZODB can affect the way that messages are received (i.e. veto messages based on certain criteria in the first instance). My problem is that I don't quite know how to get hold of the ZODB objects. As far as I can tell, Nikolay's smtpserver.SMTPServer.SMTPChannel.process_message method uses ZServer.PubCore.handle to make the connection, but I don't really understand how this all works. What I really want to be able to do from the server code is something like:: root = magic_that_gets_me_zodb_root() That magic is basically (from memory): import Zope Zope.startup() root = Zope.app() But note that starting up a zope is slow, so you don't want to do that very often. Florent account_manager = root['Control_Panel']['AccountManager'] account_manager.checkAccepts(msg) I want calls like that to checkAccepts(msg) to be made a several points in the SMTP session - say after each of the SMTP commands RCPT, MAIL, DATA, etc. I only mention that in case there are implications for some transaction jiggery-pokery (although I don't expect any of the checkAccepts() type calls to need to write to the ZODB). Any pointers much appreciated. tim ___ 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 RD +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 )
[Zope-dev] connecting server code to the ZODB
Hi, I'm trying to figure out how to adjust Nikolay Kim's smtpserver code http://cvs.sourceforge.net/viewcvs.py/collective/smtpserver/ so that objects within the ZODB can affect the way that messages are received (i.e. veto messages based on certain criteria in the first instance). My problem is that I don't quite know how to get hold of the ZODB objects. As far as I can tell, Nikolay's smtpserver.SMTPServer.SMTPChannel.process_message method uses ZServer.PubCore.handle to make the connection, but I don't really understand how this all works. What I really want to be able to do from the server code is something like:: root = magic_that_gets_me_zodb_root() account_manager = root['Control_Panel']['AccountManager'] account_manager.checkAccepts(msg) I want calls like that to checkAccepts(msg) to be made a several points in the SMTP session - say after each of the SMTP commands RCPT, MAIL, DATA, etc. I only mention that in case there are implications for some transaction jiggery-pokery (although I don't expect any of the checkAccepts() type calls to need to write to the ZODB). Any pointers much appreciated. tim ___ 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 )