[PATCH] allow http authentication information to be specified in the configuration
Martin Geisler
mg at lazybytes.net
Sun May 3 14:29:42 CDT 2009
Sune Foldager <cryo at cyanite.org> writes:
> I wrote:
>
>> On 03/05/2009, at 18.59, Martin Geisler wrote:
>>
>>>> +def dumpdict(dict):
>>>> + print '{' + ', '.join(['%s: %s' % (k, dict[k]) for k in
>>>> sorted(dict.iterkeys())]) + '}'
>>> pprint.pprint does the same.
>>
>> Ah, nice!. I have yet to explore the corners and nooks of the
>> python libraries. I'll change the test code.
>
> Actually, now I remember why I did it like this: I need to be sure the
> keys are sorted, and I don't see in the pprint documentation any such
> guarentee.
Yeah, well... I sort of cheated :-) The code for pprint reveals it:
[...]
if issubclass(typ, dict) and r is dict.__repr__:
write('{')
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
length = _len(object)
if length:
context[objid] = 1
indent = indent + self._indent_per_level
items = object.items()
items.sort()
[...]
> Also, pprint might wrap the output (maybe differently on different
> python version etc.) which I also need to avoid when testing.
I don't think pprint will change like that, but you have a point about
the hidden assumptions of using such a library. In that light your
function is simpler and better.
I just remembered: your function returns nothing, but you use it in a
print statement like this:
+ print 'CFG:', dumpdict(auth)
A "void" function really returns None in Python, and this explains the
extra "None" lines printed in the test output. Just return the string
From dumpdict instead of printing it.
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090503/91ee9d88/attachment.pgp
More information about the Mercurial-devel
mailing list