Personal tools
You are here: Home 博客群 兴致所至 今晚对付zope3之request和response
Log in


Forgot your password?
Recent Comments
 #注释问题 (Anonymous User) 2008-10-23
 谢谢,不过好像还不是很完善 (Anonymous User) 2006-10-25
 haha (Anonymous User) 2006-03-26
 能不能弄成支持ZPT阿 (taoyh) 2006-02-12
 随便 (ghiewa) 2005-02-19
 
Document Actions

今晚对付zope3之request和response 今晚对付zope3之request和response

Submitted by shinejoys. on 2005-12-06 08:10. Zope3

request和response之于web就如一呼一吸之于生命.

我们在zope3上所做的一切都是以其为最终服务对象.因此了解 zope3接收request到输出response的过程很有必要.在zpt 页等对象中我们可以用request变量引用本次请求的request对象,那么这个对象在哪里形成而让我们现成的引用呢?这个对象又包含哪些元素呢?为了弄清这个问题,我先看了zope3 book的第40 章---- the life of a request,再看了zope3 的原代码zope.server和 zope.publisher包,还有就是ThreadedAsyc包.从zope 启动开始到socket接受请求到request对象定义到请求对象(URL)的发布(定位及执行)到response的生成及输出.不求细节,只求脉络和框架.这个过程在zope3 book第40章有讲解,但是要清楚知道 request和response对象定义,必须看原代码,在zope\server\http\publisherhttpserver.py中

class PublisherHTTPServer(HTTPServer):
    """Zope Publisher-specific HTTP Server"""

    def __init__(self, request_factory, sub_protocol=None, *args, **kw):

        # The common HTTP
        self.request_factory = request_factory

        # An HTTP server is not limited to serving up HTML; it can be
        # used for other protocols, like XML-RPC, SOAP and so as well
        # Here we just allow the logger to output the sub-protocol type.
        if sub_protocol:
            self.SERVER_IDENT += ' (%s)' %str(sub_protocol)

        HTTPServer.__init__(self, *args, **kw)

    def executeRequest(self, task):
        """Overrides HTTPServer.executeRequest()."""
        env = task.getCGIEnvironment()
        instream = task.request_data.getBodyStream()

        request = self.request_factory(instream, task, env)
        response = request.response
        response.setHeaderOutput(task)
        response.setHTTPTransaction(task)
        publish(request)

 

现在可以知道这个我们可以在页面和脚本中引用的request对象是什么样子的了,可以在zope3 API DOCS 里查看zope.publisher.interfaces

对应的接口提供哪些元素供引用,而且可以查得 response是 request的一个元素(其实从上面的代码中也能看出这点).

有错误之处请指正,希望能看到各位的学习方法和心得,让我可以走上捷径.

接下来的问题是zope3怎么根据zcml装配的问题了,现在还是一头雾水,希望能够通过努力在最近解决掉.

 


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: