[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

What about SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14012] Misc tarfile fixes

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Lets push it. Lars?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18685] Restore re performance to pre-PEP393 level

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> Using #include "_sre.c" in _sre.c looks weird. Instead of huge sections 
> delimited by "#ifdef SRE_RECURSIVE", I would prefer something similar to the 
> stringlib. ".h" template files included more than once. I also expect shorter 
> files: _sre.c is close to 4000 lines of C code :-(

Agree, but a patch will be larger and harder for the synchronization and for 
the review in Rietveld. I'm going first solve other issues (issue18647, 
issue18672) before creating a large final patch.

> The value of SIZEOF_SRE_CHAR looks suspicious.

Good catch. Actually this macro is used only in order to skip some checks for 
UCS4. It should not affects the correctness, only possible the performance.

> Does test_re have some non-ASCII tests? If not, we should probably start by 
> adding such tests!

There is a small number (about 10) of tests for non-ASCII data.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I'm not really thrilled by the current implementation. The way it is done leads 
to duplication among socket constants. Also, if I create a socket from a 
numeric value (because a well-known socket family is known yet known by 
Python), then socket.family will fail.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +neologix

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread raymontag

New submission from raymontag:

Hello,

I would like to see an implementation for SSL/TLS pinning in the sll module of 
the standard library.

At this moment it's only possible to give the client a CAcert and check if the 
server's certificate is signed with this CA by creating a ssl.Context object 
with ssl.Context("/path/to/cafile"). If I don't know the server's certificate, 
that is I just have the root certificate, this is okay. But if I implement my 
own server/client structure I know the server's certificate. And here comes 
pinning into play: If I know server's certificate I could not only check if 
it's signed with my CA but also if it is the specific certificate I've signed. 
This is a better protection against MITM e.g. and would be a great enhancement 
of the ssl module IMHO.

raymontag

--
messages: 195130
nosy: raymontag
priority: normal
severity: normal
status: open
title: SSL/TLS pinning for the ssl module
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13647] Python SSL stack doesn't securely validate certificate (as client)

2013-08-14 Thread Christian Heimes

Changes by Christian Heimes :


--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15464] ssl: add set_msg_callback function

2013-08-14 Thread Christian Heimes

Changes by Christian Heimes :


--
assignee:  -> christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

TLS cert pinning should be possible with the implementation of #18293

--
nosy: +christian.heimes, giampaolo.rodola, janssen, pitrou
stage:  -> needs patch
versions: +Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread raymontag

raymontag added the comment:

Yep, that's exactly what I meant :)

--
resolution:  -> duplicate
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

If you want to check for a specific server certificate, then I guess it should 
be enough to expose the cert's fingerprint in the data returned by 
getpeercert().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

getpeercert() doesn't return Subject Public Key Info yet. It's on my TODO list. 
Chrome uses SPKI (PK algo + mod + exp) to pin certs, 
https://www.imperialviolet.org/2011/05/04/pinning.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread raymontag

raymontag added the comment:

Yeah, this was my first idea, too.

Are there at this moment other possibilities to implement pinning myself with 
the options the module provides me?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18736] Invalid charset in HTML pages inside documentation in CHM format

2013-08-14 Thread Basil Peace

New submission from Basil Peace:

HTML pages inside CHM documentation use the following tag to set applied 
character set:


`iso8859_1` is neither valid character set according to IANA registry nor is 
recognized by most browsers (I've checked IE, Firefox and Opera).

This isn't notable for text in English. But, in `Python Standard Library` in 
section `4.7.1 String Methods` there is a documentation for str.casefold(). 
This paragraph contains German letter `ß`.
Without defined character set this letter can be displayed wrongly, depending 
on user's regional settings. In my Russian I see in CHM `Я`. Firefox displays 
it as `�`.

Fix of charset to `ISO-8859-1` could resolve the problem.

P.S. Use of UTF-8 may be more convenient for preventing future errors.

--
assignee: docs@python
components: Documentation
messages: 195136
nosy: docs@python, grv87
priority: normal
severity: normal
status: open
title: Invalid charset in HTML pages inside documentation in CHM format
versions: Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> Are there at this moment other possibilities to implement pinning
> myself with the options the module provides me?

I don't think so. Perhaps you could use the serialNumber, but I'm not
sure how safe it is, even when restricting to a single CA cert.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

sha256(conn.getpeercert(True)) works until the cert gets e.g. more SAN fields.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread raymontag

raymontag added the comment:

That's not a good idea, a serial number could be faked.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> sha256(conn.getpeercert(True)) works until the cert gets e.g. more
> SAN fields.

Indeed, that's simply comparing the certificate by binary value. At this
point you don't even need a CA anymore, I guess :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> I have added documentation now so I think it is ready to merge
> (except for a change to Makefile).

Good for me. This is a very nice addition!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread raymontag

raymontag added the comment:

Great, that matches my needs exactly

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ah, good point. My only issue with the patch is that www.python.org will be 
resolved for every test method, even those that don't use remote_addr. This 
will make test_timeout unnecessarily slower.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-14 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
assignee: ncoghlan -> neologix
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18731] Increased test coverage for uu and telnet

2013-08-14 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18727] test for writing dictionary rows to CSV

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

You can probably use a StringIO for the file object, no need to create a 
temporary file.

--
nosy: +pitrou
stage:  -> patch review
versions: +Python 3.4 -Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18736] Invalid charset in HTML pages inside documentation in CHM format

2013-08-14 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

> I'm not really thrilled by the current implementation. The way it is done
> leads to duplication among socket constants.

Can you clarify which duplication you mean specifically? In the code review
tool, Serhiy proposed that instead of listing all the constants explicitly
in the Python code, we can just do:

AddressFamily = IntEnum('AddressFamily',
   {name: value for name, value in _moduledict.items()
if name.startswith('AF_')})

Is this less duplication?

> Also, if I create a socket from a numeric value (because a well-known
> socket family is known yet known by Python), then socket.family will fail.
>

Well, the documentation of socket.socket says it should be one of the AF_*
constants. One thing we can do is check in the socket.socket constructor
whether it's a known AF_* constants and fail early with a meaningful error
message. Would that be better?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

> What about SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW?
>

This is a proof of concept. As I mentioned in the original message starting
this issue - the SOCK_* constants will get the same treatment as AF_*
constants, once we decide what the right treatment is.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

We can do this in the setUpClass() method.

Or we can wrap the resolve_address() method with the @functools.lru_cache() 
decorator.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18606] Add statistics module to standard library

2013-08-14 Thread Mark Dickinson

Mark Dickinson added the comment:

Steven:  were you planning to start a discussion thread on python-dev for PEP 
450?  I see that there's some activity on python-list and on python-ideas, but 
I think most core devs would expect the main discussions to happen on the 
python-dev mailing list.  (And I suspect that many core devs don't pay 
attention to python-list very much.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> Can you clarify which duplication you mean specifically? In the code
> review
> tool, Serhiy proposed that instead of listing all the constants
> explicitly
> in the Python code, we can just do:
> 
> AddressFamily = IntEnum('AddressFamily',
>{name: value for name, value in _moduledict.items()
> if name.startswith('AF_')})

Yes, that's better.

> > Also, if I create a socket from a numeric value (because a
> > well-known
> > socket family is known yet known by Python), then socket.family
> > will fail.
> >
> 
> Well, the documentation of socket.socket says it should be one of the
> AF_*
> constants. One thing we can do is check in the socket.socket
> constructor
> whether it's a known AF_* constants and fail early with a meaningful
> error
> message. Would that be better?

Well, no. We should still allow creating sockets with unknown numeric
values. The .family attribute should then return the raw integer.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Christian Heimes

New submission from Christian Heimes:

ABCs are missing one important introspection feature. They have no API to get 
registered virtual subclasses. The patch implements a new method 
get_virtual_subclasses(recurse=False).

ABC.get_virtual_subclasses() returns the direct virtual subclasses of an ABC. 
ABC.get_virtual_subclasses(recuse=True) also takes subclasses of the ABC as 
well as subclasses of registered virtual classes into account.

Example:
>>> import numbers
>>> numbers.Number.get_virtual_subclasses()
set()
>>> numbers.Number.get_virtual_subclasses(True)
{, , , }
>>> numbers.Integral.get_virtual_subclasses()
{}
>>> numbers.Integral.get_virtual_subclasses(True)
{, }

--
components: Library (Lib)
files: virtual_subclasses.patch
keywords: patch
messages: 195150
nosy: christian.heimes, rhettinger, stutzbach
priority: normal
severity: normal
stage: patch review
status: open
title: Get virtual subclasses of an ABC
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file31290/virtual_subclasses.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I'm not sure "recurse" is a relevant distinction here. A subclass of a subclass 
is still a subclass. "Virtual" subclasses should not be different.

At the very least, if "recurse" is kept, I would expect it to be True by 
default.

--
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Another problem is what happens when an implementation uses non-"virtual" 
inheritance:

>>> issubclass(collections.UserDict, collections.abc.Mapping)
True
>>> collections.UserDict in collections.abc.Mapping.get_virtual_subclasses(True)
False

IOW, I think this get_virtual_subclasses() proposal is too low-level to be 
commonly useful, since it depends on implementation details (whether 
subclassing is direct or not, whether registering is implicit or explicit).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I'm surprised that test_repr is not failed. '%i' % socket.AddressFamily.AF_INET 
returns 'AddressFamily.AF_INET' instead of '2' as I expected. Is not this a bug 
in IntEnum implementation?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ran some benchmark numbers:

$ ./python -m timeit -s "from pprint import saferepr; s='é\"x' * 1000" 
"saferepr(s)"
-> before patch: 555 usec per loop
-> after patch: 10.9 usec per loop

$ ./python -m timeit -s "from pprint import saferepr; s='xxx' * 1000" 
"saferepr(s)"
-> before patch: 290 usec per loop
-> after patch: 8.68 usec per loop

--
nosy: +pitrou, serhiy.storchaka
stage:  -> patch review
versions: +Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

It's called get_VIRTUAL_subclasses() for a reason. You can get the real 
subclasses of an ABC with standard tool, e.g. recurse into __subclasses__(). 
For virtual subclasses you have to deal with the internals like _abc_registry. 
I could implement all four cases: recurse True/False, only virtual True/False. 
But I prefer not to do so.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

Attaching a new patch that uses Serhiy's suggestion to avoid the duplication, 
and uses Antoine's suggestion to keep socket.family working even if the family 
is an unknown numeric constant.

Note that the latter is challenging to test - I need families the OS knows and 
socket doesn't. Any suggestions are welcome. For the time being the test I 
cooked up is an abomination ;-)

--
Added file: http://bugs.python.org/file31291/socket-intenum-af.3.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

On Wed, Aug 14, 2013 at 6:24 AM, Serhiy Storchaka wrote:

>
> Serhiy Storchaka added the comment:
>
> I'm surprised that test_repr is not failed. '%i' %
> socket.AddressFamily.AF_INET returns 'AddressFamily.AF_INET' instead of '2'
> as I expected. Is not this a bug in IntEnum implementation?
>

I did notice it when playing with the implementation. Perhaps %i doesn't
call enum? Need to look into it more carefully...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> It's called get_VIRTUAL_subclasses() for a reason. You can get the
> real subclasses of an ABC with standard tool, e.g. recurse into
> __subclasses__().

What use case are you trying to solve? If I want to find out all classes
which implement an ABC, I don't care whether they implement it "virtually"
or not. OTOH, I do care that the results are stable and reliable, i.e.
that they don't change when someone changes from virtual inheritance to
real inheritance as an implementation detail.

For comparison, issubclass() doesn't make a difference between real and
virtual subclasses, or direct and recursive.

> For virtual subclasses you have to deal with the
> internals like _abc_registry. I could implement all four cases:
> recurse True/False, only virtual True/False.

I don't care about all four cases. What I'm saying is that only
"recurse=True, only virtual=False" makes sense from an user's POV.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

We can just remove "if typ is str:" case at all. A general case works for 
strings.

But for performance (this will slowdown Antoine's tests by 15-20%) we should 
left it and may be even extend it to other builtin types:

builtin_type = (str, int, float, NoneType, list, tuple, dict, set, bytes): # or 
may be use a set?
...
if typ in builtin_type:
return repr(object), True, False

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

Issue18738 created.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman

New submission from Ethan Furman:

While `.format()` works fine with enum, %-formatting does not:

--> class AF(enum.IntEnum):
...   IPv4 = 1
...   IPv6 = 2
... 

--> AF.IPv4


--> '%s' % AF.IPv4
'AF.IPv4'

--> '%r' % AF.IPv4
''

--> '%d' % AF.IPv4
'AF.IPv4'

--> '%i' % AF.IPv4
'AF.IPv4'

--> '%x' % AF.IPv4
'1'

--> '%o' % AF.IPv4
'1'

Hex and octal work, decimal and integer do not.

--
messages: 195160
nosy: barry, eli.bendersky, ethan.furman, serhiy.storchaka
priority: normal
severity: normal
status: open
title: % formatting incomplete for Enum
type: behavior
versions: Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

`.format()` is surprised too.

>>> '{:}'.format(AF.IPv4)
'AF.IPv4'
>>> '{:10}'.format(AF.IPv4)
' 1'

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

The manual list of AF_ prefixes looks ugly. We are going to run into the same 
problem for every module. How about an additional constructor that takes a 
name, dict and string prefix?

class IntEnum(int, Enum):
@classmethod
def from_moduledict(cls, name, moddict, prefix):
members = {name: value for name, value in moddict.items()
   if name.startswith(prefix)}
return cls(name, members)

>>> import socket, enum, pprint
>>> AddressFamily = enum.IntEnum.from_moduledict("AddressFamily", 
>>> socket.__dict__, "AF_")
>>> pprint.pprint(dict(AddressFamily.__members__))
{'AF_APPLETALK': ,
 'AF_ASH': ,
 'AF_ATMPVC': ,
 'AF_ATMSVC': ,
 'AF_AX25': ,
 'AF_BLUETOOTH': ,
 'AF_BRIDGE': ,
 'AF_CAN': ,
 'AF_DECnet': ,
 'AF_ECONET': ,
 'AF_INET': ,
 'AF_INET6': ,
 'AF_IPX': ,
 'AF_IRDA': ,
 'AF_KEY': ,
 'AF_LLC': ,
 'AF_NETBEUI': ,
 'AF_NETLINK': ,
 'AF_NETROM': ,
 'AF_PACKET': ,
 'AF_PPPOX': ,
 'AF_RDS': ,
 'AF_ROSE': ,
 'AF_ROUTE': ,
 'AF_SECURITY': ,
 'AF_SNA': ,
 'AF_TIPC': ,
 'AF_UNIX': ,
 'AF_UNSPEC': ,
 'AF_WANPIPE': ,
 'AF_X25': }

--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eric V. Smith

Changes by Eric V. Smith :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

In Objects/unicodeobject.c when it gets into mainformatlong, an IntEnum is 
recognized as an integer (passes PyLong_Check) and goes into formatlong. There, 
in the cases of 'd', 'i', 'u' it has:

case 'u':
/* Special-case boolean: we want 0/1 */
if (PyBool_Check(val))
result = PyNumber_ToBase(val, 10);
else
result = Py_TYPE(val)->tp_str(val);
break;

So tp_str is invoked...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

Christian, this is an interesting idea - but I suggest we review it once we 
actually get to convert "many modules". For the time being the manual listing 
is gone in the recent patch, and for a number of constant families in the same 
module (i.e. SOCK_* that will be added here) we can combine the lookup into a 
single loop - so no need walking the module dict multiple times.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

> I thing the AddressFamily enum class and the family property should be
> documented.
>

I'm leaving the documentation to the end when we decide on the
implementation strategy. Once that happens I'll post a patch with .rst
changes, etc.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18606] Add statistics module to standard library

2013-08-14 Thread Ethan Furman

Changes by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I thing the AddressFamily enum class and the family property should be 
documented.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18720] Switch suitable constants in the socket module to IntEnum

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Nitpick: If we have grouped this constants in an enum class perhaps it will be 
good if they will be enumerated in the order of its values. Or no?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

'{:}'.format(AF.IPv4) is incorrect, but '{:10}'.format(AF.IPv4) behaves as it 
should.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

Looks like Objects/unicodeobject.c needs the same enhancement that 
Modules/_json.c received: convert int/float subclasses into actual ints/floats 
before continuing.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

Ethan, str.format uses __format__. We don't seem to provide a custom one.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

On Wed, Aug 14, 2013 at 6:55 AM, Serhiy Storchaka wrote:

>
> Serhiy Storchaka added the comment:
>
> `.format()` is surprised too.
>
> >>> '{:}'.format(AF.IPv4)
> 'AF.IPv4'
> >>> '{:10}'.format(AF.IPv4)
> ' 1'
>
>
Oh, this looks like a bug in str.format (and probably the %i behavior too).
Python allows subclassing int and providing custom __str__/__repr__. The
formatting tools should behave sensically in this situation.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eli Bendersky

Changes by Eli Bendersky :


--
title: % formatting incomplete for Enum -> String formatting (% and str.format) 
issues with Enum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

Gotcha.  I'm on it.

--
assignee:  -> ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3b82e0d83bf9 by Richard Oudkerk in branch 'default':
Issue #8713: Support alternative start methods in multiprocessing on Unix.
http://hg.python.org/cpython/rev/3b82e0d83bf9

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Gregory P. Smith

New submission from Gregory P. Smith:

This is a very odd inconsistency in math.log behavior.  That said, it is 
probably only a single bit imprecision at the end of the float result.  Still, 
10 == 10L so I'd expect math.log of both to give the same result.

oss/cpython/2.7:LOAS$ ./python
Python 2.7.5+ (2.7:395ac61ebe1a, Aug 14 2013, 07:11:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.log(10) - math.log(10L)
4.440892098500626e-16
>>> math.log(10)
2.302585092994046
>>> math.log(10L)
2.3025850929940455
>>> 

In Python 3.3 things seem fine and match the int behavior from 2.7 above 
despite the internal number implementation being a PyLong in 3.x:

>>> math.log(10)
2.302585092994046

--
messages: 195175
nosy: gregory.p.smith
priority: normal
severity: normal
status: open
title: math.log of a long returns a different value of math.log of an int
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

Fascinating, how did you find the issue?

--
nosy: +christian.heimes, mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18698] importlib.reload() does not return the module in sys.modules

2013-08-14 Thread Brett Cannon

Brett Cannon added the comment:

I think you mean in 3.3 and yes. =) Patch LGTM so I say fix in 3.3 and merge 
into default.

--
assignee:  -> eric.snow

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-14 Thread Richard Oudkerk

Richard Oudkerk added the comment:

> Good for me. This is a very nice addition!

Thanks.  

I do see a couple of failed assertions on Windows which presumably happen in a 
child process because they do not cause a failure:

Assertion failed: !collecting, file ..\Modules\gcmodule.c, line 1617

The assertion is in _PyGC_CollectNoFail() and checks that it is not called 
recursively.  See


http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/2510/steps/test/logs/stdio

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

The %-formatting needs to be handled by str, correct?

What is '{:}' supposed to mean?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

> What is '{:}' supposed to mean?
> 

It should be the same as '{}'. That is, an empty format string.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> I do see a couple of failed assertions on Windows which presumably
> happen in a child process because they do not cause a failure:
> 
> Assertion failed: !collecting, file ..\Modules\gcmodule.c, line
> 1617
> 
> The assertion is in _PyGC_CollectNoFail() and checks that it is not
> called recursively.  See
> 
> 
> http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/2510/steps/test/logs/stdio

That's extremely weird. _PyGC_CollectNoFail() is only called from
PyImport_Cleanup, which itself is only called from Py_Finalize()
and Py_EndInterpreter(). It should be basically impossible for the
GC to be already collecting garbage at that point... 

Perhaps you could try to find out in which test this happens?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Christian Heimes

Christian Heimes added the comment:

I like to do something similar to marker interfaces [1] with ABCs. For 
introspection and documentation I need a way to get all non-abstract classes 
that are implemented by an ABC.

How about I change the implementation to get_subclasses(direct=False) to return 
all virtual and real subclasses of an ABC? I can filter out abstract types with 
inspect.isabstract() later.

[1] http://www.muthukadan.net/docs/zca.html#marker-interfaces

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18737] Get virtual subclasses of an ABC

2013-08-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> I like to do something similar to marker interfaces [1] with ABCs.
> For introspection and documentation I need a way to get all
> non-abstract classes that are implemented by an ABC.

You mean that implement an ABC? But you also need to return real
subclasses that implement the ABC (e.g. UserDict in the example above).

> How about I change the implementation to get_subclasses(direct=False)
> to return all virtual and real subclasses of an ABC? I can filter
> out abstract types with inspect.isabstract() later.

Sounds ok.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

Which is the same as '%s', yes?  In that case, the current behavior of 
'{:}'.format(AF.IPv4) is correct, isn't it?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Tim Peters

Tim Peters added the comment:

Yup - 2.7 evaluates this in a less precise way, as

log(10L) = log(10./16 * 2**4) = log(0.625) + log(2)*4

>>> log(10L) == log(0.625) + log(2)*4
True

This patterns works well even for longs that are far too large to represent as 
a double; e.g.,

>>> log(1L << 5)
34657.35902799726

which is evaluated internally as log(0.5) + log(2) * 50001:

>>> log(1L << 5) == log(0.5) + log(2) * 50001
True

Python 3 is more careful, falling back to this pattern _only_ if converting the 
long to a double overflows.  Of course 10L can be represented exactly as a 
double, so Python 3 evaluates it directly as log(float(10L)) = log(10.0).  It's 
minor difference overall, but definitely visible ;-)

--
nosy: +tim_one

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18740] str is number methods don't recognize '.'

2013-08-14 Thread Ron Adam

New submission from Ron Adam:

Shouldn't at least isdecimal return True?

>>> '123.0'.isdecimal()
False
>>> '123.0'.isalnum()
False
>>> '123.0'.isnumeric()
False
>>> '123.0'.isdigit()
False

--
components: Interpreter Core
messages: 195186
nosy: ron_adam
priority: normal
severity: normal
status: open
title: str is number methods don't recognize '.'
type: behavior
versions: Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Gregory P. Smith

Gregory P. Smith added the comment:

We found this while refactoring an API to be more consistent about returning 
longs vs ints in specific cases.  This resulted in another unittest that was 
using math.log for a nicer display of the value by magnitude to fail as the 
result was slightly different for the two input types.

arguably that is a fragile test as it cares about the last couple bits of a 
float... but that such a test exists does suggest that making a future 2.7.6+ 
release more pedantic about the behavior on values that safely fit into a 
double might break an odd test or three out there.  OTOH, it makes things more 
consistent all around and match 3.x in both cases so I'm still be for doing it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18740] str is number methods don't recognize '.'

2013-08-14 Thread Ned Deily

Ned Deily added the comment:

isdecimal() is working as documented, isn't it?  A period character serving as 
a decimal point is not the same as a decimal character.

"Return true if all characters in the string are decimal characters and there 
is at least one character, false otherwise. Decimal characters are those from 
general category “Nd”. This category includes digit characters, and all 
characters that can be used to form decimal-radix numbers, e.g. U+0660, 
ARABIC-INDIC DIGIT ZERO."

--
nosy: +ned.deily

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

I think:

>>> '{:}'.format(AF.IPv4)
'AF.IPv4'

is correct, assuming str(AF.IPv4) is 'AF.IPv4'. I'm not sure what:

>>> '{:10}'.format(AF.IPv4)

should produce. There's a special case for an empty format string calling str().

I think that specifying __format__() would be best, except then you need to 
decide what sort of format specification language you want to support, and deal 
with all of the implementation details. Or, maybe just have Enum's __format__ 
be:

def __format__(self, fmt):
return format(str(self), fmt)

which makes the format specification language match str's.

%-formatting is a whole different thing, of course.

--
assignee: ethan.furman -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

> Eric V. Smith added the comment:
>
> I think that specifying __format__() would be best, except then you need to 
> decide what sort of format specification language you want to support, and 
> deal with all of the implementation details. Or, maybe just have Enum's 
> __format__ be:
>
>  def __format__(self, fmt):
>  return format(str(self), fmt)
>
> which makes the format specification language match str's.

I disagree.  A subclass shouldn't have to write code to provide the /same/ 
behavior as its superclass, just code for 
different behavior.  In the cases of
 '%d' % int_subclass
or
 '{:d}'.format(int_subclass)

str should be smart enough to actually produce the numeric value, not rely on 
the subclass' __repr__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18718] datetime documentation contradictory on leap second support

2013-08-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5063dab96843 by David Wolever in branch '2.7':
Issue #18718: datetime documentation contradictory on leap second support
http://hg.python.org/cpython/rev/5063dab96843

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

>>
>> I think that specifying __format__() would be best, except then you need to 
>> decide what sort of format specification language you want to support, and 
>> deal with all of the implementation details. Or, maybe just have Enum's 
>> __format__ be:
>>
>>  def __format__(self, fmt):
>>  return format(str(self), fmt)
>>
>> which makes the format specification language match str's.
> 
> I disagree.  A subclass shouldn't have to write code to provide the /same/ 
> behavior as its superclass, just code for 
> different behavior.  In the cases of
>  '%d' % int_subclass
> or
>  '{:d}'.format(int_subclass)
> 
> str should be smart enough to actually produce the numeric value, not rely on 
> the subclass' __repr__.

I'm not sure which "str" you mean here: "str should be smart enough to
actually produce the numeric value".

For the format version, what gets called is:

int_subclass.__format__('d'), which is int.__format__(int_subclass,
'd'), which produces '1', assuming int(int_subclass) is 1.

So, there's no "str" involved anywhere, except the one on which
.format() is called ('{:d}'), and it doesn't know about the types of any
arguments or what the format specifiers mean, so it can't make any
decisions.

Which is why it's easier to think of this in terms of:
format(int_subclass, 'd')

instead of:
'{:d}'.format(int_subclass)

It's int_subclass, and only int_subclass, that gets to decide what the
format specifier means. We can either let it fall back to int.__format__
(the default), or str.__format__ (which I suggest above), or it can do
it's own custom thing with the format specifier.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Tim Peters

Tim Peters added the comment:

FYI, the improvement was made in these 2 changesets:

c8dc4b5e54fb
a9349fd3d0f7

If desired, those could presumably be grafted back into the 2.7 branch.

The commit messages refer to issue #9599, but that appears to be mistaken.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

> Eric V. Smith added the comment:
>
> For the format version, what gets called is:
>
> int_subclass.__format__('d'), which is int.__format__(int_subclass,
> 'd'), which produces '1', assuming int(int_subclass) is 1.

Ah, I didn't realize.  Thanks.

> So, there's no "str" involved anywhere, except the one on which
> .format() is called ('{:d}'), and it doesn't know about the types of any
> arguments or what the format specifiers mean, so it can't make any
> decisions.

As far as format goes, I don't think there is a problem.  It's behaving just 
like it should (which makes sense, since 
IntEnum is derived from int and is already using int's __format__ by default).

The problem, then, is just with %-formatting, which is squarely a str (aka 
Objects/unicodeobject.c) issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-14 Thread Tim Peters

Tim Peters added the comment:

OK, the correct one is issue #9959.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18740] str is number methods don't recognize '.'

2013-08-14 Thread Brett Cannon

Brett Cannon added the comment:

Ned is right, everything is working as documented and intended: as a way to 
avoid using a regex to test a simple case instead of trying to do anything 
fancy like identify a number.

--
nosy: +brett.cannon
resolution:  -> rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

On Wed, Aug 14, 2013 at 11:48 AM, Ethan Furman wrote:

>
> Ethan Furman added the comment:
>
> > Eric V. Smith added the comment:
> >
> > For the format version, what gets called is:
> >
> > int_subclass.__format__('d'), which is int.__format__(int_subclass,
> > 'd'), which produces '1', assuming int(int_subclass) is 1.
>
> Ah, I didn't realize.  Thanks.
>
> > So, there's no "str" involved anywhere, except the one on which
> > .format() is called ('{:d}'), and it doesn't know about the types of any
> > arguments or what the format specifiers mean, so it can't make any
> > decisions.
>
> As far as format goes, I don't think there is a problem.  It's behaving
> just like it should (which makes sense, since
> IntEnum is derived from int and is already using int's __format__ by
> default).
>

I'm not sure I understand. The discrepancy between {:} and {:10} is clearly
a problem.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

For format, I think the question is "should an IntEnum format like an int, with 
the wacky exception of a specifier of '', or should it always format like a 
str?"

I assumed we'd want it to look like the str() version of itself, always. But 
it's debatable.

I agree the %-formatting question is different, and I further think there's not 
much we can do there.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

On Wed, Aug 14, 2013 at 11:56 AM, Eric V. Smith wrote:

>
> Eric V. Smith added the comment:
>
> For format, I think the question is "should an IntEnum format like an int,
> with the wacky exception of a specifier of '', or should it always format
> like a str?"
>
> I assumed we'd want it to look like the str() version of itself, always.
> But it's debatable.
>
> I agree the %-formatting question is different, and I further think
> there's not much we can do there.
>

How about always being a string, unless integer formatting "%i" / {d} is
explicitly requested?

The alternative (always a string) is also fine, but the behavior should be
consistent. Certainly field-width-justification ({:}) can't affect the
formatting.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


--
nosy: +jcea

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18293] ssl.wrap_socket (cert_reqs=...), getpeercert, and unvalidated certificates

2013-08-14 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


--
nosy: +jcea

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18735] SSL/TLS pinning for the ssl module

2013-08-14 Thread Jesús Cea Avión

Jesús Cea Avión added the comment:

This technique is used in Mercurial and I use it in my projects too.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

> Eric V. Smith added the comment:
>
> I assumed we'd want it to look like the str() version of itself, always. But 
> it's debatable.

An IntEnum's str and repr should be (and any format or % codes that are the 
equivalent) the Enum str and repr.  The % 
and format codes that specifically call for a numeric representation should 
give that numeric representation (format is 
good here, % is not).

> For format, I think the question is "should an IntEnum format like an int, 
> with the wacky exception of a specifier of '', or should it always format 
> like a str?"
>

I think for format we should treat IntEnums as ints unless the s or r codes are 
specifically used.

> I agree the %-formatting question is different, and I further think there's 
> not much we can do there.

We can have unicodeobject.c convert int (and float) subclasses to actual ints 
and floats before getting the numeric 
value (we just did this to _json.c so it could serialize IntEnums).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

On Wed, Aug 14, 2013 at 12:07 PM, Ethan Furman wrote:

>
> Ethan Furman added the comment:
>
> > Eric V. Smith added the comment:
> >
> > I assumed we'd want it to look like the str() version of itself, always.
> But it's debatable.
>
> An IntEnum's str and repr should be (and any format or % codes that are
> the equivalent) the Enum str and repr.  The %
> and format codes that specifically call for a numeric representation
> should give that numeric representation (format is
> good here, % is not).
>
> > For format, I think the question is "should an IntEnum format like an
> int, with the wacky exception of a specifier of '', or should it always
> format like a str?"
> >
>
> I think for format we should treat IntEnums as ints unless the s or r
> codes are specifically used.
>

As I wrote above, I rather see it differently. The original intent of Enums
was to have string representation in most cases. So this should be the
default, since most of the time this is what the user wants. No one really
passes explicit s/r codes. In the minority, specialized cases, where the
user wants to force int-like formatting, then the number should be given
and not the member name. This would also be consistent with non-decimal
formatting options like %x and the .format equivalent.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18740] str is number methods don't recognize '.'

2013-08-14 Thread Ron Adam

Ron Adam added the comment:

I get the same resluts if I make the string by str(123.0).  I was thinking it 
should test True for the isdecimal case for that.

It seems I missunderstood their purpose/use.  This seems like it would be a 
very common misunderstanding.

It appears, (Because it isn't stated in the doc strings), that they are for 
testing what specific sub-group of unicode data, the individual character(s) 
are in.  I think the methods doc strings should say this and be worded so they 
are more character specific.  

   """ Tests each character, and returns true if
all of them are in the unicode ___ sub-group. """

As for testing weather or not a string as a whole represents a number value, it 
seems try/except is still the best way.  :-/

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18740] str is number methods don't recognize '.'

2013-08-14 Thread Brett Cannon

Brett Cannon added the comment:

Feel free to submit an issue suggesting better docstrings as that sounds like 
it could stand to get some TLC.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13504] Meta-issue for "Invent with Python" IDLE feedback

2013-08-14 Thread Kurt B. Kaiser

Changes by Kurt B. Kaiser :


--
nosy: +kbk

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

I think IntEnum should act like a str for format() purposes. After all, having 
a useful string representation is a prime reason it exists. If you want it to 
act like a str() sometimes, and an int() at others, you're going to have to 
parse the format specifier and figure out what to do. It might be as easy as:

def __format__(self, fmt):
  if len(fmt) >= 1 and fmt[-1] in 'oOxXdD':
# treat like an int
return format(self.value, fmt)
  else:
# treat like a string
format(str(self), fmt)

But I haven't completely thought it through or tested it.

Or, couldn't we just say it's always str, and if you want to treat it like an 
int then use .value?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

Okay, I see your points.  I can certainly agree with going with the str 
representation when no numeric code is specified.  But, if a numeric code is 
specified (x, b, d, etc.) then the numeric value should be used.

Agreed?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Ethan Furman

Ethan Furman added the comment:

On 08/14/2013 11:55 AM, Eli Bendersky wrote:
>
> I'm not sure I understand. The discrepancy between {:} and {:10} is clearly
> a problem.

Ah, you're right.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-14 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch which adds fast path for builtin scalar types.

Or we can just remove a special case for strings.

--
Added file: http://bugs.python.org/file31292/pprint_safe_repr_scalars.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eli Bendersky

Eli Bendersky added the comment:

>
> Okay, I see your points.  I can certainly agree with going with the str
> representation when no numeric code is specified.  But, if a numeric code
> is specified (x, b, d, etc.) then the numeric value should be used.
>
> Agreed?
>

 Yes. I suggest to wait a day or two for others to react (night in Europe,
etc). If this sounds good to everyone then it may make sense to split this
issue to one for str.format and another for legacy % formatting, because
the implementation is likely to be different.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18677] Enhanced context managers with ContextManagerExit and None

2013-08-14 Thread Kristján Valur Jónsson

Kristján Valur Jónsson added the comment:

"locally visible" is, I think a very misleading term.  How is

with ignore_error, acquire_resource as r:
   doo_stuff_with_resource(r) #can be silently skipped

any more locally visible than
with acquire_resource_ignore_error as r:
doo_stuff_with resource(r) # can be silently skipped.

? does the "nested with" syntax immediatelly tell you "hey, the body can be 
silently skipped"?

Requiring that some context manager patterns must be done with a special syntax 
is odd.  What is more, it prohibits us to abstract away context managers.  For 
instance, you can write a function like this

def execute_with_context(ctxt, fn, args):
with ctxt:
return fn(*args)

but if your context manager is of the kind mentioned, i.e. requiring the double 
syntax, you are screwed.

Basically, what I'm proposing (and what the patch provides) is that you can 
write this code:
@contextmanager
def nestedc(ca, cb):
with ca as a, cb as b:
yield a, b

and have it work for _all_ pair of ca, cb.  This then, allows context managers 
to be used like abstract entities, like other objects in the language.  It is 
_not_ about flow control, but about completeness.

A similar pattern for functions is already possible:
def nestedf(fa, fb):
def helper(v):
return fa(fb(v))
return helper

And so, we could write:
execute_with_context(nestedc(ca, cb), nestedf(fa, fb), ('foo',))

Current python does not allow this for arbitrary pairs ca, cb.  My version 
does.  This is what I'm advocating.  That programmers are given the tool to 
combine context managers if they want.
 

As for "contextlib.nested()".
I'm not necessarily advocation its resuciation in the standardlib, but adding 
that to the patch here to demonstrate how it now _works_.

Here is a simpler version of contextlib.nested:

@contextmanager
def nested_empty():
yield []

@contextmanager
def nested_append(prev, next):
with prev as a, next as b:
a.append(b)
yield a

def nested(*managers):
total = nested_empty()
for mgr in managers:
total = nested_append(total, mgr)
return total

Pretty nice, no?

Now we come to the argument with nested(open(a), open(b)).
I see your point, but I think that the problem is not due to nested, but to 
open.  Deprecating nested, even as a programming pattern demonstration is 
throwing out the baby with the bathwater.

I´ve coined the term "hybrid context manager" (at least I think I have)to mean 
resources that are their own context managers.  They're hybrid because they are 
acquired explicitly, but can be released via a context manager.  The context 
manager is a bolt on, an afterthought.  Instead of adding __exit__() to files, 
and allowing
with open(fn) as f: pass
We should have encouraged the use of proper context managers:
with opened(fn) as f: pass
or 
with closing(f):  pass

Now, we unfortunately have files being context managers and widely see the 
pattern
with open(fn) as f, open(fn2) as f2:
pass

But how is this bug here:
with nested(open(fn), open(fn2)) as f, f2: pass

any more devuiys than
f, f2 = open(fn), open(fn2)
with f, f2: pass
?

The problem is that files aren't "real" context managers but "hybrids" and this 
is what we should warn people about.  The fact that we do have those hybrids in 
our code base should not be cause to remove tools that are designed to work 
with "proper" context managers.

The decision to remove "nested" on these grounds sets the precedence that we 
cannot have any functions that operate on context managers.  In fact, what this 
is really is saying is this:

"context managers should only be used with the "with" statement and only 
instantiated in-line.
Anything else may introduce sublte bugs because some context managers are in 
fact not context managers, but the resource that they manage.
"

In my opinion, it would have been better to deprecate the use of files as 
context managers, and instead urge people to use proper context managers for 
the:  (the proposed) contextlib.opened and (the existing) contextlib.closing)

K

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18727] test for writing dictionary rows to CSV

2013-08-14 Thread Muhammad Jehanzeb

Muhammad Jehanzeb added the comment:

Thanks Antoine,

Attached is the updated version of patch using StringIO

--
Added file: http://bugs.python.org/file31293/issue18727_v2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18738] String formatting (% and str.format) issues with Enum

2013-08-14 Thread Eric V. Smith

Eric V. Smith added the comment:

If IntEnum.__format__ is going to parse the format string, it's a little 
fragile. For example, say we modify int.__format__ to understand a "Z" 
presentation type. Who's going to remember to update IntEnum.__format__?

For reference, the existing integer formats are: "bdoxXn".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4749] Issue with RotatingFileHandler logging handler on Windows

2013-08-14 Thread Piotr Dobrogost

Changes by Piotr Dobrogost :


--
nosy: +piotr.dobrogost

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >