| Home | Trees | Indices | Help |
|
|---|
|
|
object --+
|
Application
An application.
Simple example:
>>> from smisk import Application >>> class MyApp(Application): >>> def service(self): >>> self.response.write('<h1>Hello World!</h1>') >>> >>> MyApp().run()
Example of standalone/listening/slave process:
>>> import smisk >>> class MyApp(smisk.Application): >>> def service(self): >>> self.response.write('<h1>Hello World!</h1>') >>> >>> from smisk.core import bind >>> smisk.bind('hostname:1234') >>> MyApp().run()
It is also possible to use your own types to represent Requests and Responses. You set request_class and/or response_class to a type, before application_will_start() has been called. For example:
>>> from smisk import Application, Request >>> class MyRequest(Request): >>> def from_internet_explorer(self): >>> return self.env.get('HTTP_USER_AGENT','').find('MSIE') != -1 >>> >>> class MyApp(Application): >>> def __init__(self): >>> super(MyApp, self).__init__() >>> self.request_class = MyRequest >>> >>> def service(self): >>> if self.request.from_internet_explorer(): >>> self.response.write('<h1>Good bye, cruel World!</h1>') >>> else: >>> self.response.write('<h1>Hello World!</h1>') >>> >>> MyApp().run()
| Instance Methods | |||
|
|||
| a new object with type S, a subtype of T |
|
||
|
|||
|
|||
| None |
|
||
| None |
|
||
| None |
|
||
| None |
|
||
|
Inherited from |
|||
| Static Methods | |||
| Application |
|
||
| Properties | |
| Request | request |
| Type |
request_class Must be set before calling run() |
| Response | response |
| Type |
response_class Must be set before calling run() |
| smisk.session.Store | sessions |
| Type |
sessions_class Must be set before first access to sessions |
| bool |
show_traceback Defaults to True. |
|
Inherited from |
|
| Method Details |
|
|
Called when the application stops accepting incoming requests. The default implementations does nothing. It's ment to be overridden. :rtype: None |
Called just before the application starts accepting incoming requests. The default implementations does nothing. It's ment to be overridden. :rtype: None |
Service a error message. You might override this to display a custom error response, but it is recommended you use this implementation, or at least filter certain higher level exceptions and let the lower ones through to this handler. Normally, this is what you do: >>> class MyApp(Application): >>> def error(self, typ, val, tb): >>> if issubclass(MyExceptionType, typ): >>> self.nice_error_response(typ, val) >>> else: >>> Application.error(self, typ, val, tb) >>> What is sent as response depends on if output has started or not: If output has started, if Response.has_begun is True, calling this method will insert a HTML formatted error message at the end of what has already been sent. If output has not yet begun, any headers set will be discarded and a complete HTTP response will be sent, including the same HTML message describet earlier. If show_traceback evaluates to true, the error message will also include a somewhat detailed backtrace. You should disable show_traceback in production environments.
See Also: Response.has_begun |
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sun May 11 20:25:44 2008 | http://epydoc.sourceforge.net |