Sunteți pe pagina 1din 6

1

2
3
4
5
6 __ _______ _____ _____
7 \ \ / / ____|/ ____|_ _|
8 \ \ /\ / / (___ | | __ | |
9 \ \/ \/ / \___ \| | |_ | | |
10 \ /\ / ____) | |__| |_| |_
11 \/ \/ |_____/ \_____|_____|
12
13
14
15 # Python Web Server Gateway Interface #
16
17
18
19
20
21 [Alex Morega] (http://grep.ro)
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10
1
2 ### Ce este WSGI? ###
3
4 * Ce *nu* este:
5 - web framework
6 + Django, Pylons, TurboGears, Zope, repoze.bfg
7 - web server
8 + `wsgiref.simpleserver`, `mod_wsgi`,
9 flup/Paste, CherryPy
10
11 * Ce este:
12 + API pentru HTTP în Python
13 + convenții preluate din CGI
14 + minimalist
15
16 * Aplicație "hello world":
17
18 def hello_app(environ, start_response):
19 start_response('200 OK', [('Content-Type',
20 'text/plain')])
21 return ['Hello WWW!']
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10
1
2 ### Cum funcționează ###
3
4
5 * `environ`:
6 + toată informația despre request
7 - variabile CGI
8 + informație de la alte layere (middleware)
9 - chei cu litere mici, namespaced
10
11
12 * `start_response`:
13 + înseamnă "sunt gata să trimit răspunsul"
14 + status code, response headers
15
16
17 * `return`:
18 + iterator cu response body (ex. o listă)
19 + trimite răspunsul în bucăți
20
21
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10
1
2 ### Middleware ###
3
4
5 * Scopul: modificarea request-ului și/sau response-ului
6
7 * Funcționare: un middleware "îmbracă" aplicația
8 + aplicația este WSGI
9 + din afară, middleware-ul + aplicația sunt o nouă
10 aplicație WSGI
11 + turtles all the way down
12
13 UA PX S M3 M2 M1 A
14 | ===>| ===>| --->| --->| --->| --->|
15 |<=== |<=== |<--- |<--- |<--- |<--- |
16
17 UA: user agent (ex. browser) === (HTTP)
18 PX: HTTP proxy --- (WSGI)
19 S: origin server
20 M*: middleware
21 A: aplicație
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10
1
2 ### Biblioteci ###
3
4
5 * Generic WSGI:
6 + wsgiref: `simple_server`, `validate`
7 + WebOb:
8 - obiecte prietenoase de request, response, erori
9 - diverse utilitare (decoratori, middleware,
10 escaping, diverse headere)
11 + Routes: URL dispatch
12 + Werkzeug: asemănător cu WebOb, + URL dispatch
13
14 * Framework-uri: Pylons/TurboGears, BFG, Django, Zope3
15
16 * Servere: `wsgiref.simple_server`, `mod_wsgi`,
17 flup, twisted, magnum
18
19 * Middleware: weberror, toscawidgets, deliverance
20
21 * Testing: twill, zope.testbrowser
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10
1
2 ### Link-uri ###
3
4
5
6 * [WSGI] (http://wsgi.org)
7
8 * [wsgiref] (http://docs.python.org/library/wsgiref)
9
10 * [WebOb] (http://pythonpaste.org/webob)
11
12 * [Pylons] (http://pylonshq.com/docs/en/0.9.7
13 /wsgi_support)
14
15 * [PasteDeploy] (http://pythonpaste.org/deploy/
16 #the-config-file)
17
18
19
20 * [prezentare] (http://grep.ro/quickpub/rtt-wsgi)
21
22
23 --------------------------------------------------------
24 ROSEdu TechTalks, 2009/11/10

S-ar putea să vă placă și