Dictionaries with variable default.

2014-11-03 Thread Antoon Pardon
Is it possible to have a default dictionary where the default is dependant
on the key?

I was hoping something like this might work:
 m = defaultdict(lambda key: key+1)

But it obviously doesn't:
 m[3]

Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: lambda() takes exactly 1 argument (0 given)

-- 
Antoon Pardon
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dictionaries with variable default.

2014-11-03 Thread Chris Angelico
On Mon, Nov 3, 2014 at 10:04 PM, Antoon Pardon
antoon.par...@rece.vub.ac.be wrote:
 Is it possible to have a default dictionary where the default is dependant
 on the key?

 I was hoping something like this might work:
 m = defaultdict(lambda key: key+1)

 But it obviously doesn't:
 m[3]

 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: lambda() takes exactly 1 argument (0 given)

Yes, but not with the defaultdict. Instead, just implement __missing__:

class KeyPlusOne(dict):
def __missing__(self, key): return key+1

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Jean-Michel Pichavant
- Original Message -
 From: Gregory Ewing greg.ew...@canterbury.ac.nz
 Steven D'Aprano wrote:
  Like all good Pythonistas[1], we hate Java and think that
  getter/setter
  methods are pointless. But come on, they're not *wrong*,
 
 What's wrong is the statement that getters and setters
 are necessary to allow the implementation to change
 without changing the interface. That's factually
 incorrect in regard to Python.
 
 --
 Greg

I'm not sure that is what the course was stating:

The advantage of
following this practice is that the implementer of the class
definition (often someone other than the user of the class) may
restructure the organization of the data fields associated with the
object while avoiding the need to rewrite code that uses the class.

I agree with Steven on that one, while getters/setters are not the preferred 
way, they are not utterly wrong.
Python uses the descriptor protocol which is basically getters and setters. 
It's is just hidden by a strange decorator syntax.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


support for boost::python for build double object

2014-11-03 Thread Joseph Shen
In the boost::python library there is a function

 boost::python::long_

and this function return a boost::python::object variable

I'm trying to wrap a double variale but I can't find 
something just like

  boost::python::double_

can someone help me to build a double object 

PS.
I know there are some functions in pure python c api like 

 PyFloat_FromDouble

and after create the object I can wrap it in boost::python::object

but all I want is same api from boost::python library

I can't find what I want

tanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: support for boost::python for build double object

2014-11-03 Thread Skip Montanaro
On Mon, Nov 3, 2014 at 7:53 AM, Joseph Shen joseph.sm...@gmail.com wrote:

 In the boost::python library there is a function

  boost::python::long_

 and this function return a boost::python::object variable

 I'm trying to wrap a double variable but I can't find
 something just like

   boost::python::double_

 can someone help me to build a double object


Is there a boost::python::float_ function? If so, does it produce a 32-bit
(C float) or 64-bit (C double) number?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: support for boost::python for build double object

2014-11-03 Thread Joseph Shen
On Monday, November 3, 2014 10:11:01 PM UTC+8, Skip Montanaro wrote:
 On Mon, Nov 3, 2014 at 7:53 AM, Joseph Shen joseph...@gmail.com wrote:
 
 In the boost::python library there is a function
 
 
 
  boost::python::long_
 
 
 
 and this function return a boost::python::object variable
 
 
 
 I'm trying to wrap a double variable but I can't find
 
 something just like
 
 
 
   boost::python::double_
 
 
 
 can someone help me to build a double object
 Is there a boost::python::float_ function? If so, does it produce a 32-bit (C 
 float) or 64-bit (C double) number?
 
 
 Skip

thanks for reply,

no there is no such function like float_ or double_ or float32_ etc.

I'm reading the boost source code right now to find something

wish me good luck
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Ian Kelly
On Nov 2, 2014 5:31 AM, Denis McMahon denismfmcma...@gmail.com wrote:
 And perhaps that also addresses the square - rectangle (or circle -
 ellipse) issue - square, rectangle and rhombus are all forms of
 quadrilateral, and perhaps should all inherit a base class Quadrilateral,
 rather than trying (and partially failing) to inherit each other.

No, it doesn't matter whether you have square inheriting from rectangle,
rhombus or quadrilateral. If the base class has mutator methods, you're
still going to have this problem when they allow the object to be mutated
in ways that violate the restrictions of the subclass.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: support for boost::python for build double object

2014-11-03 Thread Mark Lawrence

On 03/11/2014 13:53, Joseph Shen wrote:

In the boost::python library there is a function


boost::python::long_


and this function return a boost::python::object variable

I'm trying to wrap a double variale but I can't find
something just like


  boost::python::double_


can someone help me to build a double object

PS.
I know there are some functions in pure python c api like


PyFloat_FromDouble


and after create the object I can wrap it in boost::python::object

but all I want is same api from boost::python library

I can't find what I want

tanks.



I'm sorry that I can't help directly but try here 
https://mail.python.org/mailman/listinfo/cplusplus-sig which is also 
available as gmane.comp.python.c++


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Chris Angelico
On Tue, Nov 4, 2014 at 12:50 AM, Dennis Lee Bieber
wlfr...@ix.netcom.com wrote:
 On Mon, 3 Nov 2014 03:12:32 + (UTC), Denis McMahon
 denismfmcma...@gmail.com declaimed the following:

So:

Quadrilateral
Parallelogram
Square
Rectangle
Rhombus
Diamond (4 sides eq)
Trapezoid
Arrowhead

Is an arrowhead a trapezoid?

 I'd probably indent square under rectangle, and indent diamond where 
 it
 is -- both being restrictions on rectangle/rhombus

 But we may need another category, convex and concave; the arrowhead
 would fall into the concave grouping.

That's fine if you're creating a taxonomical hierarchy of immutables,
but neither works if you're creating a mutable class hierarchy that
follows LSP. The only way you can make any of this work (as someone
suggested earlier, I believe) is by having __new__ potentially return
a subclass, so if you ask Parallelogram to give you one with all sides
equal and all angles equal, it gives you back a Square. But since a
square is a special form of rhombus as well as a special form of
rectangle, you'd have to use multiple inheritance or an AST-style
subclass hook to verify. Of course, if you're going down that route,
you probably want to take this up a level and have a Shape class, and
have the subclass hook simply check if it's four-sided as well.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Simon Evans
I input 'pip install html5lib' to the Python 2.7 console and got :

 pip install html5lib
  File stdin, line 1
pip install html5lib
  ^
SyntaxError: invalid syntax


I am not sure what you mean about 'single line paragraphs'. I put my text 

into double line spacing in my last missive, I left the code input/ output 

in single line spacing as that is how it reads from the console, after all 

who am I to alter it? Regarding 'context' if you are referring to the text 

I am using, it is from 'Getting Started in Beautiful Soup' by Vineeth G.

Nair. 

For what its worth some of the subsequent code in the book runs, but not 

all, and I think this may be due to the parser installation factor, and I 

wanted to work through the book (112 pages) without any errors being 

returned. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Chris Angelico
On Tue, Nov 4, 2014 at 3:27 AM, Simon Evans musicalhack...@yahoo.co.uk wrote:
 I input 'pip install html5lib' to the Python 2.7 console and got :

 pip install html5lib
   File stdin, line 1
 pip install html5lib
   ^
 SyntaxError: invalid syntax


This should be run from your command interpreter - cmd.exe, bash, or
whatever you normally run programs from.

 I am not sure what you mean about 'single line paragraphs'. I put my text

 into double line spacing in my last missive, I left the code input/ output

 in single line spacing as that is how it reads from the console, after all

 who am I to alter it? Regarding 'context' if you are referring to the text

 I am using, it is from 'Getting Started in Beautiful Soup' by Vineeth G.

 Nair.

Why the double line spacing? I don't get that... and I think that's
what was meant.

Context in this context means quoted text from previous posts.

http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

The parts with the angle brackets at the beginning are quoted text,
providing context for what you're saying.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parsing Python dictionary with multiple objects

2014-11-03 Thread Anurag Patibandla
json_split = {}
value = {Status: Submitted, m_Controller: Python}
a = range(31)
del a[0]
for i in a:
json_split[i] = value
keys = json_split.keys()
order = list(keys)
q1 = int(round(len(keys)*0.2))
q2 = int(round(len(keys)*0.3))
q3 = int(round(len(keys)*0.5))
b = [q1,q2,q3]
n=0
threedicts = []
for i in b:
queues = order[n:n+i]
n = n+i
lists = [(queues[j], json_split.get(queues[j])) for j in range(len(queues))]
onedict = {}
for q in queues:
onedict[q] = json_split[q]
threedicts.append (onedict)
queue1, queue2, queue3 = threedicts
keys1 = queue1.keys()
for i in keys1:
queue1[i]['Priority'] = ['1']
keys2 = queue2.keys()
for j in keys2:
queue2[j]['Priority'] = ['2']
keys3 = queue3.keys()
for z in keys3:
queue3[z]['Priority'] = ['3']

I am trying to add a key value pair of (Priority:1) to queue1, 
(Priority:2) to queue2, and (Priority:3) to queue3.
When I just add (Priority:1) to queue1, it works.
But when I run the above code, (Priority:3) is being added to all the 
queues.
This looks trivial and I don't understand why this is happening. Is there 
something wrong with what I am doing?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Simon Evans
I input to the cmd console  'pip install html5lib' but again got an error 
return. I thought one of the participants was unhappy about single line spacing 
(re: single line paragraphs') Okay I will go back to single line spacing, I 
don't think it is all that important, really.
Anyway this is my console's response:- 


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atompip install html5lib
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Intel Atom  
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Mark Lawrence

On 03/11/2014 21:28, Simon Evans wrote:

I input to the cmd console  'pip install html5lib' but again got an error 
return. I thought one of the participants was unhappy about single line spacing 
(re: single line paragraphs') Okay I will go back to single line spacing, I 
don't think it is all that important, really.


Thank you for being so inconsiderate.  Yet another single line paragraph 
that stretches out well over the horizon.  Add that to the potential for 
double line spacing and all we end up with is a right mess.  You've also 
replied without any context again.



Anyway this is my console's response:-


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atompip install html5lib
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Intel Atom




Either you haven't installed pip (it comes with the Python 3.4 
installer) or it's not on your path.  In my installation I've pip.exe, 
pip3.4.exe and pip3.exe in C:\Python34\Scripts so what have you in your 
equivalent and what is your path set to?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Greg Ewing

Jean-Michel Pichavant wrote:


I agree with Steven on that one, while getters/setters are not the preferred
way, they are not utterly wrong.


I'm not saying that they're wrong in general, only that
they're wrong for *Python*.

This matters, because the course in question is purportedly
teaching Python. To make a blanket statement like that in
a Python course, without pointing out that it applies
*only* to some languages *other* than Python, is grossly
misleading.

Now it may be that the quotation is taken out of context,
and the instructor did in fact point this out, but the
way the paragraph is worded, it sounds like it's just
been blindly lifted from some Java or C++ book.
--
Greg

--
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-11-03 Thread Albert van der Horst
In article mailman.15076.1413990100.18130.python-l...@python.org,
Ned Batchelder  n...@nedbatchelder.com wrote:
On 10/22/14 5:27 AM, ast wrote:

 Chris Angelico ros...@gmail.com a écrit dans le message de
 news:mailman.15058.1413968065.18130.python-l...@python.org...
 On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote:
 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?

 In fact i have (-1)**N with N an integer potentially big.

 Exponentiation is far more efficient than the naive implementation of
 iterated multiplication.

 In the very particular case of (-1)**N,  I belive that Python check
 the odd or even parity of N and provides the result accordingly.

 I tried:
 (-1)**10
 1
 (-1)**11
 -1

 and it is instantaneous



Keep in mind that actually calculating the exponentiation wouldn't do
10 multiplications anyway: the clever
way to do integer powers is by squaring based on the binary
representation of the exponent.  It's explained here:
http://stackoverflow.com/a/101613/14343

So even if Python is actually calculating the value, it's only doing 75
multiplications or so.

I'm pretty sure that if we replace -1 by 2 , it never gets at its 75-th
multiplication.


--
Ned Batchelder, http://nedbatchelder.com

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Denis McMahon
On Mon, 03 Nov 2014 06:29:39 +, Dan Sommers wrote:

 On Mon, 03 Nov 2014 03:12:32 +, Denis McMahon wrote:
 
 Quadrilateral
 Parallelogram
 Square Rectangle Rhombus Diamond (4 sides eq)
 Trapezoid
 Arrowhead
 
 What's the difference between a Diamond and a Rhombus?

Oops, I was thinking a rhombus was a general parallelogram, my mistake.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Gregory Ewing

Denis McMahon wrote:

On Mon, 03 Nov 2014 06:29:39 +, Dan Sommers wrote:




What's the difference between a Diamond and a Rhombus?


Oops, I was thinking a rhombus was a general parallelogram, my mistake.


Some diamonds are neither rhombuses nor parallelograms:

http://minecraft.gamepedia.com/Diamond

More a sort of irregular hexagon...

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-11-03 Thread Gregory Ewing

Jean-Michel Pichavant wrote:

Python uses the descriptor protocol which is
basically getters and setters. It's is just hidden by a strange decorator
syntax.


This is about the interface, not the implementation.
Getters and setters in this context means designing
the API of your class to have things like getFoo() and
setFoo() in it. That's not just totally unnecessary in
Python, it's counterproductive. It makes the API
tedious to use for no benefit.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


[issue22457] load_tests not invoked in root __init__.py when start=package root

2014-11-03 Thread Robert Collins

Changes by Robert Collins robe...@robertcollins.net:


Added file: http://bugs.python.org/file37118/issue22457.patch

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



[issue22784] test_asyncio fails without the ssl module

2014-11-03 Thread Antoine Pitrou

Antoine Pitrou added the comment:

The problem is the default value for `purpose` in the function declaration (the 
signature mocks the ssl.create_default_context() function, so I don't think 
it's ok to change the default parameter value here).

--

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



[issue22650] set up and use VM for net access in the test suite

2014-11-03 Thread Georg Brandl

Georg Brandl added the comment:

Nice! How do you plan to organize its setup?

--

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



[issue8350] Document lack of support for keyword arguments in C functions

2014-11-03 Thread Yongzhi Pan

Changes by Yongzhi Pan panyong...@gmail.com:


--
nosy: +fossilet

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



[issue21650] add json.tool option to avoid alphabetic sort of fields

2014-11-03 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


Added file: http://bugs.python.org/file37119/issue21650_v4.diff

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

 I don't want to change the kind of exception being raised (an API change from
 AttributeError to TypeError) without a really good reason.

Subclasses cannot work with the current implementation.

 In general, in-place methods are not required to return NotImplemented (for
 example, (3).__iadd__(4.5) raises an AttributeError).

AttributeError is being raised because int does not have an __iadd__ method, 
not because of a problem with the float operand.

 Also, I prefer the current AttributeError with its clear indication that an 
 items()
 method is needed for duck-typing.  These kind of error messages are very 
 helpful
 when you're trying to figure-out how to duck-type on-purpose

That's what the docs are for.

 (for example, {}.update(1) and {}.update([[]]) both provide the information 
 about
 what you would need to do to get update() to work).

update is not a binary operation, so has more leeway in how it handles problems.

 The current duck-typeable behavior was an intended part of the design and is 
 no
 different from a number of other methods that update in-place.

The only problem with the design is that it does not play well with others.  
For duck-typeable just do a check on 'other' to see if it has an .items() 
method, and return NotImplemented if it does not.  Oh, and check that 'self' is 
Counter, and also return NotImplemented if that fails.

 At any rate, I want to avoid unnecessary API churn (and avoid contributing to
 what Guido has called a death by a thousand cuts for the growing list of 
 tiny
 semantic differences between Python 2 and Python 3).

Not an issue in this case, as the 2.7 Counter does not have the in-place 
methods.

Here's proof of subclass trouble -- the idea is to make an immutable Counter:
-
from collections import Counter

class FrozenCounter(Counter):

immutable after definition

def __add__(self, other):
new_counter = self.__class__()
for elem, count in self.items():
new_counter[elem] = count
for elem, count in other.items():
new_counter[elem] += count
return new_counter._keep_positive()

fc = FrozenCounter(abbc)
sc = FrozenCounter(bubba)
original = fc
fc += sc
assert fc == FrozenCounter(aabcu)
assert fc is not original
-

and the results:
-
Traceback (most recent call last):
  File blah.py, line 20, in module
assert fc is not original
AssertionError
-

For subclassing to work, the fix is:

if not hasattr(other, 'items') or type(self) is not Counter:
return NotImplemented

--

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



[issue6721] Locks in the standard library should be sanitized on fork

2014-11-03 Thread Nir Soffer

Changes by Nir Soffer nir...@gmail.com:


--
nosy: +nirs

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



[issue22753] urllib2 localnet Changed test to lookup IP-address of localhost

2014-11-03 Thread Håkan Lövdahl

Håkan Lövdahl added the comment:

Yes, I can confirm that changing 'URL' to be 'http://127.0.0.1' works. I think 
that would be a solution to this.

--

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



[issue22650] set up and use VM for net access in the test suite

2014-11-03 Thread R. David Murray

R. David Murray added the comment:

Why a separate domain rather than a subdomain?  I'm not objecting, but I am 
curious.

--

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-11-03 Thread R. David Murray

R. David Murray added the comment:

On Mon, 03 Nov 2014 10:53:09 +, Ethan Furman rep...@bugs.python.org wrote:
 
 Ethan Furman added the comment:
 
  I don't want to change the kind of exception being raised (an API change 
  from
  AttributeError to TypeError) without a really good reason.
 
 Subclasses cannot work with the current implementation.

I don't understand this statement.

  Also, I prefer the current AttributeError with its clear indication that an 
  items()
  method is needed for duck-typing.  These kind of error messages are very 
  helpful
  when you're trying to figure-out how to duck-type on-purpose
 
 That's what the docs are for.

That's not the way it works in real life.  You implement something, it
doesn't work, and if the solution isn't obvious from the error message
*then* you look at the docs or google.  But if the error message says
you can't do this, then like as not you don't even look at the docs.

  (for example, {}.update(1) and {}.update([[]]) both provide the information 
  about
  what you would need to do to get update() to work).
 
 update is not a binary operation, so has more leeway in how it handles 
 problems.

As Raymond pointed out, the augmented assignment operator is a
*shortcut* for update.

  The current duck-typeable behavior was an intended part of the design and 
  is no
  different from a number of other methods that update in-place.
 
 The only problem with the design is that it does not play well with others.  
 For duck-typeable just do a check on 'other' to see if it has an .items() 
 method, and return NotImplemented if it does not.  Oh, and check that 'self' 
 is Counter, and also return NotImplemented if that fails.

No, that doesn't support duck typing.  Duck typing is not putting
arbitrary restrictions on what objects you accept, but only essential
restrictions.  And as noted above, if you return NotImplemented, then
you get an error message that essentially says this is impossible
instead of this is what didn't work.

 Here's proof of subclass trouble -- the idea is to make an immutable Counter:

Your subclass doesn't override __iadd__ or any of the other mutation
methods.  Why would you expect it to be immutable if it doesn't?

 For subclassing to work, the fix is:
 
 if not hasattr(other, 'items') or type(self) is not Counter:
 return NotImplemented

I've never seen a type check like that in a Python class, and I hope
I never do.  *That* breaks subclassing.

--

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



[issue2504] Add gettext.pgettext() and variants support

2014-11-03 Thread Wichert Akkerman

Wichert Akkerman added the comment:

Bump.

Python 3 is still not on my radar, but I'll happily do a backport for Py2 and 
drop that on PyPI once this gets resolved.

--
versions: +Python 3.3, Python 3.4, Python 3.5, Python 3.6

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



[issue2504] Add gettext.pgettext() and variants support

2014-11-03 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
stage: patch review - needs patch
versions:  -Python 3.2, Python 3.3, Python 3.4, Python 3.6

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



[issue22650] set up and use VM for net access in the test suite

2014-11-03 Thread Donald Stufft

Donald Stufft added the comment:

It is configured using salt, see 
https://github.com/python/psf-salt/blob/master/salt/pythontest/init.sls.

A separate domain just makes it easier to do whatever we need with it without 
needing to worry about getting confused between live sites and test sites.

--

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



[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Till Maas

New submission from Till Maas:

https://github.com/python/cpython/commit/71a4ee3ea2c6847b9fc4b33cbc8d565a7bf2424a

introduces a regression in ssl.SSLContext.load_cert_chain()

https://github.com/python/cpython/blob/2.7/Modules/_ssl.c#L2462

With this change it is not possible to specify None as keyfile which can 
be triggered on Debian Testing? (there the change is backported) in 
requests.get(https://example.com;, cerf=keycert.pem). It can also be 
triggered with the sample code in the attached file. It is fixed in recent 
python 3.

--
components: Library (Lib)
files: poc.txt
messages: 230539
nosy: till
priority: normal
severity: normal
status: open
title: ssl.SSLContext.load_cert_chain() backport regression with None as keyfile
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file37120/poc.txt

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



[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Till Maas

Till Maas added the comment:

sorry, it should be:
requests.get(https://example.com;, cert=keycert.pem)

--

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



[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Alex Gaynor

Changes by Alex Gaynor alex.gay...@gmail.com:


--
nosy: +alex, christian.heimes, dstufft, giampaolo.rodola, janssen, pitrou

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

% ./python Lib/test/regrtest.py -v test_urllib2_localnet
== CPython 3.4.2+ (3.4:7be6ef737aaf+, Nov 3 2014, 10:03:11) [GCC 4.8.3]
==   
Linux-3.16.5-gentoo-x86_64-Intel-R-_Core-TM-_i7-2860QM_CPU_@_2.50GHz-with-gentoo-2.2
 little-endian
==   hash algorithm: siphash24 64bit
==   /home/benjamin/dev/python/3.4/build/test_python_28724
Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, 
dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, 
verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0)
[1/1] test_urllib2_localnet
test_basic_auth_httperror (test.test_urllib2_localnet.BasicAuthTests) ... ok
test_basic_auth_success (test.test_urllib2_localnet.BasicAuthTests) ... ok
test_proxy_qop_auth_int_works_or_throws_urlerror 
(test.test_urllib2_localnet.ProxyAuthTests) ... ok
test_proxy_qop_auth_works (test.test_urllib2_localnet.ProxyAuthTests) ... ok
test_proxy_with_bad_password_raises_httperror 
(test.test_urllib2_localnet.ProxyAuthTests) ... ok
test_proxy_with_no_password_raises_httperror 
(test.test_urllib2_localnet.ProxyAuthTests) ... ok
test_200 (test.test_urllib2_localnet.TestUrlopen) ... ok
test_200_with_parameters (test.test_urllib2_localnet.TestUrlopen) ... ok
test_404 (test.test_urllib2_localnet.TestUrlopen) ... ok
test_bad_address (test.test_urllib2_localnet.TestUrlopen) ... skipped Use of 
the 'network' resource not enabled
test_basic (test.test_urllib2_localnet.TestUrlopen) ... ok
test_chunked (test.test_urllib2_localnet.TestUrlopen) ... ok
test_geturl (test.test_urllib2_localnet.TestUrlopen) ... ok
test_https (test.test_urllib2_localnet.TestUrlopen) ... Got an error:
[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:600)
stopping HTTPS server
joining HTTPS thread
ERROR
test_https_sni (test.test_urllib2_localnet.TestUrlopen) ... Got an error:
[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:600)
stopping HTTPS server
joining HTTPS thread
ERROR
test_https_with_cadefault (test.test_urllib2_localnet.TestUrlopen) ... stopping 
HTTPS server
Got an error:
[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:600)
joining HTTPS thread
ok
test_https_with_cafile (test.test_urllib2_localnet.TestUrlopen) ... Got an 
error:
[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:600)
stopping HTTPS server
joining HTTPS thread
stopping HTTPS server
joining HTTPS thread
ok
test_info (test.test_urllib2_localnet.TestUrlopen) ... ok
test_iteration (test.test_urllib2_localnet.TestUrlopen) ... ok
test_line_iteration (test.test_urllib2_localnet.TestUrlopen) ... ok
test_redirection (test.test_urllib2_localnet.TestUrlopen) ... ok
test_sending_headers (test.test_urllib2_localnet.TestUrlopen) ... ok

==
ERROR: test_https (test.test_urllib2_localnet.TestUrlopen)
--
Traceback (most recent call last):
  File /home/benjamin/dev/python/3.4/Lib/urllib/request.py, line 1182, in 
do_open
h.request(req.get_method(), req.selector, req.data, headers)
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 1090, in request
self._send_request(method, url, body, headers)
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 1128, in 
_send_request
self.endheaders(body)
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 1086, in 
endheaders
self._send_output(message_body)
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 924, in 
_send_output
self.send(msg)
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 859, in send
self.connect()
  File /home/benjamin/dev/python/3.4/Lib/http/client.py, line 1230, in connect
server_hostname=sni_hostname)
  File /home/benjamin/dev/python/3.4/Lib/ssl.py, line 364, in wrap_socket
_context=self)
  File /home/benjamin/dev/python/3.4/Lib/ssl.py, line 584, in __init__
self.do_handshake()
  File /home/benjamin/dev/python/3.4/Lib/ssl.py, line 811, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 
(_ssl.c:600)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File /home/benjamin/dev/python/3.4/Lib/test/test_urllib2_localnet.py, line 
548, in test_https
data = self.urlopen(https://localhost:%s/bizarre; % handler.port)
  File /home/benjamin/dev/python/3.4/Lib/test/test_urllib2_localnet.py, line 
455, in urlopen
f = urllib.request.urlopen(url, data, **kwargs)
  File /home/benjamin/dev/python/3.4/Lib/urllib/request.py, line 161, in 
urlopen
return opener.open(url, data, timeout)
  File /home/benjamin/dev/python/3.4/Lib/urllib/request.py, line 463, in open
response = self._open(req, data)
  File /home/benjamin/dev/python/3.4/Lib/urllib/request.py, line 481, in _open
'_open', req)
  File 

[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Alex Gaynor

Changes by Alex Gaynor alex.gay...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file37121/issue22787.diff

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Alex Gaynor

Alex Gaynor added the comment:

Latest patch fixes the urllib2_localnet tests.

--
Added file: http://bugs.python.org/file37122/issue22417.diff

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



[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Alex Gaynor

Changes by Alex Gaynor alex.gay...@gmail.com:


--
keywords: +needs review

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



[issue22784] test_asyncio fails without the ssl module

2014-11-03 Thread Guido van Rossum

Guido van Rossum added the comment:

OK, them LGTM.

--

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-11-03 Thread Jim Jewett

Jim Jewett added the comment:

If I know that a Counter (or any class X) can be updated in place, I will be 
surprised to find out that I'm using a different instance after a successful 
in-place operation.

I would even consider that (replacement of the original instance) a security 
risk, though it is mitigated by the fact that I don't see how to exploit it 
without already being able to create arbitrary subclasses.

 For subclassing to work, the fix is:
 
 if not hasattr(other, 'items') or type(self) is not Counter:
 return NotImplemented

That breaks for Counter subclasses on the left hand side -- even a trivial 
subclass to change the repr would fail unless the _i* methods were all 
re-implemented, either by the otherwise-trivial Counter subclass or by the 
right-hand objects.  If you start making it work for the obvious cases, you 
just make the failure conditions more obscure.

--
nosy: +Jim.Jewett

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



[issue22676] _pickle's whichmodule() is slow

2014-11-03 Thread Steve Dower

Steve Dower added the comment:

The fix for this now uses module without initializing it, which could lead to a 
crash if get_dotted_path() tries to raise an exception (it puts module into the 
error string with %R). See Modules/_pickle.c#l1656 and Modules/_pickle.c#l1538.

I think the fix is to initialize module with Py_None and currently there's no 
need to bump the refcount (though I'm always wary of doing that in case things 
change in the future). If that sounds right I'm happy to put the fix in, else 
Antoine can do it :)

--
nosy: +steve.dower

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



[issue22676] _pickle's whichmodule() is slow

2014-11-03 Thread Steve Dower

Steve Dower added the comment:

(Looks like I was outsmarted by the tracker when trying to put line numbers in 
my links... is there a way to do that?)

--

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

Ethan stated:
 The only problem with the design is that it does not play well with others.  
 For
 duck-typeable just do a check on 'other' to see if it has an .items() 
 method, and
 return NotImplemented if it does not.  Oh, and check that 'self' is Counter, 
 and
 also return NotImplemented if that fails.

R. David Murray replied:
 No, that doesn't support duck typing.  Duck typing is not putting arbitrary
 restrictions on what objects you accept, but only essential restrictions.

__iadd__ will raise an AttributeError if 'other' doesn't have an 'items' method 
-- how is that an arbitrary restriction?

If 'other' doesn't have an 'items' but does know how to add itself to Counter, 
it won't matter because Counter is raising an exception instead of returning 
NotImplemented.  

What other types return NotImplemented when 'other' is not the expected 
(sub)type?  bytes, bytearray, int, float, string, dict, list, tuple, Enum, 
deque, defaultdict, OrderedDict, Decimal, Fraction, and Counter itself for 
every binary method /except/ the four inplace ops it supplies itself.

 And as noted above, if you return NotImplemented, then you get an error 
 message
 that essentially says this is impossible instead of this is what didn't 
 work.

Correct implementation should not be sacrificed for a nicer error message.

 Here's proof of subclass trouble -- the idea is to make an immutable Counter:
 [snip example]

 Your subclass doesn't override __iadd__ or any of the other mutation methods. 
  Why
 would you expect it to be immutable if it doesn't?

You're right, that was a bad example.  A subclass would need to override any 
method whose behavior it wants to change.

What does not seem correct to me is raising an exception because the type of 
'other' is not correct, instead of returning NotImplemented, and in 14 other 
core datatypes it does work that way, and even in Counter it works that way for 
any in-place method that Counter itself doesn't override, and it does work that 
way /in/ Counter for the normal binary ops that it /does/ override.

 For subclassing to work, the fix is:
 
 if not hasattr(other, 'items') or type(self) is not Counter:
 return NotImplemented

 I've never seen a type check like that in a Python class, and I hope I never 
 do.  *That*
 breaks subclassing.

Explanations and examples go a lot further than bare statements.

[Jim Jewitt posts an explanation.]

Ah, I see.  Thank you, Jim.

Okay, I agree that the check against the base class is ill-advised (and I 
modified some of the above reply to match that understanding).

However, I am still unconvinced that 'other' should not be checked.  Hopefully 
the python-dev thread will shed more light on this.

--

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Alex Gaynor

Alex Gaynor added the comment:

Fix for the failing test_ssl testes.

--
Added file: http://bugs.python.org/file37123/issue22417.diff

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



[issue22788] allow HTTPHandler to take an SSLContext

2014-11-03 Thread Benjamin Peterson

New submission from Benjamin Peterson:

It would be nice if HTTPHandler could take an SSLContext as a parameter, which 
would be passed to HTTPSConnection to configure the security of the connection.

--
components: Library (Lib)
messages: 230549
nosy: benjamin.peterson, vinay.sajip
priority: normal
severity: normal
stage: needs patch
status: open
title: allow HTTPHandler to take an SSLContext
type: enhancement
versions: Python 3.5

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



[issue1539381] Add readinto method to StringIO and cStringIO

2014-11-03 Thread Silvio Ricardo Cordeiro

Silvio Ricardo Cordeiro added the comment:

BufferedReader assumes that readinto is defined, but that's not the case for 
StringIO's. In the end, this cripples StringIO objects, because their data can 
never be peek()'ed as with all other file objects.

--
components: +IO -Library (Lib)
nosy: +silvioricardoc
type:  - behavior
versions: +Python 2.7, Python 3.2 -Python 2.6

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



[issue22788] allow HTTPHandler to take an SSLContext

2014-11-03 Thread Alex Gaynor

Alex Gaynor added the comment:

I'm not sure I follow, where does HTTPHandler ever construct an HTTPSConnection?

--
nosy: +alex

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



[issue22788] allow HTTPHandler to take an SSLContext

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

emit()

On Mon, Nov 3, 2014, at 15:33, Alex Gaynor wrote:
 
 Alex Gaynor added the comment:
 
 I'm not sure I follow, where does HTTPHandler ever construct an
 HTTPSConnection?
 
 --
 nosy: +alex
 
 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue22788
 ___

--

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



[issue22788] allow HTTPHandler to take an SSLContext

2014-11-03 Thread Alex Gaynor

Alex Gaynor added the comment:

Hah! I didn't realize you meant *logging.handlers.HTTPHandler*, I thought you 
meant *urllib.request.HTTPHandler*.

--

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



[issue22788] allow logging.handlers.HTTPHandler to take an SSLContext

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

Right then...

--
title: allow HTTPHandler to take an SSLContext - allow 
logging.handlers.HTTPHandler to take an SSLContext

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 2afe5413d7af by Benjamin Peterson in branch '3.4':
PEP 476: enable HTTPS certificate verification by default (#22417)
https://hg.python.org/cpython/rev/2afe5413d7af

New changeset 731375f83406 by Benjamin Peterson in branch 'default':
merge 3.4 (#22417)
https://hg.python.org/cpython/rev/731375f83406

--
nosy: +python-dev

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

Okay, 3.4/3.5 have been dealt with. I had to hack up test_logging a bit. 
(#22788 would make that better). 2.7 now needs a backport.

--

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



[issue7559] TestLoader.loadTestsFromName swallows import errors

2014-11-03 Thread Domen Kožar

Domen Kožar added the comment:

Could we backport this one to 3.x and 2.7? It's leads to really bad UX.

--

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



[issue22788] allow logging.handlers.HTTPHandler to take an SSLContext

2014-11-03 Thread Alex Gaynor

Alex Gaynor added the comment:

Quick pass at a patch. No docs, and it should proabbly be an error to pass 
context with secure=False.

--
keywords: +needs review, patch
Added file: http://bugs.python.org/file37124/issue22788.diff

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

Okay, the python-dev ruling is in, and raising an exception in the __ixxx__ 
methods is allowed, and even a good idea in the cases of mutable containers.

However, doing the check on 'other' and raising a TypeError with an appropriate 
message would still be better for a couple reasons:

  - all the non-inplace operations raise TypeError when 'other' is not a 
correct type
  - __iand__ is currently buggy because it does not do the check

If backwards compatibility is a concern in this case, a custom TypeError that 
was a subclass of both TypeError and AttributeError could address that.

--

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



[issue22735] Fix various crashes exposed through mro() customization

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

Thank you for the patchset. I wonder if we should just forbid most reentrancy 
i.e. set a flag on the type when it's being constructed and not let 
type_set_bases be called then. Setting __bases__ from within mro() doesn't seem 
very useful outside of producing pathologies.

--

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

+   Special value which should be returned by the special methods
+   (:meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, etc.) to indicate
+   that the operation is not implemented with respect to the other type.

After a discussion on python-dev, I think this wording could be even clearer.  
How about:

Special value which should be returned by the binary special methods
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
etc.) to indicate that the operation is not implemented with respect to
the other type; may be returned by the in-place binary special methods
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.

--
status: closed - open

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



[issue22366] urllib.request.urlopen should take a context (SSLContext) argument

2014-11-03 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

Please update versionchanged to 3.4.3 on default branch.

--

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



[issue21650] add json.tool option to avoid alphabetic sort of fields

2014-11-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

LGTM.

--
stage: patch review - commit review

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread R. David Murray

R. David Murray added the comment:

Sounds OK to me.  There should already be a discussion of the consequences of 
returning it (I don't remember where, though), and it would be nice to link to 
that discussion.

Note that any doc change should be applied to 3.4 first, and then merged to 3.5.

--
versions: +Python 3.4

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



[issue7559] TestLoader.loadTestsFromName swallows import errors

2014-11-03 Thread R. David Murray

R. David Murray added the comment:

I would love that, but I think the fix depends on a feature.  Robert will know 
for sure.

--

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

I found these items:

Doc/c-api/object.rst

.. c:var:: PyObject* Py_NotImplemented

   The ``NotImplemented`` singleton, used to signal that an operation is
   not implemented for the given type combination.


Doc/extending/newtypes.rst
---
where the operator is one of ``Py_EQ``, ``Py_NE``, ``Py_LE``, ``Py_GT``,
``Py_LT`` or ``Py_GT``.  It should compare the two objects with respect to the
specified operator and return ``Py_True`` or ``Py_False`` if the comparison is
successful, ``Py_NotImplemented`` to indicate that comparison is not
implemented and the other object's comparison method should be tried, or *NULL*
if an exception was set.


Doc/Library/numbers.rst
---
Implementing the arithmetic operations
~~

We want to implement the arithmetic operations so that mixed-mode
operations either call an implementation whose author knew about the
types of both arguments, or convert both to the nearest built in type
and do the operation there. For subtypes of :class:`Integral`, this
means that :meth:`__add__` and :meth:`__radd__` should be defined as::

class MyIntegral(Integral):

def __add__(self, other):
if isinstance(other, MyIntegral):
return do_my_adding_stuff(self, other)
elif isinstance(other, OtherTypeIKnowAbout):
return do_my_other_adding_stuff(self, other)
else:
return NotImplemented

def __radd__(self, other):
if isinstance(other, MyIntegral):
return do_my_adding_stuff(other, self)
elif isinstance(other, OtherTypeIKnowAbout):
return do_my_other_adding_stuff(other, self)
elif isinstance(other, Integral):
return int(other) + int(self)
elif isinstance(other, Real):
return float(other) + float(self)
elif isinstance(other, Complex):
return complex(other) + complex(self)
else:
return NotImplemented


There are 5 different cases for a mixed-type operation on subclasses
of :class:`Complex`. I'll refer to all of the above code that doesn't
refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as
boilerplate. ``a`` will be an instance of ``A``, which is a subtype
of :class:`Complex` (``a : A : Complex``), and ``b : B :
Complex``. I'll consider ``a + b``:

1. If ``A`` defines an :meth:`__add__` which accepts ``b``, all is
   well.
2. If ``A`` falls back to the boilerplate code, and it were to
   return a value from :meth:`__add__`, we'd miss the possibility
   that ``B`` defines a more intelligent :meth:`__radd__`, so the
   boilerplate should return :const:`NotImplemented` from
   :meth:`__add__`. (Or ``A`` may not implement :meth:`__add__` at
   all.)
3. Then ``B``'s :meth:`__radd__` gets a chance. If it accepts
   ``a``, all is well.
4. If it falls back to the boilerplate, there are no more possible
   methods to try, so this is where the default implementation
   should live.
5. If ``B : A``, Python tries ``B.__radd__`` before
   ``A.__add__``. This is ok, because it was implemented with
   knowledge of ``A``, so it can handle those instances before
   delegating to :class:`Complex`.


Doc/library/datetime.rst

   In other words, ``date1  date2`` if and only if ``date1.toordinal() 
   date2.toordinal()``. In order to stop comparison from falling back to the
   default scheme of comparing object addresses, date comparison normally raises
   :exc:`TypeError` if the other comparand isn't also a :class:`date` object.
   However, ``NotImplemented`` is returned instead if the other comparand has a
   :meth:`timetuple` attribute.  This hook gives other kinds of date objects a
   chance at implementing mixed-type comparison. If not, when a :class:`date`
   object is compared to an object of a different type, :exc:`TypeError` is 
raised
   unless the comparison is ``==`` or ``!=``.  The latter cases return
   :const:`False` or :const:`True`, respectively.


Doc/reference/expressions.rst
-
Comparisions

...
Comparison of objects of differing types depends on whether either of the
types provide explicit support for the comparison.  Most numeric types can be
compared with one another.  When cross-type comparison is not supported, the
comparison method returns ``NotImplemented``.


Ahha!  I think I found it (nearly at the end, of course):

Doc/reference/datamodel.rst
---
The standard type hierarchy
===
...
NotImplemented
   .. index:: object: NotImplemented

   This type has a single value.  There is a single object with this value. This
   object is accessed through the built-in name ``NotImplemented``. Numeric 
methods
   and rich comparison 

[issue22780] NotImplemented doc section needs update

2014-11-03 Thread R. David Murray

R. David Murray added the comment:

I was actually thinking of the Implementing the arithmetic operations section.  
Maybe we should copy the parenthetical from the datamodel description into the 
text you are modifying, and then link to the implementing section.

--

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-11-03 Thread Benjamin Peterson

Benjamin Peterson added the comment:

Somehow the Windows bots are failing to verify python.org 
http://buildbot.python.org/all/builders/x86%20XP-4%203.x/builds/11179/steps/test/logs/stdio

--

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



[issue22788] allow logging.handlers.HTTPHandler to take an SSLContext

2014-11-03 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

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



[issue22650] set up and use VM for net access in the test suite

2014-11-03 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Not to mention possible cookie tests, I suppose.
(I would personally have preferred something like comfychair.net, but I guess 
pythontest.net is ok too :-))

--
nosy: +pitrou

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



[issue826897] Proto 2 pickle vs dict subclass

2014-11-03 Thread Tim Graham

Tim Graham added the comment:

Cookie pickling issue should be fixed in #22775.

--
nosy: +Tim.Graham

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



[issue22787] ssl.SSLContext.load_cert_chain() backport regression with None as keyfile

2014-11-03 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e54d0b197c82 by Benjamin Peterson in branch '2.7':
allow keyfile argument to be None (closes #22787)
https://hg.python.org/cpython/rev/e54d0b197c82

--
nosy: +python-dev
resolution:  - fixed
stage:  - resolved
status: open - closed

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-11-03 Thread Tim Graham

Tim Graham added the comment:

Georg, how do want to proceed with this issue? Should we backport #16611 
(support for parsing secure/httponly flag) to 3.2 to fix this regression and 
then create a separate issue to fix the lax parsing issue on all versions?

--

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



[issue20160] broken ctypes calling convention on MSVC / 64-bit Windows (large structs)

2014-11-03 Thread Steve Dower

Steve Dower added the comment:

Patch looks good to me, but given this issue, #11835, #22733, and probably 
more, should we be integrating from libffi (which apparently has fixes for some 
of these) more often? I know nothing about how we move code between that and 
ctypes.

--
nosy: +steve.dower

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



[issue17896] Move Windows external libs from src\..\ to src\externals

2014-11-03 Thread Zachary Ware

Zachary Ware added the comment:

Good point, David.  Jeremy, Trent, you're the only other Windows buildbot 
operators as far as I know; feel free to clean up the old externals locations 
as you like.

Also, sorry to make it a bit hairier to operate, but I think this is a big 
enough improvement for day-to-day development that I definitely don't want to 
change back.  For the record, it is fairly easy to just move out the externals 
folder, do whatever you need to with the repository, and move it back in 
without having to rebuild OpenSSL or Tcl/Tk/Tix.

--
nosy: +jeremy.kloth

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



[issue22725] improve documentation for enumerate() (built-in function)

2014-11-03 Thread Tshepang Lekhonkhobe

Tshepang Lekhonkhobe added the comment:

@raymond

Why do you say that 'sequence' is a keyword?

 enumerate()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: Required argument 'sequence' (pos 1) not found

That means that 'sequence' can be changed to 'iterable' without worrying about 
backwards compatibility.

--
nosy: +tshepang

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



[issue22789] Compress the marshalled data in PYC files

2014-11-03 Thread Raymond Hettinger

New submission from Raymond Hettinger:

Save space and reduce I/O time (reading and writing) by compressing the 
marshaled code in  files.

In my code tree for Python 3, there was a nice space savings 19M to 7M.  Here's 
some of the output from my test:

8792 - 4629 ./Tools/scripts/__pycache__/reindent.cpython-35.pyc
1660 - 1063 ./Tools/scripts/__pycache__/rgrep.cpython-35.pyc
1995 - 1129 ./Tools/scripts/__pycache__/run_tests.cpython-35.pyc
1439 -  973 ./Tools/scripts/__pycache__/serve.cpython-35.pyc
 727 -  498 ./Tools/scripts/__pycache__/suff.cpython-35.pyc
3240 - 1808 ./Tools/scripts/__pycache__/svneol.cpython-35.pyc
   74866 -23611 ./Tools/scripts/__pycache__/texi2html.cpython-35.pyc
5562 - 2870 ./Tools/scripts/__pycache__/treesync.cpython-35.pyc
1492 -  970 ./Tools/scripts/__pycache__/untabify.cpython-35.pyc
1414 -  891 ./Tools/scripts/__pycache__/which.cpython-35.pyc
19627963 -  6976410 Total

I haven't measured it yet, but I believe this will improve Python's start-up 
time (because fewer bytes get transferred from disk).

--
files: compress_pyc.py
messages: 230576
nosy: rhettinger
priority: normal
severity: normal
stage: needs patch
status: open
title: Compress the marshalled data in PYC files
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file37125/compress_pyc.py

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



[issue22719] os.path.isfile os.path.exists bug in while loop

2014-11-03 Thread Zachary Ware

Zachary Ware added the comment:

Aaron, what version of Python are you using on what version of Windows?  Also, 
32 or 64 bit on both?

I can't reproduce this with any Python 3.3.6 or newer on 64-bit Windows 8.1.

--

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



[issue22725] improve documentation for enumerate() (built-in function)

2014-11-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

static PyObject *
 Why do you say that 'sequence' is a keyword?

It is a keyword argument to enumerate().  Here's the relevant section of code:

enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
enumobject *en;
PyObject *seq = NULL;
PyObject *start = NULL;
static char *kwlist[] = {sequence, start, 0};

if (!PyArg_ParseTupleAndKeywords(args, kwds, O|O:enumerate, kwlist,
 seq, start))
return NULL

--

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

FWIW, I think doc changes like this need to be made by the people most familiar 
with the implementation details and with the original design intent (i.e. the 
authors of PEP 207).

The knowledge here is fragile and it would be easy to accidentally make-up new 
normative rules that aren't actually true or necessary, or to subtly 
misrepresent what was trying to be accomplished originally.  The risk is 
greatest when the OP is just now learning the ins and outs of NotImplemented 
(i.e. whether in-place operations can or should return NotImplemeted or whether 
those operations can be duck typed).

Changing can be returned to should be returned is normative (making-up a 
new rule without sufficient discussion).  This doesn't add explanation; 
instead, instead, it make a rule change about how a feature should be used.
https://hg.python.org/cpython/rev/26d0a17affb5

--
nosy: +gvanrossum, rhettinger, tim.peters

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
Removed message: http://bugs.python.org/msg230579

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



[issue22789] Compress the marshalled data in PYC files

2014-11-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Looking into this further, I suspect that the cleanest way to implement this 
would be to add a marshal version 4 that compresses and decompresses using zlib.

--
components: +Interpreter Core
nosy: +brett.cannon, pitrou

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



[issue22789] Compress the marshalled data in PYC files

2014-11-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Looking into this further, I suspect that the cleanest way to implement this 
would be to add a zlib compression and decompression using to the marshal.c 
(bumping the version number to 5).

--

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



[issue22789] Compress the marshalled data in PYC files

2014-11-03 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
Removed message: http://bugs.python.org/msg230580

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

Thank you, Raymond, both for your concern and your discretion.

My interest in changing the can or may to should is that, whatever the 
original intent of the PEP, the way Python works /now/ is that any class that 
doesn't return NotImplemented when it /should/ is not going to interoperate 
well with other compatible classes.

At the heart of the issue is what happens when

  def bin_op(self, other):
 ...

is called, but the left-hand operand doesn't know how to work with the 
right-hand operand?

We have three choices:

  - do nothing, letting any exceptions boil up or errors propagate

  - do a check on 'other' to determine if it's usable, and raise an exception
if it is not

  - do a check on 'other' to determine if it's usable, and return NotImplemented
if it is not

Only the last choice allows 'other' to also try the operation.  Except for the 
special-case of in-place bin-ops, why would we not want choice three?

--

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



[issue21931] Nonsense errors reported by msilib.FCICreate for bad argument

2014-11-03 Thread Martin v . Löwis

Martin v. Löwis added the comment:

I haven't had any time to work on Python in the last year, so it may take some 
more time for me to look into this.

--

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Ethan Furman

Ethan Furman added the comment:

How about:

Special value which should be returned by the binary special methods
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
etc.) to indicate that the operation is not implemented with respect to
the other type; may be returned by the in-place binary special methods
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
Its truth value is true.

Note::
When NotImplemented is returned, the interpreter will then try the
reflected operation on the other type, or some other fallback, depending
on the operator.  If all attempted operations return NotImplemented, the
interpreter will raise an appropriate exception.


I have no idea how to create a link to the 'Implementing the arithmetic 
operations' section.  Any clues?

--

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



[issue22780] NotImplemented doc section needs update

2014-11-03 Thread Georg Brandl

Georg Brandl added the comment:

You add a label before that section and then reference it with :ref:.

--

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



[issue22775] SimpleCookie not unpicklable with protocol 2+

2014-11-03 Thread Georg Brandl

Georg Brandl added the comment:

Thanks!

--

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-11-03 Thread Georg Brandl

Georg Brandl added the comment:

That seems like the best course of action.

--

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



[issue22695] open() declared deprecated in python 3 docs

2014-11-03 Thread Georg Brandl

Georg Brandl added the comment:

LGTM.

--

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