[Web-SIG] My original template API proposal

Ian Bicking ianb at colorstudy.com
Mon Feb 6 00:44:48 CET 2006

James Y Knight wrote:
> On Feb 5, 2006, at 6:17 PM, Ian Bicking wrote:
>>           ``set_header_callback`` is a function that can be called  like
>>           ``set_header_callback(header_name, header_value)``.
>>           Arguments can only be strings (not unicode) [encode unicode
>>           with ASCII?].  The header named ``'Status'`` can be used to
>>           set the status.  Even if this template is rendered in a web
>>           environment, frameworks may not provide this callback if  they
>>           do not expect or wish the template to effect the headers.
>>           This function returns an iterator which produces strings or
>>           unicode strings.  (It should produce one or the other, not
>>           both.)  Unicode is preferred.
> Now that you're re-specifying something similar to WSGI, you need to  
> consider issues like what should happen if you call the  
> set_header_callback after having yielded one string out of the  
> iterator. Is that an error, or is it silently ignored, or can the  
> container decide? Also, is the caller required to send the strings  
> returned by the iterator to the browser immediately, or can it buffer  
> it all up to send when the template iterator finishes? Or doesn't it  
> matter?

I'm not sure about order of execution -- the same as WSGI, I guess (what 
does PHP do?)  There's no promises on when the yielded strings get sent, 
or if they get sent at all.  In most cases I expect the results will be 
fully buffered.

I suspect most templates will buffer their output internally, unless 
somehow configured or dynamically set not to do so.

Ian Bicking  |  ianb at colorstudy.com  |  http://blog.ianbicking.org

More information about the Web-SIG mailing list