Skip to content

Instantly share code, notes, and snippets.

@aodag
Created April 21, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/6ecce88611d1f22ee11be8b861b97dbf to your computer and use it in GitHub Desktop.
Save aodag/6ecce88611d1f22ee11be8b861b97dbf to your computer and use it in GitHub Desktop.
zope.publisher に最低限のpublicationを使って Hello, world
from zope.publisher.paste import Application
from zope.publisher.interfaces import IPublication
from zope.interface import implementer
from zope.component import getGlobalSiteManager
@implementer(IPublication)
class MyWorkPublication:
def __init__(self, global_conf, **app_conf):
pass
def beforeTraversal(self, request):
"""Pre-traversal hook.
This is called *once* before any traversal has been done.
"""
print("beforeTraversal")
def getApplication(self, request):
"""Returns the object where traversal should commence.
"""
print("getApplication")
return {}
def callTraversalHooks(self, request, ob):
"""Invokes any traversal hooks associated with the object.
This is called before traversing each object. The ob argument
is the object that is about to be traversed.
"""
print("callTraversalHooks")
def traverseName(self, request, ob, name):
"""Traverses to the next object.
Name must be an ASCII string or Unicode object."""
print("traverseName %s" % name)
def afterTraversal(self, request, ob):
"""Post-traversal hook.
This is called after all traversal.
"""
print("afterTraversal")
def callObject(self, request, ob):
"""Call the object, returning the result.
For GET/POST this means calling it, but for other methods
(including those of WebDAV and FTP) this might mean invoking
a method of an adapter.
"""
print("callObject %s" % ob)
return "Hello"
def afterCall(self, request, ob):
"""Post-callObject hook (if it was successful).
"""
print("afterCall")
def handleException(self, object, request, exc_info, retry_allowed=1):
"""Handle an exception
Either:
- sets the body of the response, request.response, or
- raises a Retry exception, or
- throws another exception, which is a Bad Thing.
"""
print("handleException %s" % exc_info)
def endRequest(self, request, ob):
"""Do any end-of-request cleanup
"""
print("endRequest")
def getDefaultTraversal(self, request, ob):
return ob, None
class MyWorkApplication(Application):
def __init__(self, global_conf, **app_conf):
self.publication = MyWorkPublication(global_conf, **app_conf)
def make_app(global_conf, **app_conf):
return MyWorkApplication(global_conf, **app_conf)
def main():
import plaster
loader = plaster.loaders.get_loader("development.ini", protocols=["wsgi"])
app = loader.get_wsgi_app()
server = loader.get_wsgi_server()
server(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment