[merge][0.11] updates to rio and version_info

Aaron Bentley aaron.bentley at utoronto.ca
Fri Sep 22 17:02:09 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Arbash Meinel wrote:
> Matthew Fuller noticed that 'bzr version-info --all' fails in bzr.dev.
> This is because I'm attempting to create a nested Stanzas, and was doing
> so incorrectly. I forgot that the output of 'RioWriter()' was a utf-8
> encoded string, but that Stanza.add() requires a Unicode string.

I do wonder: would XML be a better format for this data?  It sounds like
it's tree-structured.

> Rather than doing that, I added a 'Stanza.to_unicode()' that doesn't do
> any encoding. Instead it just creates a unicode string, which can then
> be passed to a parent Stanza.

This looks fine to me.

> And then I updated read_stanza() so that it doesn't try to decode a
> string that is already Unicode.

I feel that APIs which accept bytestrings and unicode strings
interchangeabley are more trouble than they are worth.  Unicode files
are especially bad.

I'd rather see the implementation moved to read_stanza_unicode, with
read_stanza being just:

def read_stanza(line_iter)
    unicode_iterator = (l.decode('utf-8') for l in line_iter)
    return read_stanza_unicode(unicode_iterator)

> And finally, I fixed a timing bug in the version-info blackbox test.

> So instead of using 'self.assertEqual()' I created a helper that asserts
> the texts are equal except for the 'build-date' line.

Makes sense.

> The Stanza api changes are not strictly necessary. I could instead
> always .encode() or .decode() before reading/adding a child Stanza. But
> doing it this way is better for performance, and I think more natural
> for people who want to use Stanzas.

My main beef here is treating bytestrings and unicode strings as
interchangeable.  They're not usually, so that makes this a 'magic'
interface.

Though I do wonder whether nested rio really makes sense.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFFFAkB0F+nu1YWqI0RAkXCAJ9kaiu6ijkL5Tzylj4i8D3To3W0TwCfVCgN
MbgGGH60PwGRuxxmHpac8f4=
=ReYa
-----END PGP SIGNATURE-----




More information about the bazaar mailing list