bloodhound-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matevz Bradac <>
Subject Re: Genshi XHTML + HTML 5
Date Sun, 02 Dec 2012 17:45:14 GMT
I tried solving this on the stream level, but no luck so far. First I
implemented a test wrapper for the stream:
class BloodhoundStream(Stream):
    # Stream is using __slots__, so the subclass should as well
    __slots__ = []

    def render(self, method=None, encoding='utf-8', out=None, **kwargs):
        kwargs['doctype'] = DocType.HTML5
        super(BloodhoundStream, self).render(method, encoding, out, **kwargs)

and in the filter stream I changed the stream's type using:
  stream.__class__ = BloodhoundStream

The Stream however defines an __or__ operator (for chaining purposes)
and that one returns back
a Stream object. So I defined and __or__ in the BloodhoundStream as well:
    def __or__(self, function):
        return BloodhoundStream(_ensure(function(self)),

This still doesn't work, because Chrome's render_template() uses
Template.generate() for the initial
stream, and that one returns Stream as well. Since this is the first
Stream in line, all the subsequent
BloodhoundStream objects also become Stream (Stream | BloodhoundStream
| BloodhoundStream
produces a Stream in the end).

Due to the above complications (and those not yet discovered), I'd say
it would be easier and less error-prone
to just override the genshi.output.get_serializer() with BH's wrapper.
The function is pretty trivial and unlikely
to change much, so it looks like a safe alternative.


On Sat, Dec 1, 2012 at 6:13 PM, Olemis Lang <> wrote:
> On 12/1/12, Matevz Bradac <> wrote:
>> Thanks for the suggestion, but unfortunately it won't work on the
>> instance level. =/
> :'(
>> The Stream class is using __slots__, so most instance attributes are
>> read-only, e.g. this:
>>     import types
>>     stream.render = types.MethodType(new_render, stream)
>> doesn't work - AttributeError exception.
> I see .
>> Brane suggested monkeypatching on a class/module level, so maybe
>> genshi.core.Stream.serialize(),
>> or even genshi.output.get_serializer() would be good candidates.
> that's risky . I'd really suggest to try to solve this at stream level
> since monkey patching at module level may be a serious matter .
> FWIW ... most of the time I advocate for wrapping rather than monkey
> patching , because it's easier to deal with the impact and scope of
> the changes .
> --
> Regards,
> Olemis.
> Blog ES:
> Blog EN:
> Featured article:

View raw message