An application.
Simple example:
from smisk.core import Application
class MyApp(Application):
def service(self):
self.response.write('<h1>Hello World!</h1>')
MyApp().run()
Example of standalone/listening/slave process:
from smisk.core import Application, bind
class MyApp(Application):
def service(self):
self.response.write('<h1>Hello World!</h1>')
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.core 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()
Current application instance, if any. Class attribute.
| See: | smisk.core.app |
|---|
Number of child processes to fork off into.
This must be set before calling run(), as it’s in run() where the forking goes down. Defaults to 0 (disabled).
New in version 1.1.
Called when the application stops accepting incoming requests.
The default implementation does nothing.
Called just before the application starts accepting incoming requests.
The default implementation does nothing.
Handle an error and produce an appropriate response.
The built-in implementation renders error information as XHTML encoded in UTF-8 with the HTTP status code 500 (Internal Server Error).
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 isinstance(val, MyExceptionType):
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 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 described 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.
| Parameters: |
|
|---|