• Like
WSGI, Repoze, Deliverence
Upcoming SlideShare
Loading in...5
×
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,763
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
37
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. WSGI, Repoze, Deliverence Mykola Kharechko © Quintagroup, 2008
  • 2. Overview
    • Connection between WSGI, Repoze, Deliverance
    • WSGI
    • Repoze
    • Deliverance
  • 3. Connection between WSGI, Repoze, Deliverance WSGI WSGI Zope Repoze Deliverance
  • 4. WSGI – The Problem ● Lots of web frameworks: Zope, Quixote, Webware, SkunkWeb and Twisted Web etc. ● Applications written for one framework often weren't compatible with the server components of the others ● Made the choosing a Python web framework hard as there were so many different and incompatible options ● The PEP compares the situation to Java which had its Servelet API
  • 5. WSGI `Hello World`
    • from wsgiref import simple_server
    • def app(env, start_response):
    • start_response('200 OK', [('Content-type', 'text/html')])
    • return ['<h1>Hello, World!</h1>']
    • server=simple_server.make_server('', 8000, app)
    • server.serve_forever()
  • 6. What makes this a WSGI application
    • ● It is a callable (in this case a simple function)
    • taking environ and start_response as
    • positional parameters.
    • ● It calls start_response() with a status code
    • and a list of tuple pairs of headers before it
    • returns a value. It should only be called
    • once.
    • ● The response it returns is an iterable (in this
    • case a list with just one string).
  • 7. WSGI - Middleware 1. Acts like a WSGI application 2. Follows the WSGI Spec 3. Looks like a server to another piece of middleware or an application 4. Could decide to give its own response, or call your app
  • 8. WSGI Middleware Example try: my_app_resp = my_app(env, my_start_response) start_response(status, header) except: start_response('500 Internal error', some_headers) my_app_resp = ['Sorry'] return my_app_resp
  • 9. WSGI Summary ● WSGI isn't too complicated ● If your app is WSGI compliant you can instantly deploy it on a number of servers ● There are lots of powerful tools and middleware already in existence and you can easily re-use them -> see wsgi.org ● I'll be talking about Pylons later today which is one of the first projects to use WSGI throughout its stack.
  • 10. Repoze – The Problem
    • Zope isn't compatible with WSGI
  • 11. Top-Level Packages
    • repoze.zope2
    • repoze.plone
    • repoze.grok
  • 12. repoze.zope2
    • Re-implementation of Zope 2's ZPublisher to fit into a WSGI stack &quot;natively&quot;.
    • As a result, run Zope2 within Apache using mod_wsgi.
    • Goal: 100% backwards compatibility with all Zope 2 products.
    • Goal: 100% egg-based package installation.
    • Goal: move many Zope 2 features out into middleware.
  • 13. Repoze - Installing and Starting
    • easy_install and virtualenv based via http://repoze.org/quickstart.html.
    • Buildout-based via http://svn.repoze.org/buildouts.
    • bin/paster serve etc/zope2.ini
  • 14. Motivation to Deliverance
    • Zope and Content Management System forces web designers to learn a complex page templating language. It makes designing web pages slow to develop and hard to debug. There should be an easier way to take the content from a CMS and style it in various ways without understanding the architecture of the CMS and without even knowing the origin of the content. This would create a formal distinction between content production and content delivery.
  • 15. Deliverance Components
    • The content is the information you want to style with the theme. It can be a live website or a static file, specified with a URI.
    • The theme contains the style and layout information you want to apply to the content. It can be a live website or a static file, specified with a URI.
    • The rules tell Deliverance how to apply the theme to the content.
  • 16. Introduction example
    • Content: <html><body><div id=&quot;bar&quot;>Real Content</div></body></html>
    • Theme:<html><head><title>Blah</title></head><body><div id=&quot;foo&quot;>Dummy Content</div></body></html>
    • Rule: <replace theme=&quot;//div[@id='foo']&quot; content=&quot;//div[@id='bar']&quot; />
    • Result:<html><head><title>Blah</title></head><body><div id=&quot;bar&quot;>Real Content</div></body></html>
  • 17. Deliverance. Simple Example. Page with content <html> <head> <title>my boring todo page</title> <head> <body> <div id=&quot;todo&quot;> <h1>Things To Do</h1> <ul> <li>Feed the cat</li> <li>Wash the dishes</li> </ul> </div> </body> </html>
  • 18. Deliverance. Simple Example. Page with theme <html> <head> <style type=&quot;text/css&quot;> div {background: #00ffdd;} li {list-style-type: disc;} </style> <title>my exciting home page</title> </head> <body> <h1>Deliverance User's Exciting Page</h1> <div id=&quot;wishes&quot;> I wish my todo list looked this cool </div> </body> </html>
  • 19. Deliverance. Simple Example. Rule File <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <rules xmlns=&quot;http://www.plone.org/deliverance&quot; > <replace theme=&quot;//div[@id='wishes']&quot; content=&quot;//div[@id='todo']&quot; /> </rules>
  • 20. Deliverance. Simple Example. Output div {background: #00ffdd;} li {list-style-type: disc;} </style> <title>my exciting home page</title> </head> <body> <h1>Deliverance User's Exciting Page</h1> <div id=&quot;todo&quot;> <h1>Things To Do</h1> <ul> <li>Feed the cat</li> <li>Wash the dishes</li> <ul>
  • 21. Deliverance directives
    • append-or-replace
    • replace
    • move
    • copy
    • prepend
    • drop
  • 22. Deliverance. Interacting with other wsgi applications Some WSGI-app with html content Deliverance Theme site Browser
  • 23. Deliverence Problems
    • Does not work with curve/wrong HTML
    • Includes only basic XSL Transformations
    • XPath requires additional library
  • 24. The End