Get rid of tabs that sneaked into sample code.
This commit is contained in:
parent
24bd216f0c
commit
110c3a33a3
54
pep-0333.txt
54
pep-0333.txt
|
@ -253,7 +253,7 @@ server.
|
||||||
# Re-raise original exception if headers sent
|
# Re-raise original exception if headers sent
|
||||||
raise exc_info[0], exc_info[1], exc_info[2]
|
raise exc_info[0], exc_info[1], exc_info[2]
|
||||||
finally:
|
finally:
|
||||||
exc_info = None # avoid dangling circular ref
|
exc_info = None # avoid dangling circular ref
|
||||||
elif headers_sent:
|
elif headers_sent:
|
||||||
raise AssertionError("Headers already sent!")
|
raise AssertionError("Headers already sent!")
|
||||||
|
|
||||||
|
@ -263,8 +263,8 @@ server.
|
||||||
result = application(environ, start_response)
|
result = application(environ, start_response)
|
||||||
try:
|
try:
|
||||||
for data in result:
|
for data in result:
|
||||||
if data: # don't send headers until body appears
|
if data: # don't send headers until body appears
|
||||||
write(data)
|
write(data)
|
||||||
if not headers_sent:
|
if not headers_sent:
|
||||||
write('') # send headers now if body was empty
|
write('') # send headers now if body was empty
|
||||||
finally:
|
finally:
|
||||||
|
@ -329,20 +329,20 @@ a block boundary.)
|
||||||
its first non-empty string, so 'transform_ok' has to be a mutable
|
its first non-empty string, so 'transform_ok' has to be a mutable
|
||||||
truth value."""
|
truth value."""
|
||||||
|
|
||||||
def __init__(self,result,transform_ok):
|
def __init__(self,result,transform_ok):
|
||||||
if hasattr(result,'close'):
|
if hasattr(result,'close'):
|
||||||
self.close = result.close
|
self.close = result.close
|
||||||
self._next = iter(result).next
|
self._next = iter(result).next
|
||||||
self.transform_ok = transform_ok
|
self.transform_ok = transform_ok
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
if self.transform_ok:
|
if self.transform_ok:
|
||||||
return piglatin(self._next())
|
return piglatin(self._next())
|
||||||
else:
|
else:
|
||||||
return self._next()
|
return self._next()
|
||||||
|
|
||||||
class Latinator:
|
class Latinator:
|
||||||
|
|
||||||
|
@ -361,28 +361,28 @@ a block boundary.)
|
||||||
for name,value in headers:
|
for name,value in headers:
|
||||||
if name.lower()=='content-type' and value=='text/plain':
|
if name.lower()=='content-type' and value=='text/plain':
|
||||||
transform_ok.append(True)
|
transform_ok.append(True)
|
||||||
# Strip content-length if present, else it'll be wrong
|
# Strip content-length if present, else it'll be wrong
|
||||||
headers = [(name,value)
|
headers = [(name,value)
|
||||||
for name,value in headers
|
for name,value in headers
|
||||||
if name.lower()<>'content-length'
|
if name.lower()<>'content-length'
|
||||||
]
|
]
|
||||||
break
|
break
|
||||||
|
|
||||||
write = start_response(status,headers,exc_info)
|
write = start_response(status,headers,exc_info)
|
||||||
|
|
||||||
if transform_ok:
|
if transform_ok:
|
||||||
def write_latin(data):
|
def write_latin(data):
|
||||||
write(piglatin(data))
|
write(piglatin(data))
|
||||||
return write_latin
|
return write_latin
|
||||||
else:
|
else:
|
||||||
return write
|
return write
|
||||||
|
|
||||||
return LatinIter(self.application(environ,start_latin),transform_ok)
|
return LatinIter(self.application(environ,start_latin),transform_ok)
|
||||||
|
|
||||||
|
|
||||||
# Run foo_app under a Latinator's control, using the example CGI gateway
|
# Run foo_app under a Latinator's control, using the example CGI gateway
|
||||||
from foo_app import foo_app
|
from foo_app import foo_app
|
||||||
run_with_cgi(Latinator(foo_app))
|
run_with_cgi(Latinator(foo_app))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -752,7 +752,7 @@ involved. The simplest way to do this is something like::
|
||||||
try:
|
try:
|
||||||
# do stuff w/exc_info here
|
# do stuff w/exc_info here
|
||||||
finally:
|
finally:
|
||||||
exc_info = None # Avoid circular ref.
|
exc_info = None # Avoid circular ref.
|
||||||
|
|
||||||
The example CGI gateway provides another illustration of this
|
The example CGI gateway provides another illustration of this
|
||||||
technique.
|
technique.
|
||||||
|
|
Loading…
Reference in New Issue