[MERGE] Pass realm as a string rather than a one-tuple.

John Arbash Meinel john at arbash-meinel.com
Sat Apr 11 20:31:57 BST 2009


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

Vincent Ladeuil wrote:
>>>>>> "Jelmer" == Jelmer Vernooij <jelmer at vernstok.nl> writes:
> 
>     Jelmer> The attached patch fixes a bug in the way realm is
>     Jelmer> parsed at the moment during Basic HTTP
>     Jelmer> auth. Currently it ends up as a tuple because of the
>     Jelmer> way it is parsed, but ideally it should of course be
>     Jelmer> a string.
> 
> The http prompt tests should have caught that one, but... python
> is too helpful, the prompt is built with:
> 
>             prompt += ", Realm: '%s'" % realm
> 
> and it makes no difference here whether realm is a string or a
> tuple of length 1.
> 
>     Jelmer> We should ideally add a test for this, but I was
>     Jelmer> unsure about *where* this would have to be done.
> 
> The attached patch adds such an explicit test.
> 
>     Vincent
> 
> 

Just mentioning, that is why you shouldn't use a plain "%" for this, but
should instead do:

"...%s..." % (foo,)

Especially if you are being passed the argument you are formatting.
Considering that if the argument ends up being a 2-tuple, then you get:
  TypeError: not all arguments converted during string formatting

I'll admit it is a bit uglier, mostly because you need the trailing
comma. But it is recommended.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkng8C0ACgkQJdeBCYSNAAPbDACggWt7U/OxwZekHMHQtDa4ctF1
g5YAn1PA5EqaMWu6bWrAC8ZvZYmqVzLt
=MGcR
-----END PGP SIGNATURE-----



More information about the bazaar mailing list