[Twisted-Python] Surprises in twisted.web.woven

Tim Allen screwtape at froup.com
Mon Aug 4 03:47:13 MDT 2003


On Monday, Aug 4, 2003, at 01:37 Australia/Sydney, Alex Levy wrote:

> On Sun, Aug 03, 2003 at 11:05:48PM +1000, Tim Allen wrote:
>> I had a little play with Woven tonight, and I'm pleased to report that
>> I'm (slowly) getting my head around it quite satisfyingly. However, I
>> did come across some things which surprised me - I'm not going to call
>> them bugs, because I don't understand Woven well enough.
>
> Don't you know anything about software development? These are FEATURES 
> :)

Oh, right, my bad. :)

> You've hit a problem that I encountered as well; the root element in a 
> Woven
> template doesn't behave the same way as its child elements. What you 
> want is
> this:
>
>   class TestContent(view.View):
>     template = """
>     <div><ul model="sampleList" view="List">...</ul></div>
>     """
>
> I believe this is one of those "just accept it" situations. 
> Fortunately,
> wrapping your work in <div></div>'s isn't that bad; they don't affect 
> layout
> (unless your CSS puts padding on every div, which is nuts), and HTML
> pretty-printing has been added to CVS in time for the next release.

Donovan Preston writes that he considers it a bug, I have faith he'll 
get around to it eventually, that's good enough for me. (Last time I 
wrote, I asked for HTML pretty-printing, and lo and behold, here it is. 
:)

> On to your models question. Views must be given a model to operate 
> on; they
> do not (as far as I know) intrinsically contain models of their own.

Ahh, that makes sense.

I was being misled by the special case of Page - Page inherits from 
View, but uses itself as the default model. Apparently other things 
that inherit from View have different behaviour.

<snip>

>> Finally, if I have a template that looks like this:
>>
>>     <p>Have a look at
>>     <a href="cat1.png">these</a>
>>     <a href="cat2.png">three</a>
>>     <a href="cat3.png">cats</a>.</p>
>>
>> then the output HTML looks like:
>>
>>     <p>Have a look at <a href="cat1.png">these</a><a
>>     href="cat2.png">three</a><a href="cat3.png">cats</a>.</p>
>
> This is another issue that I've wrangled with for some time. Feel free 
> to
> make a lot of noise and hope somebody fixes it; I believe the problem 
> lies
> in the XML parser itself. As Wayne so aptly put it, "We fear change."

Hmm. How sad.

I guess I'll have a look at the XML parser, if I have time.

> The two quick fixes I've employed to get around this until a better 
> solution
> presents itself are either   entities after every anchor, or 
> using CSS
> to add spacing. [The second option is, in my opinion, much cleaner.]

Cleaner, yes, but not much. :(

Also, I'm imagining this same problem could crop up among hetereogenous 
collections of tags, in which case CSS isn't quite as useful.

> I'm not entirely happy with this, but it makes my pages look nice 
> until any
> issues with the XML parser get hammered out.

As an interim step, sure.

> As far as chomping off docstrings, that's something you might want to 
> add to
> the tracker <http://www.twistedmatrix.com/bugs>. I see it happening on 
> my
> site as well, and Woven probably shouldn't be doing that.

Well, I was going to try fixing this little issue so I spent a while 
tracing code and learning the structure of view.View and so forth, 
until I discovered the following snippet in 
microdom.Document.writexml():

         if self.doctype:
             stream.write("<!DOCTYPE "+self.doctype+">" + newl)

And lo and behold, ever since I discovered that, it's been working fine.

Maybe I should subscribe to the CVS commits list as well before I start 
poking around in Twisted again. :)





More information about the Twisted-Python mailing list