Basically we need to have an executable

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: eck though as the first item may only contain the prologue and not '<html>'. These checks are only going to work for iterables if the results of publishing of each item were added to the end of a list of strings, rather than being written back immediately using req.write(). Once all that has been returned by the iterable is obtained, this can all be joined back together and then the HTML check done. Joining all the separate items returned from the iterable back together defeats the purpose of what this feature was about in the first place and may result in huge in memory objects needing to be created to hold the combined result just so the HTML check can be done. The only way to avoid the problem is for the content type to be set explicitly by the user before the iterable is processed. This is a bit tricky as it is mod_python.publisher which is automagically doing this. The best you can do is something like: class SetContentType: def __init__(self,content_type): self.__content_type = content_type def __call__(self,req): req.content_type = self.__content_type return "" index = [ SetContentType('text/html'), '<html><body><p>', 1000 * "X", '</p></body></html>', Once you start doing this, the user may as well have provided their own published function in the first place that set the content type and manually iterated over items and wrote them to req.write(). This could also be managed by a user specified wrapper class which is how I saw this as preferably being done in the first place. Ie., class PublishIterable: def __init__(self,value,content_type): self.__value = value self.__content_type = content_type def __call__(self,req): req.content_type = self.__content_type for item in self.__value: req.write(item) _values = [ '<html><body><p>', 1000 * "X", '</p></body></html>', index = PublishIterable(_values,'text/html') Personally I believe this automagic publishing of iterables shoul...
View Full Document

Ask a homework question - tutors are online