Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Glenn Linderman

On 9/6/2013 10:22 AM, Dan Callahan wrote:

On 9/5/13 12:31 PM, Jesus Cea wrote:

I have big hopes for Mozilla Persona, looking forward
Python infrastructure support :).


Hi, I'm the project lead on Persona signin, and I spoke at PyCon 
earlier this year regarding why and how Mozilla is building Persona. 
If you'd like some more background, that video [0] is worth a look.


Let's pull this discussion up a level:

It sounds like many people (Jesus, Donald, Toshio, Barry, Tres, 
Dirkjan, etc.) are interested in seeing Persona on Python.org 
properties, and most of the objections coming from a place of "Persona 
hasn't gone viral, what if this is wasted effort?"


OK, let's pull this discussion down a level: testing it out.

So I tried to login to the crossword.thetimes.co.uk -- I used an email 
address persona had never seen, it asked me for a password, and sent me 
a confirmation message, containing a link that I clicked on.


However, as I was reading clues and filling in blanks, I got a popup 
that said "login failure [object Object]". And crossword told me it was 
saving locally, and to login to save to the server. And the Log in 
button stayed displayed, rather than a Log out button, which I assume it 
might get replaced with if I ever get successfully logged in.


Firefox 23.0.1, Windows 7 64-bit with autoupdates. Need any other info? 
Write me privately if you want the email address I used (not the one I 
use here), or the password. I used new ones, so I can share for testing, 
and then discard them and use different ones "for real". If the system 
actually works. Hey, the video demos looked great...


Glenn
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Antoine Pitrou

Ok, can this discussion go off python-dev, please? This has been
terribly off-topic for a long time (arguably from the beginning,
actually).

Thank you

Antoine.



Le Tue, 10 Sep 2013 00:21:28 -0700,
Glenn Linderman  a écrit :
> On 9/6/2013 10:22 AM, Dan Callahan wrote:
> > On 9/5/13 12:31 PM, Jesus Cea wrote:
> >> I have big hopes for Mozilla Persona, looking forward
> >> Python infrastructure support :).
> >
> > Hi, I'm the project lead on Persona signin, and I spoke at PyCon 
> > earlier this year regarding why and how Mozilla is building
> > Persona. If you'd like some more background, that video [0] is
> > worth a look.
> >
> > Let's pull this discussion up a level:
> >
> > It sounds like many people (Jesus, Donald, Toshio, Barry, Tres, 
> > Dirkjan, etc.) are interested in seeing Persona on Python.org 
> > properties, and most of the objections coming from a place of
> > "Persona hasn't gone viral, what if this is wasted effort?"
> 
> OK, let's pull this discussion down a level: testing it out.
> 
> So I tried to login to the crossword.thetimes.co.uk -- I used an
> email address persona had never seen, it asked me for a password, and
> sent me a confirmation message, containing a link that I clicked on.
> 
> However, as I was reading clues and filling in blanks, I got a popup 
> that said "login failure [object Object]". And crossword told me it
> was saving locally, and to login to save to the server. And the Log
> in button stayed displayed, rather than a Log out button, which I
> assume it might get replaced with if I ever get successfully logged
> in.
> 
> Firefox 23.0.1, Windows 7 64-bit with autoupdates. Need any other
> info? Write me privately if you want the email address I used (not
> the one I use here), or the password. I used new ones, so I can share
> for testing, and then discard them and use different ones "for real".
> If the system actually works. Hey, the video demos looked great...
> 
> Glenn
> 


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou

Hello,

In http://bugs.python.org/issue18986 I proposed adding a new mapping
type to the collections module.

The original use case is quite common in network programming and
elsewhere (Eric Snow on the tracker mentioned an application with stock
symbols). You want to have an associative container which matches keys
case-insensitively but also preserves the original casing (e.g. for
presentation). It is a commonly reimplemented container.

It is also an instance of a more general pattern: match keys after
applying a derivation (or coercion) function, but at the same time keep
track of the original key. Note that the derivation function needn't be
(and generally won't be) bijective, otherwise it's too simple.

Therefore I propose adding the general pattern. Simple example:

   >>> d = transformdict(str.lower)
   >>> d['Foo'] = 5
   >>> d['foo']
   5
   >>> d['FOO']
   5
   >>> list(d)
   ['Foo']

(case-insensitive but case-preserving, as the best filesystems are ;-))


On the tracker issue, it seems everyone agreed on the principle. There
is some bikeshedding left to do, though. So here are the reasonable
naming proposals so far:

- transformkeydict
- coercekeydict
- transformdict
- coercedict

I have a sweet spot for "transformdict" myself.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Skip Montanaro
> (case-insensitive but case-preserving, as the best filesystems are ;-))

> I have a sweet spot for "transformdict" myself.

Antoine,

"Transform" does not remind me of "case-insensitive but
case-preserving". If this is important enough to put into the
collections module (I'm skeptical), shouldn't that behavior be more
strongly hinted at in the name? Lot's of things are transformations.
You're interested in a very specific one.

Skip
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 04:42:46 -0500,
Skip Montanaro  a écrit :
> > (case-insensitive but case-preserving, as the best filesystems
> > are ;-))
> 
> > I have a sweet spot for "transformdict" myself.
> 
> Antoine,
> 
> "Transform" does not remind me of "case-insensitive but
> case-preserving".

That was only describing the example, not the proposal.
(and I hoped it would be obvious that that sentence was a joke ;-))

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Victor Stinner
2013/9/10 Antoine Pitrou :
> In http://bugs.python.org/issue18986 I proposed adding a new mapping
> type to the collections module.
>
> The original use case is quite common in network programming and
> elsewhere (Eric Snow on the tracker mentioned an application with stock
> symbols). You want to have an associative container which matches keys
> case-insensitively but also preserves the original casing (e.g. for
> presentation). It is a commonly reimplemented container.

If it is commonly reimplemented, what is the most common name? :-)

The http.client and email.message modules convert headers to lower
case, but keep the original case.

> - transformkeydict

Do you know a use case where values need also to be transformed? If
not, I prefer the transformdict name.

> - coercekeydict
> - coercedict

I only read "coerce" in old Python documentation, not in other
languages. I prefer the more common and generic term "tranform".

Victor
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Oscar Benjamin
On 10 September 2013 10:28, Antoine Pitrou  wrote:
> On the tracker issue, it seems everyone agreed on the principle. There
> is some bikeshedding left to do, though. So here are the reasonable
> naming proposals so far:
>
> - transformkeydict
> - coercekeydict
> - transformdict
> - coercedict
>
> I have a sweet spot for "transformdict" myself.

Could you not use a name with some sense of purpose like approxmatchdict?


Oscar
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Dirkjan Ochtman
On Tue, Sep 10, 2013 at 11:28 AM, Antoine Pitrou  wrote:
> On the tracker issue, it seems everyone agreed on the principle. There
> is some bikeshedding left to do, though. So here are the reasonable
> naming proposals so far:
>
> - transformkeydict
> - coercekeydict
> - transformdict
> - coercedict
>
> I have a sweet spot for "transformdict" myself.

Given OrderedDict, it seems like this should definitely be
TransformDict rather than transformdict.

Cheers,

Dirkjan
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Martin v. Löwis
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 05.09.13 19:31, schrieb Jesus Cea:
> What are you using?. bugs.python.org admins could share some data?

Most users use one of the large services:

https://www.google.com 3326
https://login.launchpad.net 335
https://*.myopenid.com 253
https://launchpad.net 23
https://*.id.fedoraproject.org 11

The remaining ones are mostly private URLs. Of those, a majority
again delegates to providers, namely (ignoring providers with less
than 3 users)

www.startssl.com 3
www.clavid.com 3
openid.stackexchange.com 4
openid.claimid.com 4
login.launchpad.net 7
openid.yandex.ru 8
www.google.com 14
pip.verisignlabs.com 20
www.myopenid.com 41

Regards,
Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlIvCQgACgkQavBT8H2dyNIX/gCeL9As+Z/aRAggbP+bjwUxFtGo
wZYAn2YkEEf/iv+bPGDBEnV+UWZmrf9M
=B5pE
-END PGP SIGNATURE-
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Nick Coghlan
Is this just syntactic sugar for recursive lookup of a transformed version
in __missing__? Or a way of supplying a custom "key" function to a
dictionary?

Any such proposal should consider how it composes with other dict variants
like defaultdict, OrderedDict and counter.

Cheers,
Nick.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 22:00:37 +1000,
Nick Coghlan  a écrit :
> Is this just syntactic sugar for recursive lookup of a transformed
> version in __missing__?

Nope. For one, it doesn't use __missing__ at all. I think
using __missing__ would be... missing the point, because it wouldn't
working properly if you have e.g. X != Y such that transform(X) == Y
and transform(Y) == X.

(a simple example being transform = str.swapcase :-))

> Or a way of supplying a custom "key" function
> to a dictionary?

Probably, although I'm not entirely sure what you mean by that :-)

> Any such proposal should consider how it composes with other dict
> variants like defaultdict, OrderedDict and counter.

Well, one sticking point here is that those variants don't compose with
each other already :-)
But, yes, I may make another proposal with composition in mind.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Paul Moore
On 10 September 2013 13:24, Paul Moore  wrote:
> On 10 September 2013 13:00, Nick Coghlan  wrote:
>> Is this just syntactic sugar for recursive lookup of a transformed version
>> in __missing__? Or a way of supplying a custom "key" function to a
>> dictionary?
>
> Not quite, because the dict should preserve the originally entered key.
>
 td['FOO'] = 42
 td['bar'] = 1
 td['foo']
> 42
 td['BAR']
> 1
 list(td.keys())
> ['FOO', 'bar']
>
> This actually prompts the question, what should the following produce:
>
 td['FOO'] = 42
 td['foo'] = 32
 list(td.keys())
>
> ['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
> even useful depending on context...

I'm using the case where the transform is str.lower here - sorry I
wasn't explicit.
Paul
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Paul Moore
On 10 September 2013 13:00, Nick Coghlan  wrote:
> Is this just syntactic sugar for recursive lookup of a transformed version
> in __missing__? Or a way of supplying a custom "key" function to a
> dictionary?

Not quite, because the dict should preserve the originally entered key.

>>> td['FOO'] = 42
>>> td['bar'] = 1
>>> td['foo']
42
>>> td['BAR']
1
>>> list(td.keys())
['FOO', 'bar']

This actually prompts the question, what should the following produce:

>>> td['FOO'] = 42
>>> td['foo'] = 32
>>> list(td.keys())

['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
even useful depending on context...

Paul
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 13:24:29 +0100,
Paul Moore  a écrit :
> On 10 September 2013 13:00, Nick Coghlan  wrote:
> > Is this just syntactic sugar for recursive lookup of a transformed
> > version in __missing__? Or a way of supplying a custom "key"
> > function to a dictionary?
> 
> Not quite, because the dict should preserve the originally entered
> key.
> 
> >>> td['FOO'] = 42
> >>> td['bar'] = 1
> >>> td['foo']
> 42
> >>> td['BAR']
> 1
> >>> list(td.keys())
> ['FOO', 'bar']
> 
> This actually prompts the question, what should the following produce:
> 
> >>> td['FOO'] = 42
> >>> td['foo'] = 32
> >>> list(td.keys())
> 
> ['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
> even useful depending on context...

I think it would be best to leave it as an implementation detail,
because whichever is easiest to implement depends on the exact
implementation choices (e.g. C vs. Python).

(my prototypes right now conserve the last __setitem__ key, not the
first)

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Martin v. Löwis
Am 10.09.13 14:35, schrieb Antoine Pitrou:
>> ['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
>> even useful depending on context...
> 
> I think it would be best to leave it as an implementation detail,
> because whichever is easiest to implement depends on the exact
> implementation choices (e.g. C vs. Python).

I think this is the point where the datatype is *not* clearly
straight-forward, and thus deserves a PEP.

I think it would be a flaw to have this detail implementation-defined.
This would be like saying that it is implementation-defined which
of A,B,C is returned from "A and B and C" if all are true.

Regards,
Martin

___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Hrvoje Niksic

On 09/10/2013 02:24 PM, Paul Moore wrote:

td['FOO'] = 42
td['foo'] = 32
list(td.keys())


['FOO'] or ['foo']? Both answers are justifiable.


Note that the same question can be reasonably asked for dict itself:

>>> d = {}
>>> d[1.0] = 'foo'
>>> d[1] = 'bar'
>>> d
{1.0: 'bar'}

So, dict.__setitem__ only replaces the value, leaving the original key 
in place. transformdict should probably do the same, returning 'FOO' in 
your example.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Richard Oudkerk

On 10/09/2013 10:28am, Antoine Pitrou wrote:

Therefore I propose adding the general pattern. Simple example:

>>> d = transformdict(str.lower)
>>> d['Foo'] = 5
>>> d['foo']
5
>>> d['FOO']
5
>>> list(d)
['Foo']


I guess another example is creating an "identity dict" (see 
http://code.activestate.com/lists/python-ideas/7161/) by doing


d = transformdict(id)

--
Richard

___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Barry Warsaw
On Sep 10, 2013, at 12:04 PM, Victor Stinner wrote:

>The http.client and email.message modules convert headers to lower
>case, but keep the original case.

As RDM pointed out on the tracker, email headers aren't a great use case for
this because they aren't really dictionaries.  They're lists with some
dict-like syntax.

-Barry
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 09:49:28 -0400,
Barry Warsaw  a écrit :
> On Sep 10, 2013, at 12:04 PM, Victor Stinner wrote:
> 
> >The http.client and email.message modules convert headers to lower
> >case, but keep the original case.
> 
> As RDM pointed out on the tracker, email headers aren't a great use
> case for this because they aren't really dictionaries.  They're lists
> with some dict-like syntax.

defaultdict(list)?



___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Barry Warsaw
On Sep 10, 2013, at 03:57 PM, Antoine Pitrou wrote:

>Le Tue, 10 Sep 2013 09:49:28 -0400,
>Barry Warsaw  a écrit :
>> On Sep 10, 2013, at 12:04 PM, Victor Stinner wrote:
>> 
>> >The http.client and email.message modules convert headers to lower
>> >case, but keep the original case.
>> 
>> As RDM pointed out on the tracker, email headers aren't a great use
>> case for this because they aren't really dictionaries.  They're lists
>> with some dict-like syntax.
>
>defaultdict(list)?

Not really.  Email headers support duplicates, although the dict-syntax will
only return the first such header.  Alternative syntax like .get_all() gives
you all of them.

But anyway, don't let this stop you!  I like your robots-in-disguise[1] dicts
no matter what you call them, and even if email can't use them.

-Barry

[1] http://www.youtube.com/watch?v=59QeKkjishs
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 447: add type.__locallookup__

2013-09-10 Thread Armin Rigo
Hi Mark,

On Mon, Sep 9, 2013 at 11:18 PM, Mark Shannon  wrote:
> 5. Other implementations. What do the Jython/IronPython/PyPy developers
> think?

Thanks for asking :-)  I'm fine with staying out of language design
issues like this one, and I believe it's the general concensus in
PyPy.  Whatever gets decided will probably be easy to port to PyPy and
have no measurable performance impact: the extra checks on the type,
if any, are all constant-folded by the JIT.


A bientôt,

Armin.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Armin Rigo
Hi Richard,

On Tue, Sep 10, 2013 at 3:42 PM, Richard Oudkerk  wrote:
> I guess another example is creating an "identity dict" (see
> http://code.activestate.com/lists/python-ideas/7161/) by doing
>
> d = transformdict(id)

This is bogus, because only the id will be stored, and the original
key object will be forgotten (and its id probably reused).


A bientôt,

Armin.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Eli Bendersky
On Tue, Sep 10, 2013 at 5:22 AM, Antoine Pitrou  wrote:

> Le Tue, 10 Sep 2013 22:00:37 +1000,
> Nick Coghlan  a écrit :
> > Is this just syntactic sugar for recursive lookup of a transformed
> > version in __missing__?
>
> Nope. For one, it doesn't use __missing__ at all. I think
> using __missing__ would be... missing the point, because it wouldn't
> working properly if you have e.g. X != Y such that transform(X) == Y
> and transform(Y) == X.
>
> (a simple example being transform = str.swapcase :-))
>
> > Or a way of supplying a custom "key" function
> > to a dictionary?
>
> Probably, although I'm not entirely sure what you mean by that :-)
>
> > Any such proposal should consider how it composes with other dict
> > variants like defaultdict, OrderedDict and counter.
>
> Well, one sticking point here is that those variants don't compose with
> each other already :-)
> But, yes, I may make another proposal with composition in mind.
>

Does anyone have an idea how to make the existing variants more composable?
It would be nice to get a better understanding of this before we add
another variant. Conceptually, composability makes a lot of sense (what if
we want this transformdict but also in insertion order...)

Eli
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 07:18:41 -0700,
Eli Bendersky  a écrit :
> On Tue, Sep 10, 2013 at 5:22 AM, Antoine Pitrou 
> wrote:
> 
> > Le Tue, 10 Sep 2013 22:00:37 +1000,
> > Nick Coghlan  a écrit :
> > > Is this just syntactic sugar for recursive lookup of a transformed
> > > version in __missing__?
> >
> > Nope. For one, it doesn't use __missing__ at all. I think
> > using __missing__ would be... missing the point, because it wouldn't
> > working properly if you have e.g. X != Y such that transform(X) == Y
> > and transform(Y) == X.
> >
> > (a simple example being transform = str.swapcase :-))
> >
> > > Or a way of supplying a custom "key" function
> > > to a dictionary?
> >
> > Probably, although I'm not entirely sure what you mean by that :-)
> >
> > > Any such proposal should consider how it composes with other dict
> > > variants like defaultdict, OrderedDict and counter.
> >
> > Well, one sticking point here is that those variants don't compose
> > with each other already :-)
> > But, yes, I may make another proposal with composition in mind.
> >
> 
> Does anyone have an idea how to make the existing variants more
> composable? It would be nice to get a better understanding of this
> before we add another variant. Conceptually, composability makes a
> lot of sense (what if we want this transformdict but also in
> insertion order...)

AFAICT, the main problem with composability is that the implementation
is less simple and it removes many opportunities for optimization. It
may or may not be a problem, depending on your use cases.

(I'm playing a bit with a TransformMap which is a composable version of
transformdict, and it's clear the implementation is less amenable to
optimization tweaks and shortcuts: in fact, I have to *add* some logic
to e.g. cater with defaultdict)

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Andrea Corbellini
On Tue, Sep 10, 2013 at 11:28 AM, Antoine Pitrou  wrote:
> Therefore I propose adding the general pattern. Simple example:
>
>>>> d = transformdict(str.lower)
>>>> d['Foo'] = 5
>>>> d['foo']
>5
>>>> d['FOO']
>5
>>>> list(d)
>['Foo']
>
> (case-insensitive but case-preserving, as the best filesystems are ;-))

Just a nitpick: if this example (or a similar one) gets into the
documentation, it would be better to replace str.lower() with
str.casefold().
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] IOCP (I/O Completion Port) in Python ?

2013-09-10 Thread 张佩佩
Hello:
I wondering why there is no standard IOCP module in Python ?
As I know: Python3 have support epoll in linux and kqueue in freebsd.
Is there a plan to add IOCP module for Windows ?

Regards!
peipei
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 15:09:56 +0200,
Hrvoje Niksic  a écrit :
> On 09/10/2013 02:24 PM, Paul Moore wrote:
>  td['FOO'] = 42
>  td['foo'] = 32
>  list(td.keys())
> >
> > ['FOO'] or ['foo']? Both answers are justifiable.
> 
> Note that the same question can be reasonably asked for dict itself:
> 
>  >>> d = {}
>  >>> d[1.0] = 'foo'
>  >>> d[1] = 'bar'
>  >>> d
> {1.0: 'bar'}
> 
> So, dict.__setitem__ only replaces the value, leaving the original
> key in place. transformdict should probably do the same, returning
> 'FOO' in your example.

It's not that obvious. It's not common to rely on that aspect of dict
semantics, because you will usually lookup using the exact same type,
not a compatible one. I would expect very little code, if any, to rely
on this.

(also, I would intuitively expect the latest key to be held, not the
first one, since that's what happens for values.)

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IOCP (I/O Completion Port) in Python ?

2013-09-10 Thread Guido van Rossum
One will come with Tulip (http://code.google.com/p/tulip/), assuming we can
get PEP 3156 accepted at least as "experimental" and the core Tulip code in
the stdlib. At the moment the IOCP code there is pretty specialized for use
with Tulip -- but if you want to help extracting the IOCP code from there
for inclusion into the stdlib that would be great!


On Tue, Sep 10, 2013 at 3:58 AM, 张佩佩  wrote:

> Hello:
> I wondering why there is no standard IOCP module in Python ?
> As I know: Python3 have support epoll in linux and kqueue in freebsd.
> Is there a plan to add IOCP module for Windows ?
>
> Regards!
> peipei
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
Le Tue, 10 Sep 2013 16:15:56 +0200,
Armin Rigo  a écrit :
> Hi Richard,
> 
> On Tue, Sep 10, 2013 at 3:42 PM, Richard Oudkerk 
> wrote:
> > I guess another example is creating an "identity dict" (see
> > http://code.activestate.com/lists/python-ideas/7161/) by doing
> >
> > d = transformdict(id)
> 
> This is bogus, because only the id will be stored, and the original
> key object will be forgotten (and its id probably reused).

No, the original key is kept as well.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Richard Oudkerk

On 10/09/2013 3:15pm, Armin Rigo wrote:

Hi Richard,

On Tue, Sep 10, 2013 at 3:42 PM, Richard Oudkerk  wrote:

I guess another example is creating an "identity dict" (see
http://code.activestate.com/lists/python-ideas/7161/) by doing

 d = transformdict(id)


This is bogus, because only the id will be stored, and the original
key object will be forgotten (and its id probably reused).


Seems to work for me:

>>> import collections
>>> d = collections.transformdict(id)
>>> L = [1,2,3]
>>> d[L] = None
>>> L in d
True
>>> [1,2,3] in d
False
>>> print(d[L])
None
>>> d._data
{41444136: ([1, 2, 3], None)}
>>> list(d)
[[1, 2, 3]]

However __repr__() is broken:

>>> d
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Repos\cpython-dirty\lib\collections\abc.py", line 444, in 
__repr__

return '{0.__class__.__name__}({0._mapping!r})'.format(self)
  File "C:\Repos\cpython-dirty\lib\collections\__init__.py", line 944, 
in __repr__

self._transform, repr(dict(self)))
TypeError: unhashable type: 'list'

--
Richard
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Guido van Rossum
Why do several posts in this thread have an Unsubscribe link that tries to
unsubscribe me from the list? (I saw one by Glen, and another one by Donald
Stufft.)

(Come to think of it, what's the point of having an Unbub link in ever
message that goes out?)


On Tue, Sep 10, 2013 at 12:21 AM, Glenn Linderman wrote:

>  On 9/6/2013 10:22 AM, Dan Callahan wrote:
>
> On 9/5/13 12:31 PM, Jesus Cea wrote:
>
> I have big hopes for Mozilla Persona, looking forward
> Python infrastructure support :).
>
>
> Hi, I'm the project lead on Persona signin, and I spoke at PyCon earlier
> this year regarding why and how Mozilla is building Persona. If you'd like
> some more background, that video [0] is worth a look.
>
> Let's pull this discussion up a level:
>
> It sounds like many people (Jesus, Donald, Toshio, Barry, Tres, Dirkjan,
> etc.) are interested in seeing Persona on Python.org properties, and most
> of the objections coming from a place of "Persona hasn't gone viral, what
> if this is wasted effort?"
>
>
> OK, let's pull this discussion down a level: testing it out.
>
> So I tried to login to the crossword.thetimes.co.uk -- I used an email
> address persona had never seen, it asked me for a password, and sent me a
> confirmation message, containing a link that I clicked on.
>
> However, as I was reading clues and filling in blanks, I got a popup that
> said "login failure [object Object]". And crossword told me it was saving
> locally, and to login to save to the server. And the Log in button stayed
> displayed, rather than a Log out button, which I assume it might get
> replaced with if I ever get successfully logged in.
>
> Firefox 23.0.1, Windows 7 64-bit with autoupdates. Need any other info?
> Write me privately if you want the email address I used (not the one I use
> here), or the password. I used new ones, so I can share for testing, and
> then discard them and use different ones "for real". If the system actually
> works. Hey, the video demos looked great...
>
> Glenn
>
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>
>


-- 
--Guido van Rossum (python.org/~guido)
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Ethan Furman

On 09/10/2013 06:09 AM, Hrvoje Niksic wrote:

On 09/10/2013 02:24 PM, Paul Moore wrote:

td['FOO'] = 42
td['foo'] = 32
list(td.keys())


['FOO'] or ['foo']? Both answers are justifiable.


Note that the same question can be reasonably asked for dict itself:


d = {}
d[1.0] = 'foo'
d[1] = 'bar'
d

{1.0: 'bar'}

So, dict.__setitem__ only replaces the value, leaving the original key in 
place. transformdict should probably do the
same, returning 'FOO' in your example.


+1
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Donald Stufft

On Sep 10, 2013, at 11:08 AM, Guido van Rossum  wrote:

> Why do several posts in this thread have an Unsubscribe link that tries to 
> unsubscribe me from the list? (I saw one by Glen, and another one by Donald 
> Stufft.)
> 
> (Come to think of it, what's the point of having an Unbub link in ever 
> message that goes out?)

All posts should have that. It's possible your mail client is collapsing it in 
some cases though because it looks like quoted text.

> 
> 
> On Tue, Sep 10, 2013 at 12:21 AM, Glenn Linderman  
> wrote:
> On 9/6/2013 10:22 AM, Dan Callahan wrote:
>> On 9/5/13 12:31 PM, Jesus Cea wrote: 
>>> I have big hopes for Mozilla Persona, looking forward 
>>> Python infrastructure support :). 
>> 
>> Hi, I'm the project lead on Persona signin, and I spoke at PyCon earlier 
>> this year regarding why and how Mozilla is building Persona. If you'd like 
>> some more background, that video [0] is worth a look. 
>> 
>> Let's pull this discussion up a level: 
>> 
>> It sounds like many people (Jesus, Donald, Toshio, Barry, Tres, Dirkjan, 
>> etc.) are interested in seeing Persona on Python.org properties, and most of 
>> the objections coming from a place of "Persona hasn't gone viral, what if 
>> this is wasted effort?"
> 
> OK, let's pull this discussion down a level: testing it out.
> 
> So I tried to login to the crossword.thetimes.co.uk -- I used an email 
> address persona had never seen, it asked me for a password, and sent me a 
> confirmation message, containing a link that I clicked on.
> 
> However, as I was reading clues and filling in blanks, I got a popup that 
> said "login failure [object Object]". And crossword told me it was saving 
> locally, and to login to save to the server. And the Log in button stayed 
> displayed, rather than a Log out button, which I assume it might get replaced 
> with if I ever get successfully logged in.
> 
> Firefox 23.0.1, Windows 7 64-bit with autoupdates. Need any other info? Write 
> me privately if you want the email address I used (not the one I use here), 
> or the password. I used new ones, so I can share for testing, and then 
> discard them and use different ones "for real". If the system actually works. 
> Hey, the video demos looked great...
> 
> Glenn
> 
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
> 
> 
> 
> 
> -- 
> --Guido van Rossum (python.org/~guido)


-
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Oleg Broytman
On Tue, Sep 10, 2013 at 11:28:25AM -0400, Donald Stufft 
 wrote:
> On Sep 10, 2013, at 11:08 AM, Guido van Rossum  wrote:
> > Why do several posts in this thread have an Unsubscribe link that tries to 
> > unsubscribe me from the list? (I saw one by Glen, and another one by Donald 
> > Stufft.)
> > 
> > (Come to think of it, what's the point of having an Unbub link in ever 
> > message that goes out?)
> 
> All posts should have that. It's possible your mail client is collapsing it 
> in some cases though because it looks like quoted text.

   When a mail message is all plain/text Mailman simply inline the
stance into the text. When a message is a complex tree of MIME parts
(like the message I'm replying to) Mailman append the stance to the end
of the message as another MIME part. Some MUAs could ignore that part --
they neither show the part nor include it in replies. Mine (mutt) shows
it and includes in replies anyway, I always trim it myself.

Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/[email protected]
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [RELEASED] Python 3.4.0a2

2013-09-10 Thread Ryan Gonzalez
MS Windows is on a steep decline? I mean, I know Windows 8 isn't the most
popular thing on the planet, but...Windows itself? If anything would be
rising, I'd still prefer it to be either Linux or Haiku.


On Tue, Sep 10, 2013 at 12:48 AM, Stefan Behnel  wrote:

> Ned Deily, 09.09.2013 21:29:
> > 3.4.0a2 also contains a new batteries-included feature for OS X
> > users.  The python.org 64-bit/32-bit installer now includes its own
> > private version of Tcl/Tk 8.5.14 so it is finally no longer necessary to
> > install a third-party version of Tcl/Tk 8.5 to workaround the
> > problematic system versions shipped in OS X 10.6+.  More improvements to
> > come.
>
> With MS Windows on steep decline, I'm so happy we have at least MacOS-X
> rising to keep us busy.
>
> Stefan
>
>
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com
>



-- 
Ryan
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Janzert

On 9/10/2013 10:54 AM, Antoine Pitrou wrote:

(also, I would intuitively expect the latest key to be held, not the
first one, since that's what happens for values.)

Regards

Antoine.



I intuitively expected, and I think most often would want, the first key 
to be held. The reason being that I would except most often the initial 
insertion to be the canonical form.


Whichever way is adopted, I think even if you say it's implementation 
specific, people will end up relying on it in their code.


Janzert

___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Eric V. Smith
On 09/10/2013 11:54 AM, Janzert wrote:
> On 9/10/2013 10:54 AM, Antoine Pitrou wrote:
>> (also, I would intuitively expect the latest key to be held, not the
>> first one, since that's what happens for values.)
>>
>> Regards
>>
>> Antoine.
>>
> 
> I intuitively expected, and I think most often would want, the first key
> to be held. The reason being that I would except most often the initial
> insertion to be the canonical form.

My stock ticker example (but from a real problem I had a few days ago)
would want to have this example: I want the first key, because I'm
pre-seeding the dict with a variety of keys that are of the canonical form.

> Whichever way is adopted, I think even if you say it's implementation
> specific, people will end up relying on it in their code.

Agreed.

Eric.

___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Glenn Linderman

On 9/10/2013 8:54 AM, Janzert wrote:


I intuitively expected, and I think most often would want, the first 
key to be held. 


My intuition matches yours, but my thoughts are that it should be 
changeable by specific request.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Nigel Small
Could a more generic variant of this class work? In the same way that
`sorted` can accept a comparison function, similar could be done for a
dictionary-like class:

d = transformdict(key=str.lower)

Strictly speaking, this would provide case-insensitive but not
case-preserving behaviour. For any given use case, though, a function could
instead be supplied to "normalise" the key (upper, lower, title case, etc)
in a way that fits that case. I can't think of many real cases where
multiple types of capitalisation would be useful within the same dictionary.

Nigel



On 10 September 2013 15:40, Richard Oudkerk  wrote:

> On 10/09/2013 3:15pm, Armin Rigo wrote:
>
>> Hi Richard,
>>
>> On Tue, Sep 10, 2013 at 3:42 PM, Richard Oudkerk 
>> wrote:
>>
>>> I guess another example is creating an "identity dict" (see
>>> http://code.activestate.com/**lists/python-ideas/7161/)
>>> by doing
>>>
>>>  d = transformdict(id)
>>>
>>
>> This is bogus, because only the id will be stored, and the original
>> key object will be forgotten (and its id probably reused).
>>
>
> Seems to work for me:
>
> >>> import collections
> >>> d = collections.transformdict(id)
> >>> L = [1,2,3]
> >>> d[L] = None
> >>> L in d
> True
> >>> [1,2,3] in d
> False
> >>> print(d[L])
> None
> >>> d._data
> {41444136: ([1, 2, 3], None)}
> >>> list(d)
> [[1, 2, 3]]
>
> However __repr__() is broken:
>
> >>> d
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Repos\cpython-dirty\lib\**collections\abc.py", line 444, in
> __repr__
> return '{0.__class__.__name__}({0._**mapping!r})'.format(self)
>   File "C:\Repos\cpython-dirty\lib\**collections\__init__.py", line 944,
> in __repr__
> self._transform, repr(dict(self)))
> TypeError: unhashable type: 'list'
>
> --
> Richard
>
> __**_
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/**mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/**mailman/options/python-dev/**
> nigel%40nigelsmall.com
>
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Barry Warsaw
On Sep 10, 2013, at 08:08 AM, Guido van Rossum wrote:

>Why do several posts in this thread have an Unsubscribe link that tries to
>unsubscribe me from the list? (I saw one by Glen, and another one by Donald
>Stufft.)

This is way off topic, but I suspect your original response didn't trim your
little unsub footer and they didn't trim it from their responses.

Looking at my list copy of *this* message, I see my own unsub footer, but my
MUA automatically trims it in my response buffer.  OTOH, I always try to trim
my responses anyway, which I think is good netiquette, and which is easy for
me with Emacs as my edit/composer of messages.

>(Come to think of it, what's the point of having an Unbub link in ever
>message that goes out?)

As a general Mailman feature, it decreases the likelihood that laypeople who
want off a mailing list will do bad things to unsub because they can't figure
out how to do it, like complain back to the list or the admins, spam block, or
worse, report the list as spam.  All of which and more we've seen in the wild.
Adding the footer with the unsub block doesn't eliminate this, because some
people are lazy, stressed, mean, or frustrated, but it does reduce the
incidences.

Now, whether it's appropriate for a highly technical list like python-dev is
up for discussion (but maybe not here?).  While messages are personalized on
this list (meaning, you get a unique copy of it for bounce tracking, and yes
unsub personalization), those unsub stanzas cannot currently be disabled on a
per-user basis.

-Barry
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Offtopic: OpenID Providers

2013-09-10 Thread Glenn Linderman

On 9/10/2013 8:08 AM, Guido van Rossum wrote:
Why do several posts in this thread have an Unsubscribe link that 
tries to unsubscribe me from the list? (I saw one by Glen, and another 
one by Donald Stufft.)


Seems to be in all of them. Probably added by the mailing list software.

Why don't you always see it?

Possibly a combination of being directly listed as a recipient, so that 
you get a copy not sent through the mailing list, together with an email 
client that suppresses the duplicates (if the mailing list software 
doesn't change the Message-Id:). But since heretofore you haven't 
participated in this thread, if you don't see the Unsub link in all of 
this thread, I doubt this is the explanation. You message to which I'm 
replying is the first in this thread that came directly to me and which 
doesn't have the link, because you addressed me directly.  Use 
Reply-List rather than Reply-All if your MUA supports that.


(Come to think of it, what's the point of having an Unbub link in ever 
message that goes out?)


To avoid people that accidentally subscribe from asking how to 
unsubscribe, perhaps.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Ethan Furman

On 09/10/2013 07:54 AM, Antoine Pitrou wrote:

Le Tue, 10 Sep 2013 15:09:56 +0200,
Hrvoje Niksic  a écrit :

On 09/10/2013 02:24 PM, Paul Moore wrote:

td['FOO'] = 42
td['foo'] = 32
list(td.keys())


['FOO'] or ['foo']? Both answers are justifiable.


Note that the same question can be reasonably asked for dict itself:

  >>> d = {}
  >>> d[1.0] = 'foo'
  >>> d[1] = 'bar'
  >>> d
{1.0: 'bar'}

So, dict.__setitem__ only replaces the value, leaving the original
key in place. transformdict should probably do the same, returning
'FOO' in your example.


It's not that obvious. It's not common to rely on that aspect of dict
semantics, because you will usually lookup using the exact same type,
not a compatible one. I would expect very little code, if any, to rely
on this.

(also, I would intuitively expect the latest key to be held, not the
first one, since that's what happens for values.)


Whether there is a bunch of code that relies on this behavior is irrelevant.  That behavior is already in place, and 
having another dict that is just the opposite will only lead to more confusion, not less.


--
~Ethan~
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IOCP (I/O Completion Port) in Python ?

2013-09-10 Thread Richard Oudkerk

On 10/09/2013 11:58am, 张佩佩 wrote:

Hello:
I wondering why there is no standard IOCP module in Python ?
As I know: Python3 have support epoll in linux and kqueue in freebsd.
Is there a plan to add IOCP module for Windows ?


_winapi does have some undocumented support for IOCP (used only by 
multiprocessing), but the APIs are not very nice and should not be 
considered stable.


(Also _winapi.ReadFile(), _winapi.WriteFile() only support pipes or 
sockets, not disk-based files where you also have to control file-position.)


--
Richard
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread R. David Murray
On Tue, 10 Sep 2013 16:21:18 +0100, Nigel Small  wrote:
> Could a more generic variant of this class work? In the same way that
> `sorted` can accept a comparison function, similar could be done for a
> dictionary-like class:
> 
> d = transformdict(key=str.lower)
> 
> Strictly speaking, this would provide case-insensitive but not
> case-preserving behaviour. For any given use case, though, a function could
> instead be supplied to "normalise" the key (upper, lower, title case, etc)
> in a way that fits that case. I can't think of many real cases where
> multiple types of capitalisation would be useful within the same dictionary.

I can:

  MIME-Version
  Message-ID
  Content-Type

For network protocols you really do want to *preserve* the case.

--David
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
On Tue, 10 Sep 2013 14:44:01 +0200
"Martin v. Löwis"  wrote:
> Am 10.09.13 14:35, schrieb Antoine Pitrou:
> >> ['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
> >> even useful depending on context...
> > 
> > I think it would be best to leave it as an implementation detail,
> > because whichever is easiest to implement depends on the exact
> > implementation choices (e.g. C vs. Python).
> 
> I think this is the point where the datatype is *not* clearly
> straight-forward, and thus deserves a PEP.

Not saying you're necessary wrong, but a few data points:
- defaultdict was added without a PEP:
  http://bugs.python.org/issue1433928
- Counter was added without a PEP:
  http://bugs.python.org/issue1696199
- ChainMap was added without a PEP:
  http://bugs.python.org/issue11089
  http://bugs.python.org/issue11297
- namedtuple was added without a PEP:
  https://mail.python.org/pipermail/python-dev/2007-February/071196.html
  (no tracker reference for its addition)

OrderedDict, however, came with a PEP:
http://www.python.org/dev/peps/pep-0372/

> I think it would be a flaw to have this detail implementation-defined.
> This would be like saying that it is implementation-defined which
> of A,B,C is returned from "A and B and C" if all are true.

Ok, it seems everyone (except me :-)) agrees that it should return the
first key value, so that's how it will be.

Regards

Antoine.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Paul Moore
On 10 September 2013 19:31, Antoine Pitrou  wrote:
>> I think it would be a flaw to have this detail implementation-defined.
>> This would be like saying that it is implementation-defined which
>> of A,B,C is returned from "A and B and C" if all are true.
>
> Ok, it seems everyone (except me :-)) agrees that it should return the
> first key value, so that's how it will be.

If you retain the first key value, it's easy enough for the
application to implement "retain the last" semantics:

try:
del d[k]
finally:
d[k] = v

If you provide "retain the last", I can't see any obvious way of
implementing "retain the first" in application code without in effect
reimplementing the class.

Paul
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread MRAB

On 10/09/2013 20:08, Paul Moore wrote:

On 10 September 2013 19:31, Antoine Pitrou  wrote:

I think it would be a flaw to have this detail implementation-defined.
This would be like saying that it is implementation-defined which
of A,B,C is returned from "A and B and C" if all are true.


Ok, it seems everyone (except me :-)) agrees that it should return the
first key value, so that's how it will be.


If you retain the first key value, it's easy enough for the
application to implement "retain the last" semantics:

try:
 del d[k]
finally:
 d[k] = v


That would raise a KeyError is the key was missing. A better way is:

d.pop(k, None)
d[k] = v


If you provide "retain the last", I can't see any obvious way of
implementing "retain the first" in application code without in effect
reimplementing the class.


"Retain the first" does feel more natural to me.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
On Tue, 10 Sep 2013 17:38:26 -0300
"Joao S. O. Bueno"  wrote:
> On 10 September 2013 16:08, Paul Moore  wrote:
> > If you provide "retain the last", I can't see any obvious way of
> > implementing "retain the first" in application code without in effect
> > reimplementing the class.
> 
> Which reminds one - this class should obviously have a method for
> retrivieng the original key value, given a matching key -
> 
> d.canonical('foo') -> 'Foo'

I don't know. Is there any use case?
(sure, it is trivially implemented)

Regards

Antoine.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Joao S. O. Bueno
On 10 September 2013 16:08, Paul Moore  wrote:
> If you provide "retain the last", I can't see any obvious way of
> implementing "retain the first" in application code without in effect
> reimplementing the class.

Which reminds one - this class should obviously have a method for
retrivieng the original key value, given a matching key -

d.canonical('foo') -> 'Foo'
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Paul Moore
On 10 September 2013 20:59, MRAB  wrote:
>> try:
>>  del d[k]
>> finally:
>>  d[k] = v
>>
> That would raise a KeyError is the key was missing. A better way is:
>
> d.pop(k, None)

Sorry, I was thinking of try...except: pass. But pop is indeed better.
Teach me to code stuff on the fly without testing :-)
Paul
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Lukas Lueg
Should'nt the key'ing behaviour be controlled by the type of the key
instead of the type of the container?


2013/9/10 MRAB 

> On 10/09/2013 20:08, Paul Moore wrote:
>
>> On 10 September 2013 19:31, Antoine Pitrou  wrote:
>>
>>> I think it would be a flaw to have this detail implementation-defined.
 This would be like saying that it is implementation-defined which
 of A,B,C is returned from "A and B and C" if all are true.

>>>
>>> Ok, it seems everyone (except me :-)) agrees that it should return the
>>> first key value, so that's how it will be.
>>>
>>
>> If you retain the first key value, it's easy enough for the
>> application to implement "retain the last" semantics:
>>
>> try:
>>  del d[k]
>> finally:
>>  d[k] = v
>>
>>  That would raise a KeyError is the key was missing. A better way is:
>
> d.pop(k, None)
>
> d[k] = v
>
>  If you provide "retain the last", I can't see any obvious way of
>> implementing "retain the first" in application code without in effect
>> reimplementing the class.
>>
>>  "Retain the first" does feel more natural to me.
>
> __**_
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/**mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/**mailman/options/python-dev/**
> lukas.lueg%40gmail.com
>
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread MRAB

On 10/09/2013 22:46, Antoine Pitrou wrote:

On Tue, 10 Sep 2013 18:44:20 -0300
"Joao S. O. Bueno"  wrote:

On 10 September 2013 18:06, Antoine Pitrou  wrote:
> On Tue, 10 Sep 2013 17:38:26 -0300
> "Joao S. O. Bueno"  wrote:
>> On 10 September 2013 16:08, Paul Moore  wrote:
>> > If you provide "retain the last", I can't see any obvious way of
>> > implementing "retain the first" in application code without in effect
>> > reimplementing the class.
>>
>> Which reminds one - this class should obviously have a method for
>> retrivieng the original key value, given a matching key -
>>
>> d.canonical('foo') -> 'Foo'
>
> I don't know. Is there any use case?
> (sure, it is trivially implemented)

Well, I'd expect it to simply be there. I had not thought of
other usecases for the transformdict itself -



I had the same thought.


Well, it is not here for dict, set, etc.


In those cases the key in the dict == the key you're looking for.


For example, in latim languages it is common to want
accented letters to match their unaccented counterparts
- pick my own first name "João" - if I'd use a transform to strip
the diactriticals, and have an user input "joao" - it would match,
as intended - but I would not be able to retrieve the accented version
without re-implementing the class behavior.


Interesting example, thanks.



___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Joao S. O. Bueno
On 10 September 2013 18:06, Antoine Pitrou  wrote:
> On Tue, 10 Sep 2013 17:38:26 -0300
> "Joao S. O. Bueno"  wrote:
>> On 10 September 2013 16:08, Paul Moore  wrote:
>> > If you provide "retain the last", I can't see any obvious way of
>> > implementing "retain the first" in application code without in effect
>> > reimplementing the class.
>>
>> Which reminds one - this class should obviously have a method for
>> retrivieng the original key value, given a matching key -
>>
>> d.canonical('foo') -> 'Foo'
>
> I don't know. Is there any use case?
> (sure, it is trivially implemented)


Well, I'd expect it to simply be there. I had not thought of
other usecases for the transformdict itself -

but if I would use it and would need the original key
without such a method it would not be trivial to get it.

For example, in latim languages it is common to want
accented letters to match their unaccented counterparts
- pick my own first name "João" - if I'd use a transform to strip
the diactriticals, and have an user input "joao" - it would match,
as intended - but I would not be able to retrieve the accented version
without re-implementing the class behavior.

  js
 -><-



>
> Regards
>
> Antoine.
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Ethan Furman

On 09/10/2013 01:36 PM, Lukas Lueg wrote:


Should'nt the key'ing behaviour be controlled by the type of the key instead of 
the type of the container?


That would be up to the key function.

--
~Ethan~
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Antoine Pitrou
On Tue, 10 Sep 2013 18:44:20 -0300
"Joao S. O. Bueno"  wrote:
> On 10 September 2013 18:06, Antoine Pitrou  wrote:
> > On Tue, 10 Sep 2013 17:38:26 -0300
> > "Joao S. O. Bueno"  wrote:
> >> On 10 September 2013 16:08, Paul Moore  wrote:
> >> > If you provide "retain the last", I can't see any obvious way of
> >> > implementing "retain the first" in application code without in effect
> >> > reimplementing the class.
> >>
> >> Which reminds one - this class should obviously have a method for
> >> retrivieng the original key value, given a matching key -
> >>
> >> d.canonical('foo') -> 'Foo'
> >
> > I don't know. Is there any use case?
> > (sure, it is trivially implemented)
> 
> 
> Well, I'd expect it to simply be there. I had not thought of
> other usecases for the transformdict itself -

Well, it is not here for dict, set, etc.

> For example, in latim languages it is common to want
> accented letters to match their unaccented counterparts
> - pick my own first name "João" - if I'd use a transform to strip
> the diactriticals, and have an user input "joao" - it would match,
> as intended - but I would not be able to retrieve the accented version
> without re-implementing the class behavior.

Interesting example, thanks.

Regards

Antoine.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Ethan Furman

On 09/10/2013 03:12 PM, MRAB wrote:

On 10/09/2013 22:46, Antoine Pitrou wrote:

On Tue, 10 Sep 2013 18:44:20 -0300
"Joao S. O. Bueno"  wrote:

On 10 September 2013 18:06, Antoine Pitrou  wrote:
> On Tue, 10 Sep 2013 17:38:26 -0300
> "Joao S. O. Bueno"  wrote:
>> On 10 September 2013 16:08, Paul Moore  wrote:
>> > If you provide "retain the last", I can't see any obvious way of
>> > implementing "retain the first" in application code without in effect
>> > reimplementing the class.
>>
>> Which reminds one - this class should obviously have a method for
>> retrivieng the original key value, given a matching key -
>>
>> d.canonical('foo') -> 'Foo'
>
> I don't know. Is there any use case?
> (sure, it is trivially implemented)

Well, I'd expect it to simply be there. I had not thought of
other usecases for the transformdict itself -



I had the same thought.


Well, it is not here for dict, set, etc.


In those cases the key in the dict == the key you're looking for.


With the exception of numbers, of course (float vs int vs Decimal, etc.).

But if that distinction was useful for someone they could use this new 
TransformDict.  :)

--
~Ethan~
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Eric V. Smith
On 9/10/2013 6:18 PM, Ethan Furman wrote:
> On 09/10/2013 03:12 PM, MRAB wrote:
>> On 10/09/2013 22:46, Antoine Pitrou wrote:
>>> On Tue, 10 Sep 2013 18:44:20 -0300
>>> "Joao S. O. Bueno"  wrote:
 On 10 September 2013 18:06, Antoine Pitrou  wrote:
 > On Tue, 10 Sep 2013 17:38:26 -0300
 > "Joao S. O. Bueno"  wrote:
 >> On 10 September 2013 16:08, Paul Moore  wrote:
 >> > If you provide "retain the last", I can't see any obvious way of
 >> > implementing "retain the first" in application code without in
 effect
 >> > reimplementing the class.
 >>
 >> Which reminds one - this class should obviously have a method for
 >> retrivieng the original key value, given a matching key -
 >>
 >> d.canonical('foo') -> 'Foo'
 >
 > I don't know. Is there any use case?
 > (sure, it is trivially implemented)

 Well, I'd expect it to simply be there. I had not thought of
 other usecases for the transformdict itself -
>>>
>> I had the same thought.
>>
>>> Well, it is not here for dict, set, etc.
>>>
>> In those cases the key in the dict == the key you're looking for.
> 
> With the exception of numbers, of course (float vs int vs Decimal, etc.).

They'd still be ==, wouldn't they?

--
Eric.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Glenn Linderman

On 9/10/2013 2:46 PM, Antoine Pitrou wrote:

> >>Which reminds one - this class should obviously have a method for
> >>retrivieng the original key value, given a matching key -
> >>
> >>d.canonical('foo') -> 'Foo'

> >
> >I don't know. Is there any use case?
> >(sure, it is trivially implemented)

>
>
>Well, I'd expect it to simply be there. I had not thought of
>other usecases for the transformdict itself -

Well, it is not here for dict, set, etc.


But they don't change the keys (although numbers have different 
representations on occasion).


One use of transformdict might be to allow use of non-hashable items as 
keys, by extracting an actual key from the internals of the non-hashable 
item. The key may be sufficiently unique to enable use of the dict 
structure for lookups, but it would certainly be handy to obtain the 
actual item again. Without a canonical lookup feature, one would be 
forced to also include the key as part of the value, or some such hack.


I also thought João's example was a very practical reason to have the 
canonical lookup feature, by some name or another.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Ethan Furman

On 09/10/2013 05:26 PM, Eric V. Smith wrote:

On 9/10/2013 6:18 PM, Ethan Furman wrote:

On 09/10/2013 03:12 PM, MRAB wrote:

On 10/09/2013 22:46, Antoine Pitrou wrote:

On Tue, 10 Sep 2013 18:44:20 -0300
"Joao S. O. Bueno"  wrote:

On 10 September 2013 18:06, Antoine Pitrou  wrote:

On Tue, 10 Sep 2013 17:38:26 -0300
"Joao S. O. Bueno"  wrote:

On 10 September 2013 16:08, Paul Moore  wrote:

If you provide "retain the last", I can't see any obvious way of
implementing "retain the first" in application code without in

effect

reimplementing the class.


Which reminds one - this class should obviously have a method for
retrivieng the original key value, given a matching key -

d.canonical('foo') -> 'Foo'


I don't know. Is there any use case?
(sure, it is trivially implemented)


Well, I'd expect it to simply be there. I had not thought of
other usecases for the transformdict itself -



I had the same thought.


Well, it is not here for dict, set, etc.


In those cases the key in the dict == the key you're looking for.


With the exception of numbers, of course (float vs int vs Decimal, etc.).


They'd still be ==, wouldn't they?


Yes, but for presentation purposes not identical.

--
~Ethan~
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Joao S. O. Bueno
On 10 September 2013 18:46, Antoine Pitrou  wrote:
> On Tue, 10 Sep 2013 18:44:20 -0300
> "Joao S. O. Bueno"  wrote:
>> On 10 September 2013 18:06, Antoine Pitrou  wrote:
>> > On Tue, 10 Sep 2013 17:38:26 -0300
>> > "Joao S. O. Bueno"  wrote:
>> >> On 10 September 2013 16:08, Paul Moore  wrote:
>> >> > If you provide "retain the last", I can't see any obvious way of
>> >> > implementing "retain the first" in application code without in effect
>> >> > reimplementing the class.
>> >>
>> >> Which reminds one - this class should obviously have a method for
>> >> retrivieng the original key value, given a matching key -
>> >>
>> >> d.canonical('foo') -> 'Foo'
>> >
>> > I don't know. Is there any use case?
>> > (sure, it is trivially implemented)
>>
>>
>> Well, I'd expect it to simply be there. I had not thought of
>> other usecases for the transformdict itself -
>
> Well, it is not here for dict, set, etc.

For the simple motive that once you retrieve or find that an
element is contained in one of these classes, you already
have the canonical key. :-)

>
>> For example, in latim languages it is common to want
>> accented letters to match their unaccented counterparts
>> - pick my own first name "João" - if I'd use a transform to strip
>> the diactriticals, and have an user input "joao" - it would match,
>> as intended - but I would not be able to retrieve the accented version
>> without re-implementing the class behavior.
>
> Interesting example, thanks.
>
> Regards
>
> Antoine.
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Add a "transformdict" to collections

2013-09-10 Thread Raymond Hettinger

On Sep 10, 2013, at 4:28 AM, Antoine Pitrou  wrote:

> In http://bugs.python.org/issue18986 I proposed adding a new mapping
> type to the collections module.

I would *really* like for this to start outside the standard library.
It needs to mature with user feedback before being dumped
in the collections module (which was never intended to be a
giant pile of every collection a person could think of).  

Adding yet more dictionary variants is an example of
way-too-many-ways-to-do-it.   


Raymond___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com