WSGI, Repoze, Deliverence


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

WSGI, Repoze, Deliverence

  1. 1. WSGI, Repoze, Deliverence Mykola Kharechko © Quintagroup, 2008
  2. 2. Overview <ul><li>Connection between WSGI, Repoze, Deliverance </li></ul><ul><li>WSGI </li></ul><ul><li>Repoze </li></ul><ul><li>Deliverance </li></ul>
  3. 3. Connection between WSGI, Repoze, Deliverance WSGI WSGI Zope Repoze Deliverance
  4. 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. 5. WSGI `Hello World` <ul><li>from wsgiref import simple_server </li></ul><ul><li>def app(env, start_response): </li></ul><ul><li>start_response('200 OK', [('Content-type', 'text/html')]) </li></ul><ul><li>return ['<h1>Hello, World!</h1>'] </li></ul><ul><li>server=simple_server.make_server('', 8000, app) </li></ul><ul><li>server.serve_forever() </li></ul>
  6. 6. What makes this a WSGI application <ul><li>● It is a callable (in this case a simple function) </li></ul><ul><li>taking environ and start_response as </li></ul><ul><li>positional parameters. </li></ul><ul><li>● It calls start_response() with a status code </li></ul><ul><li>and a list of tuple pairs of headers before it </li></ul><ul><li>returns a value. It should only be called </li></ul><ul><li>once. </li></ul><ul><li>● The response it returns is an iterable (in this </li></ul><ul><li>case a list with just one string). </li></ul>
  7. 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. 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. 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 ● I'll be talking about Pylons later today which is one of the first projects to use WSGI throughout its stack.
  10. 10. Repoze – The Problem <ul><li>Zope isn't compatible with WSGI </li></ul>
  11. 11. Top-Level Packages <ul><li>repoze.zope2 </li></ul><ul><li>repoze.plone </li></ul><ul><li>repoze.grok </li></ul>
  12. 12. repoze.zope2 <ul><li>Re-implementation of Zope 2's ZPublisher to fit into a WSGI stack &quot;natively&quot;. </li></ul><ul><li>As a result, run Zope2 within Apache using mod_wsgi. </li></ul><ul><li>Goal: 100% backwards compatibility with all Zope 2 products. </li></ul><ul><li>Goal: 100% egg-based package installation. </li></ul><ul><li>Goal: move many Zope 2 features out into middleware. </li></ul>
  13. 13. Repoze - Installing and Starting <ul><li>easy_install and virtualenv based via </li></ul><ul><li>Buildout-based via </li></ul><ul><li>bin/paster serve etc/zope2.ini </li></ul>
  14. 14. Motivation to Deliverance <ul><li>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. </li></ul>
  15. 15. Deliverance Components <ul><li>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. </li></ul><ul><li>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. </li></ul><ul><li>The rules tell Deliverance how to apply the theme to the content. </li></ul>
  16. 16. Introduction example <ul><li>Content: <html><body><div id=&quot;bar&quot;>Real Content</div></body></html> </li></ul><ul><li>Theme:<html><head><title>Blah</title></head><body><div id=&quot;foo&quot;>Dummy Content</div></body></html> </li></ul><ul><li>Rule: <replace theme=&quot;//div[@id='foo']&quot; content=&quot;//div[@id='bar']&quot; /> </li></ul><ul><li>Result:<html><head><title>Blah</title></head><body><div id=&quot;bar&quot;>Real Content</div></body></html> </li></ul>
  17. 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. 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. 19. Deliverance. Simple Example. Rule File <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <rules xmlns=&quot;; > <replace theme=&quot;//div[@id='wishes']&quot; content=&quot;//div[@id='todo']&quot; /> </rules>
  20. 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. 21. Deliverance directives <ul><li>append-or-replace </li></ul><ul><li>replace </li></ul><ul><li>move </li></ul><ul><li>copy </li></ul><ul><li>prepend </li></ul><ul><li>drop </li></ul>
  22. 22. Deliverance. Interacting with other wsgi applications Some WSGI-app with html content Deliverance Theme site Browser
  23. 23. Deliverence Problems <ul><li>Does not work with curve/wrong HTML </li></ul><ul><li>Includes only basic XSL Transformations </li></ul><ul><li>XPath requires additional library </li></ul>
  24. 24. The End
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.