Overview of webapp framework
webapp 框架是一种简单的与 WSGI(Web Server Gateway Interface)兼容的网络应用程序框架,可以与 App Engine 配合使用。不必为了使用 App Engine 而使用 webapp:网络服务器支持任何使用 CGI 的 Python 应用程序。webapp 提供一种简单的方式来开始为 App Engine 开发应用程序。[1]
图:GAE web系统架构示意
web框架的主要接口概述
class WSGIApplication(object): """Wraps a set of webapp RequestHandlers in a WSGI-compatible application. To use this class, pass a list of (URI regular expression, RequestHandler) pairs to the constructor, and pass the class instance to a WSGI handler. See the example in the module comments for details. The URL mapping is first-match based on the list ordering. """
该接口主要是将URL影射到RequestHandler类的对象上。
class RequestHandler(object): """Our base HTTP request handler. Clients should subclass this class. Subclasses should override get(), post(), head(), options(), etc to handle different HTTP methods. """
实际在基于webapp框架编写代码时,会定义RequestHandler类的子类来对http请求做一些特出处理(也就你自己的处理逻辑)。
class Request(webob.Request): """Abstraction for an HTTP request. Properties: uri: the complete URI requested by the user scheme: 'http' or 'https' host: the host, including the port path: the path up to the ';' or '?' in the URL parameters: the part of the URL between the ';' and the '?', if any query: the part of the URL after the '?' You can access parsed query and POST values with the get() method; do not parse the query string yourself. """
class Response(object): """Abstraction for an HTTP response. Properties: out: file pointer for the output stream headers: wsgiref.headers.Headers instance representing the output headers """
以上只是根据我的理解对webapp框架做了简单的介绍和分析,可能有偏颇之处,还请各位高手指正。
在接下来的学习中,我会具体阐述:
1. webapp 框架的应用实例分析
2. webapp 框架的接口分析
3. webapp 框架的内部实现及其与WSGI/CGI接口的关系等相关内容。