Professional Documents
Culture Documents
Wsgi PDF
Wsgi PDF
Armin Ronacher
http://lucumr.pocoo.org/ // armin.ronacher@active-4.com // http://twitter.com/mitsuhiko
About Me
•Because I care
•Knowing what’s broken makes
fixing possible
!"#!"##$%&"'%()*+),%-().!/'"-'0-+/#()/+12
!!!!3+"4+-/!5!6*78()'+)'9:;#+7.!7'+<'=#$"%)71>
!!!!/'"-'0-+/#()/+*7?@@!AB7.!3+"4+-/1
!!!!$"%&$'!67C+$$(!D(-$4E7>
Is this WSGI?
!"#!"##$%&"'%()*+),%-().!/'"-'0-+/#()/+12
!!!!3+"4+-/!5!6*78()'+)'9:;#+7.!7'+<'=#$"%)71>
!!!!/'"-'0-+/#()/+*7?@@!AB7.!3+"4+-/1
!!!!()"*!!7C+$$(!D(-$4E7
WSGI is slightly flawed
• Trailers
• Hop-by-Hop Headers
• Chunked Responses (?)
WSGI in the Real World
• no more bytestring
• instead we have byte objects that
behave like arrays with string
methods
!!!"!"##$%&!'((')!"##$%&!
*&)+
!!!"$!"##$%&!'(('!"##$%&!
,%-.+
Other changes
New IO System
• urllib is unicode
• sys.stdin is unicode
• os.environ is unicode
• HTTP / WSGI are not unicode
What the stdlib does
regarding urllib:
the os module:
• Environment is unicode
• But not necessarily in the operating system
• Decode/Encode/Decode/Encode?
What the stdlib does
in the environ:
• HTTP_COOKIE
• SERVER_SOFTWARE
• PATH_INFO
• SCRIPT_NAME
Non-ASCII things
in the headers:
• Set-Cookie
• Server
What does HTTP say?
this code:
!"#$#%&'()*!+,-.+/0.+1
23!#4,56#"*/7,#'8#!"9
####:;4,5<#$#"*/7,(:,%3:,0%=*!+,>1
URL Parsing [py3x]
becomes this:
!"#$#7!//'?()*!+,()*!+,-.+/0.+1
23!#4,56#"*/7,#'8#!"9
####:;4,5<#$#"*/7,
)*>=#$#,8"'!38;@ABCD-EFGH@<#I
#######(:,%3:,0@7>2JK@6#@!,)/*%,@1
Common Env [py3x]
looks like this in 3.x:
)*>=#$#,8"'!38;@ABCD-EFGH@<#I
#######(,8%3:,0@'+3JKKLMJN@1
#######(:,%3:,0@7>2JK@6#@!,)/*%,@1
Middlewares in [py2x]
this common pattern:
!"#$%&!!'"()*"+),,-.
$$!"#$/"(0),,+"/1&*2/3$45)*50*"4,2/4"-.
$$$$&4065%'$7$89
$$$$!"#$/"(045)*50*"4,2/4"+45)5:43$6")!"*43
$$$$$$$$$$$$$$$$$$$$$$$$$$$";<0&/#27=2/"-.
$$$$$$&#$)/>+?@'2("*+-$77$A<2/5"/5B5>,"A$)/!
$$$$$$$$$$$$$1@4,'&5+ACA-8D9@45*&,+-$77$A5";5E65%'A-.
$$$$$$$$&4065%'@),,"/!+F*:"-
$$$$$$*"5:*/$45)*50*"4,2/4"+45)5:43$6")!"*43$";<0&/#2-
$$$$*1$7$),,+"/1&*2/3$/"(045)*50*"4,2/4"-
$$$$@@@
$$*"5:*/$/"(0),,
Middlewares in [py3x]
becomes this:
!"#$520G>5"4+;-.
$$*"5:*/$;@"/<2!"+A&42BHHIJBKA-$&#$&4&/45)/<"+;3$45*-$"'4"$;
!"#$%&!!'"()*"+),,-.
$$!"#$/"(0),,+"/1&*2/3$45)*50*"4,2/4"-.
$$$$&4065%'$7$89
$$$$!"#$/"(045)*50*"4,2/4"+45)5:43$6")!"*43
$$$$$$$$$$$$$$$$$$$$$$$$$$$";<0&/#27=2/"-.
$$$$$$&#$)/>+520G>5"4+?@'2("*+--$77$GA<2/5"/5B5>,"A$)/!
$$$$$$$$$$$$$520G>5"4+1-@4,'&5+GACA-8D9@45*&,+-$77$GA5";5E65%'A-.
$$$$$$$$&4065%'@),,"/!+F*:"-
$$$$$$*"5:*/$45)*50*"4,2/4"+45)5:43$6")!"*43$";<0&/#2-
$$$$*1$7$),,+"/1&*2/3$/"(045)*50*"4,2/4"-
$$$$@@@
$$*"5:*/$/"(0),,
My Prediction
possible outcome: