Return-Path: X-Original-To: apmail-incubator-bloodhound-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-bloodhound-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AFA7AE696 for ; Sun, 2 Dec 2012 17:46:28 +0000 (UTC) Received: (qmail 49421 invoked by uid 500); 2 Dec 2012 17:46:28 -0000 Delivered-To: apmail-incubator-bloodhound-dev-archive@incubator.apache.org Received: (qmail 49260 invoked by uid 500); 2 Dec 2012 17:46:23 -0000 Mailing-List: contact bloodhound-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bloodhound-dev@incubator.apache.org Delivered-To: mailing list bloodhound-dev@incubator.apache.org Received: (qmail 49222 invoked by uid 99); 2 Dec 2012 17:46:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Dec 2012 17:46:21 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URIBL_BLACK X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of matevzb@gmail.com designates 209.85.219.47 as permitted sender) Received: from [209.85.219.47] (HELO mail-oa0-f47.google.com) (209.85.219.47) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Dec 2012 17:46:16 +0000 Received: by mail-oa0-f47.google.com with SMTP id h1so1936907oag.6 for ; Sun, 02 Dec 2012 09:45:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=KOa98ggVhGD+qxCnhWdhdZeYWZeI1LKWL8vKqGNq/FA=; b=bXXhvKcwOUKa+YcKDwj3fqsqFMkbaIcpNRfpnzbnLBKyhckA3nTbtRpiTZ7LryQsL6 2RbluHZJb0SJxW9XkmSRC5fXS/BTsR8P8FlaLbVgDdalrPr66XBLCit1xOyNLp/NS7m7 08mKsLruS5PjRlY2yClMKJbpkKAEpW3HwkW1bo5M6YOISEoIOfnH3Aqgbazjn6QAmvP8 TU5B7kaG66f3iDOO5tH7GKB2bgtljEsX9W/6TOf0tPgbJ+LVsLZeKSlcGp3hp3KIqxYA xFgJ/iAXJLC5meuquNw3fURWdvAE4SLxXFew+MDxAwJgqyhPcCz6kP9P4+J3Y6reovYs +YrQ== Received: by 10.60.1.42 with SMTP id 10mr6083168oej.125.1354470355875; Sun, 02 Dec 2012 09:45:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.73.138 with HTTP; Sun, 2 Dec 2012 09:45:14 -0800 (PST) In-Reply-To: References: <2BA32F18-E010-433A-8E9F-359192ABA8F8@wandisco.com> From: Matevz Bradac Date: Sun, 2 Dec 2012 18:45:14 +0100 Message-ID: Subject: Re: Genshi XHTML + HTML 5 To: bloodhound-dev@incubator.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org 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)), serializer=self.serializer) 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. -- matevz 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: http://simelo-es.blogspot.com/ > Blog EN: http://simelo-en.blogspot.com/ > > Featured article: