[Twisted-Python] Conch text attribute flattening quirks

Jonathan Jacobs jonathan+twisted at jsphere.com
Wed Feb 22 06:47:46 EST 2012


I'm hoping to wrap up work on ticket #3844 [1] before the next release of Twisted, however there are a few quirks in the small DSL used for specifying text with attributes (see the ticket for some commentary on these.)

I decided to look more closely at what happens with Conch (which is where the DSL originally came from and has remained largely unchanged) in some of the places I was having problems with the IRC formatting. I was struck by something that looks like it is rather incorrect behaviour (on Twisted trunk as of 2012/2/22 and Twisted 11.0.0 on Debian):

>>> from twisted.conch.insults.helper import CharacterAttribute
>>> from twisted.conch.insults.text import flatten, attributes as A
>>> flatten(A.normal['hello', A.bold[' world '], 'quux'], CharacterAttribute())
'hello\x1b[1m world quux'

My expectations are that only " world " will be marked up with bold attributes, since it is the only piece of content in the "bold" attribute, while "hello" and "quux" both appear in normal text, i.e. without any additional markup. Looking at the output you can see that "hello" appears as normal text and then " world quux" appears in bold.

Is this the expected behaviour? There are no tests that actually test this particular case, as far as I can tell, except for twisted.conch.test.test_text.EfficiencyTestCase but that is marked as "todo" (the tests themselves do indeed fail.) While the name of this test case indicates tests for efficient markup, as far as I can tell these tests also assume (and fail) that the structure is flattened the same way I was expecting.

Any guidance would be appreciated.


[1] <http://twistedmatrix.com/trac/ticket/3844>


More information about the Twisted-Python mailing list