Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Rustom Mody
On Friday, March 25, 2016 at 9:20:23 PM UTC+5:30, Steven D'Aprano wrote:
> 
> Undefined behaviour in C is a minefield waiting to blow your program's legs
> off, because the designers of the language made the explicit choice that
> they wanted the language to be as fast and efficient as possible, even at
> the cost of safe, reproducible behaviour.

Thats a nice polemic Steven
Ive been guilty of similar... which Ive subsequently tried to correct:
http://blog.languager.org/2013/02/c-in-education-and-software-engineering.html

For one thing its good to remember that we wouldn't be here without python
Python wouldn't be what it is without CPython
And the C there is the C you are talking of.

More pertinently this polemic misses the real culprit -- intel hardware.
40 years ago Dijkstra pointed out that software costs are variable;
hardware costs are fixed.
this results in this that programmers will increasingly skip a test that is
very skew.  If that same super-skew test were taken care of by hardware we
(programmers) wouldn't mind. [1]

To see this consider overflow error for integers and for floats.
Intel hardware catches float errors in hardware but not int errors
So language designers have the hobson choice of catching errors at huge cost
Or ignoring and (inviting programmers to ) creating flaky systems.

[1] Economics/financial considerations drive more than we imagine
https://www.facebook.com/EvolvePolitics/videos/1666350230283584/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26624] Windows hangs in call to CRT setlocale()

2016-03-25 Thread Steve Dower

Steve Dower added the comment:

Locking inversion I think, I don't have the bug details handy.

The fix went out over Windows Update recently, but that's only for the release 
version of the runtime. The fixed debug version should have been installed with 
VS 2015 Update 1.

However, since it's still occurring on Jeremy's machine, it may not actually be 
the same bug. Checking the file version of ucrtbased.dll will help, but I can't 
verify the exact certain until Monday.

--

___
Python tracker 

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



[issue23551] IDLE to provide menu link to PIP gui.

2016-03-25 Thread Terry J. Reedy

Terry J. Reedy added the comment:

gohlke/pythonlibs/: Search will have to use a custom function.  If direct 
download from url by pip does not work, then we write a custom function to 
download to a temp file and pip install from local file.  (This is suggestion 
on site.)

runpip: It would be nice if import and main(...) could be made to work by 
reloading the module (to refresh the cache), but if not, subprocess should work 
as a backup.  Having 'run pip command' encapsulated makes it easy to switch 
without affecting the rest of the code.

Additional features: Raymond's list is not a firm cutoff.  I an not sure what a 
'proxy' is in this context and have no sense of what will be useful, especially 
to beginners, rather than clutter.  But I am willing to be educated and 
persuaded.  And there are other people, including a second mentor for this 
project, who can give opinions.

--

___
Python tracker 

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



Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Rustom Mody
On Saturday, March 26, 2016 at 9:55:15 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Mar 26, 2016 at 2:37 PM, Thomas 'PointedEars' Lahn wrote:
> > Chris Angelico wrote:
> >
> >> On Sat, Mar 26, 2016 at 12:36 PM, Thomas 'PointedEars' Lahn wrote:
>  Thomas is not typical of the Python community. We are mostly nice
>  people.
>  :)
> >>>
> >>> You do not even know me.  I *am* a nice person, if only for the fact that
> >>> I do not let people suffer from their own ignorance, and I encourage them
> >>> to educate and enlighten themselves in order not be dependent on people
> >>> like you who tell them what they should think.
> >>>
> >>> So *evidentially*, *you* are not a nice person.  According to your own
> >>> "logic", *you* do not belong in the Python community.  Go away.
> >>
> >> King Gama is a nicer person than you are, and in very similar ways.
> >
> > I do not know a person called "King Gama", I do not think I need to know
> > them, I do not think that he is on-topic here either, and I think that you
> > should keep in mind that this is not a niceness contest, but a technical
> > newsgroup/mailing list.  I for one prefer a direct, if blunt, correct answer
> > over a nice, evading or incorrect one any time.
> >
> > See also: 
> >
> >
> > F'up2 poster
> 
> Fine. You want a blunt answer?
> 
> You, Thomas, are not a nice person. You think you are, but you are
> not. Be nicer or go away. Please.

"You think??"
I think you just failed the Turing test Chris 
Do admit it though...

Thomas 'juvenile' Lahn does a better job than Dihedral
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 2:37 PM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> On Sat, Mar 26, 2016 at 12:36 PM, Thomas 'PointedEars' Lahn
>>  wrote:
 Thomas is not typical of the Python community. We are mostly nice
 people.
 :)
>>>
>>> You do not even know me.  I *am* a nice person, if only for the fact that
>>> I do not let people suffer from their own ignorance, and I encourage them
>>> to educate and enlighten themselves in order not be dependent on people
>>> like you who tell them what they should think.
>>>
>>> So *evidentially*, *you* are not a nice person.  According to your own
>>> "logic", *you* do not belong in the Python community.  Go away.
>>
>> King Gama is a nicer person than you are, and in very similar ways.
>
> I do not know a person called “King Gama”, I do not think I need to know
> them, I do not think that he is on-topic here either, and I think that you
> should keep in mind that this is not a niceness contest, but a technical
> newsgroup/mailing list.  I for one prefer a direct, if blunt, correct answer
> over a nice, evading or incorrect one any time.
>
> See also: 
>
>
> F'up2 poster

Fine. You want a blunt answer?

You, Thomas, are not a nice person. You think you are, but you are
not. Be nicer or go away. Please.

Also, go look up King Gama, as he's from a source that the Pythons follow.

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


Re: WP-A: A New URL Shortener

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 2:30 PM, Thomas 'PointedEars' Lahn
 wrote:
> Since nothing indicates the used module and accessed DBMS (only that, if it
> is Python code, the module cannot be sqlite3 as that does not support “%s”),
> then this code can, if the module uses an escaping mechanism, still be
> vulnerable to SQL injection.  For example, I could input something to the
> effect of
>
> #---
> data = r'\"); DROP TABLE some_table; --'
> #---
>
> if, for example, the string escaping mechanism in the module would simply
> duplicate any double-quote it finds to escape it in the string literal that
> it created (as is possible in MySQL and PostgreSQL), and still inject my
> code because the resulting query would be
>
>   insert into some_table (some_column) values ("\"");
>   DROP TABLE some_table;
>   --")
>
> which is at least syntactically valid MySQL code, but from the perspective
> of the so-attacked it is still not fine as the table would be gone
> afterwards.

In other words, you are assuming that the string escaping *in the
module* is buggy. Well, duh. This is exactly what I said about not
having stupid bugs. The developer of a MySQL binding library should
know the *entire* rules for escaping, and, duh, that's going to
include escaping the backslash. So the escaped query would be
something like:

  insert into some_table (some_column) values ("\\"");
  DROP TABLE some_table;
  --")

which would be interpreted correctly by MySQL.

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> On Sat, Mar 26, 2016 at 12:36 PM, Thomas 'PointedEars' Lahn
>  wrote:
>>> Thomas is not typical of the Python community. We are mostly nice
>>> people.
>>> :)
>>
>> You do not even know me.  I *am* a nice person, if only for the fact that
>> I do not let people suffer from their own ignorance, and I encourage them
>> to educate and enlighten themselves in order not be dependent on people
>> like you who tell them what they should think.
>>
>> So *evidentially*, *you* are not a nice person.  According to your own
>> "logic", *you* do not belong in the Python community.  Go away.
> 
> King Gama is a nicer person than you are, and in very similar ways.

I do not know a person called “King Gama”, I do not think I need to know 
them, I do not think that he is on-topic here either, and I think that you 
should keep in mind that this is not a niceness contest, but a technical 
newsgroup/mailing list.  I for one prefer a direct, if blunt, correct answer 
over a nice, evading or incorrect one any time.

See also: 


F'up2 poster

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: WP-A: A New URL Shortener

2016-03-25 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> On Sat, Mar 26, 2016 at 9:25 AM, Thomas 'PointedEars' Lahn
>  wrote:

Attribution line, not attribution novel.

>> Chris Angelico wrote:
>>> On Sat, Mar 26, 2016 at 8:28 AM, Thomas 'PointedEars' Lahn
>>>  wrote:
 Then enlighten me, please: How is “parameterization” or a
 “parameterized query”, as *you* understand it, different from a
 prepared statement?
>>>
>>> This is a prepared statement:
>>>
>>> http://www.postgresql.org/docs/current/static/sql-prepare.html
>>>
>>> You use a special "PREPARE" query to create *and store* a half-run
>>> query,
>>
>> [Having written a database layer (in PHP) myself, I know what a prepared
>> statement is, thank you very much.]
>>
>> Your statement is incorrect both for MySQL (which I know) and PostgreSQL
>> (AIUI your reference): The query is processed and stored of course, but
>> it is definitely _not_ *run* before the EXECUTE command is issued for it.
> 
> It legal to partly perform the query.

What are you getting at?  A query cannot be performed if the values of its 
parameters have no defined value yet.

> DB2 can retain a "query plan" which consists of the exact paths it will
> follow. So I stand by my statement.

A query plan is _not_ the *execution* (“run”) of a query, but the result of 
*processing* a query (AISB).  So you are still wrong.
 
>>> Back in the 1990s, I had the option of actually *compiling* my SQL
>>> queries as part of my C code, which would prepare all the queries for
>>> future execution. It is completely different from the dynamic
>>> parameterized queries that most people use.
>> Interesting, but irrelevant.
> 
> Not really, no. It was a form of PREPARE/EXECUTE that hid the PREPARE
> behind a convenient syntax, and then replaced it with EXECUTE for the
> run-time.

IOW, a prepared statement.  Thanks for the confirmation.
 
>>> Parameterization is a more general concept which prepared statements
>>> invariably use, but which general code need not use.
>>
>> If it is to be safe from SQL injection, it better uses a parameterized
>> query as it is *commonly* understood.
> 
> Why? […]

Far beyond the scope of this newsgroup/mailing list.  RTFM I referred to.

>>> A Python database connector could choose to PREPARE/EXECUTE for every
>>> query it's given,
>> That would not be wise, given that not every query contains variable
>> parameters.
> 
> Irrelevant. It would still be legal. Do you understand the difference
> between what is legal according to a specification and what is
> actually worth doing?

Red herring.  Legality (better: validity) was not the issue.  Whether 
legal/valid code or or not, it would still not be wise because application 
performance would be reduced at little advantage, if any.

>>> or it could choose to escape all the parameters and embed them,
>> Recommended against, and not a parameterized query at all.
> 
> Not once it reaches the underlying database,

And that is not how “parameterized query” is commonly defined.

>>> All three are "parameterized queries", at least from the POV of Python
>>> code.
>> You are mistaken, then: Of the three kinds of “parameterized queries” as
>> *you* understand them (OWASP and I beg to differ), at least one of them
>> that is not used in a prepared statement is *insufficient to prevent SQL
>> injection*.
> 
> Okay, then. Please explain how this code is vulnerable to SQL injection:
> 
> conn = some_db_module.connect("")
> cur = conn.cursor()
> data = input("Enter a value: ")
 ^
> cur.execute("insert into some_table (some_column) values (%s)", (input,))
   ^
> conn.commit()

This code is not vulnerable to SQL injection, unless “input” referred to an 
object that had both a suitable __call__() or __init__(), and __str__() 
method ;->

Probably you meant

#---
conn = some_db_module.connect("")
cur = conn.cursor()
data = input("Enter a value: ")
cur.execute("insert into some_table (some_column) values (%s)", (data,))
conn.commit()
#---

Since nothing indicates the used module and accessed DBMS (only that, if it 
is Python code, the module cannot be sqlite3 as that does not support “%s”), 
then this code can, if the module uses an escaping mechanism, still be 
vulnerable to SQL injection.  For example, I could input something to the 
effect of

#---
data = r'\"); DROP TABLE some_table; --'
#---

if, for example, the string escaping mechanism in the module would simply 
duplicate any double-quote it finds to escape it in the string literal that 
it created (as is possible in MySQL and PostgreSQL), and still inject my 
code because the resulting query would be


[issue23735] Readline not adjusting width after resize with 6.3

2016-03-25 Thread Martin Panter

Martin Panter added the comment:

Unfortunately, yes I think another test might be needed in configure.ac, unless 
you can piggy-back on one of the existing flags.

One more thing that I thought of: Looking at the main Python signal handler, it 
reinstalls itself, see 
. This 
is apparently because handlers installed by Posix signal() might be only called 
once. But if the handler was installed by sigaction(), it should not be 
reinstalled. Should our SIGWINCH handler do something similar?

--
versions: +Python 3.6 -Python 3.4

___
Python tracker 

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



Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 12:36 PM, Thomas 'PointedEars' Lahn
 wrote:
>> Thomas is not typical of the Python community. We are mostly nice people.
>> :)
>
> You do not even know me.  I *am* a nice person, if only for the fact that I
> do not let people suffer from their own ignorance, and I encourage them to
> educate and enlighten themselves in order not be dependent on people like
> you who tell them what they should think.
>
> So *evidentially*, *you* are not a nice person.  According to your own
> "logic", *you* do not belong in the Python community.  Go away.

King Gama is a nicer person than you are, and in very similar ways.

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Paul Rubin
Steven D'Aprano  writes:
> Culturally, C compiler writers have a preference for using undefined
> behaviour to allow optimizations, even if it means changing the semantics
> of your code. 

If your code has UB then by definition it has no semantics to change.
Code with UB has no meaning.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Random832
On Fri, Mar 25, 2016, at 22:46, Steven D'Aprano wrote:
> Culturally, C compiler writers have a preference for using undefined
> behaviour to allow optimizations, even if it means changing the semantics
> of your code. The C compiler is allowed to ignore your code, move it
> around
> so that things happen in a different order, or add its own code, even if
> that changes the semantics of the code.

Er, the point of undefined behavior is that your code doesn't *have*
semantics.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Steven D'Aprano
On Sat, 26 Mar 2016 03:57 am, Marko Rauhamaa wrote:

> Steven D'Aprano :
> 
>> Undefined behaviour in C is a minefield waiting to blow your program's
>> legs off, because the designers of the language made the explicit
>> choice that they wanted the language to be as fast and efficient as
>> possible, even at the cost of safe, reproducible behaviour.
> 
> Yes, although the same could be true for Python as well.

Is this a philosophical question? Yes, it *could* be true, in some alternate
universe, but it isn't actually true.

Python does not have undefined behaviour in the C sense. Like any language
which doesn't have a formal IEEE standard behind it (and even some that
do), it has implementation-specific behaviour, or under- or unspecified
behaviour. But that is not the same as C Undefined Behaviour. Please read
the links I gave.

Culturally, C compiler writers have a preference for using undefined
behaviour to allow optimizations, even if it means changing the semantics
of your code. The C compiler is allowed to ignore your code, move it around
so that things happen in a different order, or add its own code, even if
that changes the semantics of the code.

Python has nothing even remotely like that. If you shoot yourself in the
foot with Python, you can say it is because you didn't understand what your
code would do, but you can't say it is because Python moved code around to
execute it in an unexpected order, or ignored it.



> For example, you could have this program:
> 
> ===begin poof.py
> assert 1 < 0
> ===end poof.py==

The semantics of "assert condition" are equivalent to:


if __debug__:
if not condition:
raise AssertionError


so assert is intentionally a no-op when Python runs with debug mode disabled
(the -O command-line switch).


 
> When it is run, you might see this:
> 
> 
> $ python3 poof.py
> python3: the VM vanished in a puff of logic while executing 'poof.py'
> 

I assume that the "vanished" quip is your editorial. Otherwise, the only way
to get that result would be if you linked the python3 executable to
something other than Python 3.

There are only two behaviours a conforming Python interpreter can do
with "poof.py":

- by default, it must raise AssertionError;

- if run with optimizations switched on (debugging mode turned off), 
  it must do nothing.


Anything else would be a bug in the interpreter or compiler.




-- 
Steven

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


Re: Problem With Embedded Icon and Python 3.4

2016-03-25 Thread Wildman via Python-list
On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote:

> On 25/03/2016 05:10, Wildman via Python-list wrote:
>> I have a program that I have been trying to rewrite so it will
>> run on Python 2.7 and 3.4.
> 
> This http://pythonhosted.org/six/ might come in handy in future.
> 
> As I'm also climbing the tkinter cliff at the moment I've found anything 
> on stackoverflow from Bryan Oakley to be very helpful. In particular, 
> his answer here 
> http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application
>  
> really helped me get a grip on things.
> 
> A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also 
> useful.
> 
> HTH.

Thanks for the links.  Good stuff.  Bookmarked.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-25 Thread Steven D'Aprano
On Sat, 26 Mar 2016 09:08 am, BartC wrote:

> On 25/03/2016 16:22, Steven D'Aprano wrote:
>> On Fri, 25 Mar 2016 10:06 pm, BartC wrote:
> 
> (OK, I'll risk the wrath of Mark Lawrence et al by daring to post my
> opinions.)

Please ignore Mark Lawrence when he is acting as an obnoxious troll, as he
is now. He occasionally has something useful or helpful to say, but most of
the time he thinks he is the self-appointed Guardian of Python's Honour, a
job he is singularly ill-equipped for even if Python's honour needed
defending, which it doesn't.


>>> But it is an optimisation that /could/ be done by the byte-code compiler
> 
>> I would also expect that Victor Stinner's FAT Python project will
>> (eventually) look at optimizing such for-loops too. If you see something
>> like:
>>
>> for i in range(N):
>>  do_stuff()
>>
>>
>> and three conditions hold:
>>
>> (1) i is unused in the loop body;
>>
>> (2) range is still bound to the expected built-in function, and no
>> other "range" in a nearer scope (say, a local variable called "range", or
>> a global) exists to shadow it; and
> 
> The volatility of 'range' I'd completely forgotten about. Python really
> doesn't make this stuff easy, does it?

True. But it makes *other things* much more easy. Things which are
impossible or very difficult in other, stricter languages are trivially
easy in Python.



> Checking this at runtime, per loop (I don't think it's necessary per
> iteration) is a possibility, but now an extra overhead is introduced. It
> might worth it if the body of the loop is also optimised, but this is
> getting into the territory covered by tracing JITs.

Detecting whether or not range has been shadowed or replaced doesn't need a
full tracing JIT. Victor's work isn't complete, but preliminary results
suggest strongly that the overhead of checking guards will be
insignificant.


> My kind of approach would try to keep it simple, and that would be
> helped tremendously by special language constructs (something like
> Ruby's 100.times) where you can use a streamlined loop, and possible
> unrolling, straight off.

Ruby is an interesting case, because Ruby is even more dynamic than Python.
Python doesn't allow you to replace or add methods to built-ins, but Ruby
does, so in principle, you have no idea what 100.times is going to do until
runtime. That's no different from Python and range.

Up until a few years ago, Ruby was considered even slower than Python, by a
factor of two or five or so. I'm lead to believe that the latest version of
Ruby reverses that, and I've seen claims that it is now faster than Python,
but I haven't seen it for myself so I'm not sure if I believe it entirely.


> (Personally, if I was creating a byte-code intepreter for Python as-is,
> I would have a -dynamic:on or -dynamic:off switch.)
> 
>> Here is one of the oldest:
>>
>> http://www.ibm.com/developerworks/library/l-psyco/index.html
> 
> Yes, I tried that long ago. It's very fast on certain benchmarks. (Both
> psyco and pypy can run my lexer at around 170Klps. And this is code
> using string compares and long if-elif chains, that would be crazy in
> any other language. From that point of view, it's very impressive (I can
> only get half that speed using the same methods).

The Python philosophy seems to prefer the use of specialist JIT compilers to
speed up bottlenecks rather than language features. I've seen Guido comment
that he doesn't believe static AOT optimization is worthwhile in Python and
that people should concentrate on JIT optimizations. I suspect he's right.



-- 
Steven

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Steven D'Aprano
On Sat, 26 Mar 2016 08:17 am, PointedEars wrote:
..^^^

> get a real name.

You sign your posts "PointedEars". Do you not realise how hypocritical these
repeated carping complaints about "real names" are? 

Not to mention pointless. Aside from the fact that "real name" is
subjective, you have no idea what is someone's real name and what isn't.


Nobody appointed you as Real Name Sheriff. Just give it up.



-- 
Steven

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


Re: Problem With Embedded Icon and Python 3.4

2016-03-25 Thread Mark Lawrence

On 25/03/2016 05:10, Wildman via Python-list wrote:

I have a program that I have been trying to rewrite so it will
run on Python 2.7 and 3.4.


This http://pythonhosted.org/six/ might come in handy in future.

As I'm also climbing the tkinter cliff at the moment I've found anything 
on stackoverflow from Bryan Oakley to be very helpful. In particular, 
his answer here 
http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application 
really helped me get a grip on things.


A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also 
useful.


HTH.

--
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: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Thomas 'PointedEars' Lahn
Ned Batchelder wrote:

> Chris, I apologize for Thomas.

How dare you to speak for me, and *again* the rest of the subscribers?  
There is nothing to apologize for when I am *helping* someone by giving them 
useful information.  You can apologize for your own presumptous behavior 
instead.

> is main goal on this list seems to be pointing out when people are wrong, 
> over the smallest details.

Certainly I point out when people are wrong.   That is how we develop 
*knowledge*.  For that it does not matter of you in your blissful ignorance 
think that those are “smallest details”, which they are not.  The underlying 
process is called *learning*.  You should try it sometime.

> His secondary goal is enforcing some imaginary rule about real names,

It is not an imaginary rule, it is a social convention that follows from 
another social convention, simple politeness.  When you are seeking the help 
of people that you do not know, there is a principle of basic politeness 
saying that you should tell them who you are.  Especially if those people 
have already extended you the politeness to tell them who *they* are; like 
here, when you have read their names already.

Politeness is another thing you should try sometime, as I see that, your 
having no valid argument at all, you like to throw dirt instead.

> Thomas is not typical of the Python community. We are mostly nice people.
> :)

You do not even know me.  I *am* a nice person, if only for the fact that I 
do not let people suffer from their own ignorance, and I encourage them to 
educate and enlighten themselves in order not be dependent on people like 
you who tell them what they should think.

So *evidentially*, *you* are not a nice person.  According to your own 
"logic", *you* do not belong in the Python community.  Go away.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25987] collections.abc.Reversible

2016-03-25 Thread Guido van Rossum

Guido van Rossum added the comment:

Andrew, did you lose interest in this? We now have a PR for typing.py that 
expects this to be resolved: https://github.com/python/typing/pull/194

--

___
Python tracker 

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



[issue25654] test_multiprocessing_spawn ResourceWarning with -Werror

2016-03-25 Thread Martin Panter

Martin Panter added the comment:

Sorry, but I don’t think I have the time/motivation/expertise to look into the 
fix in detail. But there are no warnings or failures anymore when I use 
-Werror, so I am happy!

BTW the spurious background processes are still there (visible if you run “ps” 
or “pstree” immediately after the test finishes), but they no longer print 
errors.

--

___
Python tracker 

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



[issue25951] SSLSocket.sendall() does not return None on success like socket.sendall()

2016-03-25 Thread Martin Panter

Martin Panter added the comment:

Thanks for your work Aviv. This version looks good to me.

--
versions:  -Python 3.5

___
Python tracker 

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



[issue26612] test_ssl: use context manager (with) to fix ResourceWarning

2016-03-25 Thread Martin Panter

Martin Panter added the comment:

In many cases I prefer “with” over “try / finally”. But Python 2’s sockets do 
not support “with” statements, so choice (2) is not possible for 2.7.

I found one potential technical problem, and maybe some redundant close() calls 
in the review.

--

___
Python tracker 

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



[issue26391] typing: Specialized sub-classes of Generic never call __init__

2016-03-25 Thread Guido van Rossum

Guido van Rossum added the comment:

Actually, I just realized why this is. Generic.__new__() calls 
next_in_mro.__new__(_gorg(cls)). Here next_in_mro is just object, but 
_gorg(cls) is Foo, in the case where cls is Bar (i.e. Foo[str]). The _gorg() 
call strips the [str] part of the type.

So far so good. Where it gets interesting is that, in general in Python, 
whenever __new__(cls, ...) returns an object whose class is not cls, it is 
presumed to be an already properly initialized object!

I think I can fix this by calling __init__() explicitly in the case where 
_gorg(cls) is not cls.

The reason, BTW, why it strips the [str] part of the class is because that's 
what PEP 484 says, in the same section where it says that Node[T]() and 
Node[int]() are allowed:

> At runtime the type is not preserved, and the class of ``x`` is just
> ``Node`` in all cases.

So this bit of code is trying to do the right thing but obviously hasn't been 
tested much, because mypy disallows that syntax.

--

___
Python tracker 

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



[issue23886] faulthandler_user should use _PyThreadState_Current

2016-03-25 Thread Albert Zeyer

Albert Zeyer added the comment:

Yes exactly. Sorry if I was unclear before. :)

I mentioned SIGUSR1/2 because for a segfault, the signal handler will usually 
be executed in the same thread (although I'm not sure if that is guaranteed), 
so that was usually not a problem. But I used SIGUSR1 when my Python 
application is hanging and esp in that case I would like to know the current 
Python active thread.

--

___
Python tracker 

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



[issue25911] Regression: os.walk now using os.scandir() breaks bytes filenames on windows

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

Update: test_os pass on all Windows buildbots except one!

I don't understand why the test fails on this buildbot.

http://buildbot.python.org/all/builders/AMD64%20Windows8%203.x/builds/1906/steps/test/logs/stdio

==
FAIL: test_walk_bottom_up (test.test_os.BytesWalkTests)
--
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows8\build\lib\test\test_os.py", line 895, 
in test_walk_bottom_up
self.assertEqual(len(all), 4)
AssertionError: 5 != 4

--

___
Python tracker 

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



[issue25911] Regression: os.walk now using os.scandir() breaks bytes filenames on windows

2016-03-25 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 82da02b5bf22 by Victor Stinner in branch 'default':
Issue #25911: more info on test_os failure
https://hg.python.org/cpython/rev/82da02b5bf22

--

___
Python tracker 

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



[issue22898] segfault during shutdown attempting to log ResourceWarning

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

warn_5.patch: The patch cannot be reviewed on Rietveld :-( You must not use the 
git format for diff.

warn_5.patch: "if (globals == NULL) { (...) return 0; }"

It looks like filename is not initialized. I suggest to use:

   *filename = f->f_code->co_filename;

It looks like you have to add:

   if (PyUnicode_Check(*filename)) *filename = NULL;

To mimick the code below.

--

___
Python tracker 

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



[issue20021] "modernize" makeopcodetargets.py

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> Or does it matter to be able to use an external python program?

Oh wait, I misunderstood how the script is used. I understood that the script 
must be run manually only when a new opcode is added and so is rarely used and 
only used with the built Python program.

In fact, the script is part of the build process! I completely missed that, 
sorry. I searched how it was used but I missed the build process.

So yes, it matters to support Python 2 and Python 3 in 
Python/makeopcodetargets.py.

I pushed Serhiy's patch issue20021_2.diff.

--

___
Python tracker 

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



[issue20021] "modernize" makeopcodetargets.py

2016-03-25 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 6ceceb052394 by Victor Stinner in branch 'default':
makeopcodetargets.py: we need to import Lib/opcode.py
https://hg.python.org/cpython/rev/6ceceb052394

--
nosy: +python-dev

___
Python tracker 

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



[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread Martin Panter

Martin Panter added the comment:

In the long term, I prefer not calling close() in __del__(), like 
del-flush.patch, although I admit it is an API change and should probably be 
limited to 3.6+. If people want to improve things in 3.5, privately 
implementing _dealloc_warn() like Victor’s pyio_res_warn-3.patch seems the best 
option.

Serhiy: why did you add 2.7 to this bug? For 2.7, I don’t think anything should 
be done. There is no ResourceWarning in 2.7.

In 3.5, _dealloc_warn() could also be implemented in SocketIO (possibly also 
HTTPResponse, GzipFile, etc). But it should not become a public API, and I 
don’t think it is important to make this sort of change to 3.5 anyway.

In 3.6, if we stopped __del__() from calling close() like del-flush.patch, we 
would be changing the documented behaviour: 
 says “IOBase . 
. . calls the instance’s close() method.” But the end result seems cleaner to 
me. I think changing or adding an API (__del__, _dealloc_warn, etc) is 
necessary for a general solution to the problem.

The effect of del-flush.patch will be that a wrapped FileIO or similar object 
will not be closed until all references are deleted.

>>> file = open(os.devnull, "wb", 0)
>>> print(file)
<_io.FileIO name='/dev/null' mode='wb' closefd=True>
>>> wrapper = BufferedWriter(file)

In 3.5, deleting the wrapper produces a warning and closes the underlying file:

>>> del wrapper
__main__:1: ResourceWarning: unclosed file <_io.BufferedWriter name='/dev/null'>
>>> print(file)
<_io.FileIO [closed]>
>>> file.write(b"more data")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: I/O operation on closed file

I propose that in 3.6, deleting a wrapper should not automatically close or 
warn about the wrapped object until all references are deleted:

>>> del wrapper  # No problem; we still have a reference to "file"
>>> file.write(b"more data")  # File is still open
9
>>> del file  # Finally closes the file and triggers the warning
ResourceWarning: unclosed file 

--

___
Python tracker 

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



[issue23886] faulthandler_user should use _PyThreadState_Current

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> I want that it marks the current Python thread correctly, and not the current 
> sighandler thread.

Oook, I finally understood your use case. You want to know which threads 
hold the GIL. You don't care which thread got the signal.

--

___
Python tracker 

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



[issue26391] typing: Specialized sub-classes of Generic never call __init__

2016-03-25 Thread STINNER Victor

Changes by STINNER Victor :


--
title: Specialized sub-classes of Generic never call __init__ -> typing: 
Specialized sub-classes of Generic never call __init__

___
Python tracker 

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



[issue22218] Fix more compiler warnings "comparison between signed and unsigned integers"

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

fix_warning_unicodeobject.diff and issue22218-2.patch don't seem to be needed 
anymore. The code is now:

if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) < (size + 1))
return NULL;

I close the issue. More specific issues must be opened if you still want to fix 
similar issues.

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

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



Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Ned Batchelder
On Friday, March 25, 2016 at 5:17:21 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> c...@isbd.net wrote:
> 
> > Occasionally I have to make forays into Javascript, can anyone
> > recommend a place similar to this list where Javascript questions can
> > be asked?  The trouble is that there are very many usenet Javascript
> > lists and it's difficult to guess which one[es] might be good.
> 
> There is no Javascript. 
> 
> There are no Usenet lists.
> 
> This is not only a Python *mailing* list, it is also mirrored as an 
> international Usenet _newsgroup_,  (which I am 
> reading).
> 
> If you can accept all of that, then the international Usenet _newsgroup_ 
>  (where I am posting primarily) is for you.
> So are other national/language-specific newsgroups on the JavaScripts and 
> other ECMAScript implementations.  In your newsreader, search for newsgroups 
> whose name contains "javascript".
> 
> Next time, read  and STFW first, and get a real name.

Chris, I apologize for Thomas.  His main goal on this list seems to be
pointing out when people are wrong, over the smallest details.  His
secondary goal is enforcing some imaginary rule about real names, though
he couldn't be bothered to read your post thoroughly enough to discover yours.

Thomas is not typical of the Python community. We are mostly nice people. :)

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


[issue25160] Stop using deprecated imp module; imp should now emit a real DeprecationWarning

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> Tools/i18n/pygettext.py:159:import imp

I opened the issue #26639 for it.


>> Python/makeopcodetargets.py:9:import imp
> See issue 20021.

I pushed the change f682b620c64d but I forgot about the issue #20021. Let's 
discuss there about this script.


> Tools/importbench/importbench.py:10:import imp

I think that it's fine to keep imp there.


> Lib/modulefinder.py:14:import imp

This one requires more work than the other.

--

___
Python tracker 

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



[issue25160] Stop using deprecated imp module; imp should now emit a real DeprecationWarning

2016-03-25 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +eric.snow

___
Python tracker 

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



[issue26631] Unable to install Python 3.5.1 on Windows 10 - Error 0x80070643: Failed to install MSI package.

2016-03-25 Thread J Osell

J Osell added the comment:

Done

--

___
Python tracker 

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



[issue26631] Unable to install Python 3.5.1 on Windows 10 - Error 0x80070643: Failed to install MSI package.

2016-03-25 Thread J Osell

Changes by J Osell :


Added file: http://bugs.python.org/file42294/Python 3.5.1 
(64-bit)_20160323181333_000_core_JustForMe.log

___
Python tracker 

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



[issue25256] Add sys.debug_build public variable to check if Python was compiled in debug mode

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

I lost interest in this issue. It really looks like a corner case, so I prefer 
to keep the current code. I'm not interested to work on the abiflags on Windows.

--
resolution:  -> out of date
status: open -> closed

___
Python tracker 

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



[issue25276] Intermittent segfaults on PPC64 AIX 3.x

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

The origin of the crash is unknown. Since I didn't see the crash recently, I 
close the issue.

--
resolution:  -> out of date
status: open -> closed

___
Python tracker 

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



[issue26624] Windows hangs in call to CRT setlocale()

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> It's been fixed, just figuring out when the update will be available, or how 
> to get it if it already is.

Can you elaborate? What was the bug? How was it fixed? Is it a bug in Windows, 
in Visual Studio or in the C library?

--

___
Python tracker 

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



[issue26624] Windows hangs in call to CRT setlocale()

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

The issue #25289 has marked as a duplicate of this issue.

--

___
Python tracker 

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



[issue25289] test_strptime hangs sometimes on AMD64 Windows7 SP1 3.x buildbot

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

It looks like the issue was a bug in setlocale() and that it was fixed in 
Windows! See the issue #26624.

--
resolution:  -> duplicate
status: open -> closed
superseder:  -> Windows hangs in call to CRT setlocale()

___
Python tracker 

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



[issue26643] regrtest: rework libregrtest.save_env submodule

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> Consider your example with the 'sys.path' resource. With current code I need 
> to understand only 3 simple lines of the code in two close methods. With the 
> patch I need to research 4 classes with 16 complicated methods! This is awful!

I replaced get_sys_path()/restore_sys_path() (2 methods) with 
ModuleAttr.get()+ModuleAttrList.encode_value() / 
ModuleAttr.restore()+ModuleAttrList.restore_attr() (4 methods).

I want to factorize the code to limit duplicated code.

My use case is that I want to see what changed when I get the "test xxx changed 
yyy" error. For sys.path, ModuleAttrList.decode_value() helps to get a nicer 
output since you only display 1 list instead of the (id, list, list_copy) tuple.

How do you suggest to enhance the existing code to get such nicer output?


> Now about using __subclasses__(). Is it guarantied that the order of classes 
> in __subclasses__() is the same as the order of declaration and always will 
> be?

No, it looks random.


> The order of restoring resources matters.

I'm not sure that it's a good thing to have dependencies between "resources". I 
see that Files depends on Cwd, but maybe the Files check can be integrated into 
Cwd?

Ok so the order matters, in this case, I can use a metaclass to use the order 
of class definition. It will make get_resources() simpler, it will be build 
directly in the metaclass.

> For now if there is needed to change the order of restoring resources (I'm 
> sure there will be need to do this in future) you need to change only one or 
> two lines. With your patch you need to reorder classes declarations.

Yes. Is it really an issue? I only see two resources that have a dependency 
(Files and Cwd). It's not like this file is modified regulary.


> Nicer diff for dictionaries can be an enhancement, but it can be implemented 
> without such large rewriting.

How do you want to implement that? Currently, a resource has a "get" method 
which returns a blackbox. It's not easy to display it. There is not standard 
format.

--

___
Python tracker 

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



[issue26612] test_ssl: use context manager (with) to fix ResourceWarning

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

"try: ... finally: s.close()" are "with s: ..." do the same thing, but I prefer 
"with" (context-manager). IMO it's more "pythonic". I prefer to see the 
"cleanup block" at the beginning, rather than at the end.

> My point about Python 2 was that this might add an annoying difference 
> between the two branches. Even if you don’t apply this to Py 2, the next 
> person adding or updating a test might be inclined to do it.

Well, there are 3 choices:

(1) Do nothing. The code rotten slowly (technical debt)
(2) Modify all actively development branches (2.7, 3.5, default)
(3) Only modify Python 3.6

Mofiying all branches means taking the (low) risk of introducing regressions. 
IMHO regressions occur, all the time.

I prefer the option (3) because it allows to enhance the code without taking 
any risk on regression.

Yeah, the code diverge, it's a natural fact.

Then you write that my changes replacing try/finally with "with" are not worth. 
Well, maybe you are true. Since 5 years, I convert all the code to "with" 
because I really like context managers. IMHO they make the code stronger and 
easier to read.

--

___
Python tracker 

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



Re: WP-A: A New URL Shortener

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 9:25 AM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> On Sat, Mar 26, 2016 at 8:28 AM, Thomas 'PointedEars' Lahn
>>  wrote:
>>> Chris Angelico wrote:
 […] Thomas 'PointedEars' Lahn […] wrote:
> Chris Angelico wrote:
>> […] Thomas 'PointedEars' Lahn […] wrote:
>>> Daniel Wilcox wrote:
 Cool thanks, highly recommended to use an ORM to deter easy SQL
 injections.
>>> That is to crack a nut with a sledgehammer.  SQL injection can be
>>> easily and more efficiently prevented with prepared statements.  […]
>> You don't even need prepared statements. All you need is parameterized
>> queries.
> A prepared statement in this context uses a parameterized query.
>
>
>>>
> 

 I know what a prepared statement is. And I know that they are
 effective. However they are overkill - as I said, you merely need
 parameterization.
>>>
>>> Then enlighten me, please: How is “parameterization” or a “parameterized
>>> query”, as *you* understand it, different from a prepared statement?
>>
>> This is a prepared statement:
>>
>> http://www.postgresql.org/docs/current/static/sql-prepare.html
>>
>> You use a special "PREPARE" query to create *and store* a half-run
>> query,
>
> [Having written a database layer (in PHP) myself, I know what a prepared
> statement is, thank you very much.]
>
> Your statement is incorrect both for MySQL (which I know) and PostgreSQL
> (AIUI your reference): The query is processed and stored of course, but it
> is definitely _not_ *run* before the EXECUTE command is issued for it.

It legal to partly perform the query. DB2 can retain a "query plan"
which consists of the exact paths it will follow. So I stand by my
statement.

>> Back in the 1990s, I had the option of actually *compiling* my SQL queries
>> as part of my C code, which would prepare all the queries for future
>> execution. It is completely different from the dynamic parameterized
>> queries that most people use.
>
> Interesting, but irrelevant.

Not really, no. It was a form of PREPARE/EXECUTE that hid the PREPARE
behind a convenient syntax, and then replaced it with EXECUTE for the
run-time.

>> Parameterization is a more general concept which prepared statements
>> invariably use, but which general code need not use.
>
> If it is to be safe from SQL injection, it better uses a parameterized query
> as it is *commonly* understood.

Why? All it needs to do is guarantee that no user data can affect the
query. There are myriad ways to do that, and prepared statements are
only one of them. Even parameterization is not strictly necessary, as
long as the escaping is perfect. (Though that does have its own
consequences, and is not recommended.)

>> A Python database connector could choose to PREPARE/EXECUTE for every
>> query it's given,
>
> That would not be wise, given that not every query contains variable
> parameters.

Irrelevant. It would still be legal. Do you understand the difference
between what is legal according to a specification and what is
actually worth doing? In an explanation of what a parameterized query
is, I would expect to be discussing what is semantically and
functionally valid, not which optimizations are worth doing.

>> or it could choose to escape all the parameters and embed them,
>
> Recommended against, and not a parameterized query at all.

Not once it reaches the underlying database, but it is parameterized
in the source code. It's not possible for an external attacker to get
past the escaping, if it is done correctly. It is still legal,
however, it is indeed not recommended.

>> or it could (if it's using a decent database back-end like PostgreSQL)
>> simply send the query and its associated parameters as-is. Only one of
>> these options is a "prepared statement".
>
> Maybe.  I do not know enough about PostgreSQL and its “[sending] the query
> and its associated parameters as-is” yet to confirm or deny this.

The wire protocol supports this.

>> All three are "parameterized queries", at least from the POV of Python
>> code.
>
> You are mistaken, then: Of the three kinds of “parameterized queries” as
> *you* understand them (OWASP and I beg to differ), at least one of them
> that is not used in a prepared statement is *insufficient to prevent SQL
> injection*.

Okay, then. Please explain how this code is vulnerable to SQL injection:

conn = some_db_module.connect("")
cur = conn.cursor()
data = input("Enter a value: ")
cur.execute("insert into some_table (some_column) values (%s)", (input,))
conn.commit()

Do you need to know the implementation of cur.execute to be able to
say whether this is safe, or can you be confident that, short of
really blatantly obvious bugs in the database connector, this is
genuinely a parameterized 

[issue25654] test_multiprocessing_spawn ResourceWarning with -Werror

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

I'm not sure why Python 2.7 was in the Versions. I just ran "python2.7 -Werror 
-m test.regrtest -v test_multiprocessing" => no error. ResourceWarning doesn't 
exist in Python 2.

Is it still something to do on multiprocessing about ResourceWarning?

I didn't understand if you (Martin and Serhiy) are ok with my change (based on 
Serhiy's change).

--
versions:  -Python 2.7, Python 3.4

___
Python tracker 

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



Re: WP-A: A New URL Shortener

2016-03-25 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> On Sat, Mar 26, 2016 at 8:28 AM, Thomas 'PointedEars' Lahn
>  wrote:
>> Chris Angelico wrote:
>>> […] Thomas 'PointedEars' Lahn […] wrote:
 Chris Angelico wrote:
> […] Thomas 'PointedEars' Lahn […] wrote:
>> Daniel Wilcox wrote:
>>> Cool thanks, highly recommended to use an ORM to deter easy SQL
>>> injections.
>> That is to crack a nut with a sledgehammer.  SQL injection can be
>> easily and more efficiently prevented with prepared statements.  […]
> You don't even need prepared statements. All you need is parameterized
> queries.
 A prepared statement in this context uses a parameterized query.


>> 

>>>
>>> I know what a prepared statement is. And I know that they are
>>> effective. However they are overkill - as I said, you merely need
>>> parameterization.
>>
>> Then enlighten me, please: How is “parameterization” or a “parameterized
>> query”, as *you* understand it, different from a prepared statement?
> 
> This is a prepared statement:
> 
> http://www.postgresql.org/docs/current/static/sql-prepare.html
> 
> You use a special "PREPARE" query to create *and store* a half-run
> query,

[Having written a database layer (in PHP) myself, I know what a prepared 
statement is, thank you very much.]

Your statement is incorrect both for MySQL (which I know) and PostgreSQL 
(AIUI your reference): The query is processed and stored of course, but it 
is definitely _not_ *run* before the EXECUTE command is issued for it.

> and then you execute it afterwards.

In both DMBSs, the query/statement is filled with parameter values and then 
executed not before, and then only if and when, one issues the EXECUTE 
statement for it.

> Back in the 1990s, I had the option of actually *compiling* my SQL queries
> as part of my C code, which would prepare all the queries for future
> execution. It is completely different from the dynamic parameterized
> queries that most people use.

Interesting, but irrelevant.
 
> Parameterization is a more general concept which prepared statements
> invariably use, but which general code need not use.

If it is to be safe from SQL injection, it better uses a parameterized query 
as it is *commonly* understood.

> A Python database connector could choose to PREPARE/EXECUTE for every
> query it's given,

That would not be wise, given that not every query contains variable 
parameters.

> or it could choose to escape all the parameters and embed them,

Recommended against, and not a parameterized query at all.

> or it could (if it's using a decent database back-end like PostgreSQL)
> simply send the query and its associated parameters as-is. Only one of
> these options is a "prepared statement".

Maybe.  I do not know enough about PostgreSQL and its “[sending] the query 
and its associated parameters as-is” yet to confirm or deny this.

> All three are "parameterized queries", at least from the POV of Python
> code.

You are mistaken, then: Of the three kinds of “parameterized queries” as 
*you* understand them (OWASP and I beg to differ), at least one of them
that is not used in a prepared statement is *insufficient to prevent SQL 
injection*.

The second kind also moves tasks to the programming language that are better 
done by the DBMS; the program code should database-agnostic (in the best 
case, for mockup testing, even oblivious of the database).

Which is why programming languages have come to support prepared statements, 
and why OWASP recommends to use either them or stored procedures.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.y
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26627] IDLE incorrectly labeling error as internal

2016-03-25 Thread Terry J. Reedy

Terry J. Reedy added the comment:

The goal is to match the traceback that Python itself produces with the same 
code, but it is perhaps an impossible process. The current list goes back to 
2003 without tracker issue numbers, so I don't know the reason for each.  I 
worry a bit about the suppression of lines from threading and queue.

I wondered why the idlelib.run lines were here until I read this (3.5.2, 
run.py, line 233-236.

if len(tb) == 0:
# exception was in IDLE internals, don't prune!
tb[:] = orig_tb[:]
print("** IDLE Internal Exception: ", file=sys.stderr)

So both lines were deleted and then restored.

Prepending idlelib as appropriate, seems like a good idea.

exclude = ['bdb.py', 'queue.py', 'threading.py']
for name in ('RemoteDebugger.py', 'rpc.py', 'run.py'):
exclude.append(os.path.join('idlelib', name))

--
stage:  -> test needed

___
Python tracker 

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



Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-25 Thread BartC

On 25/03/2016 16:22, Steven D'Aprano wrote:

On Fri, 25 Mar 2016 10:06 pm, BartC wrote:


(OK, I'll risk the wrath of Mark Lawrence et al by daring to post my 
opinions.)



But it is an optimisation that /could/ be done by the byte-code compiler



I would also expect that Victor Stinner's FAT Python project will
(eventually) look at optimizing such for-loops too. If you see something
like:

for i in range(N):
 do_stuff()


and three conditions hold:

(1) i is unused in the loop body;

(2) range is still bound to the expected built-in function, and no
other "range" in a nearer scope (say, a local variable called "range", or a
global) exists to shadow it; and


The volatility of 'range' I'd completely forgotten about. Python really 
doesn't make this stuff easy, does it?


Checking this at runtime, per loop (I don't think it's necessary per 
iteration) is a possibility, but now an extra overhead is introduced. It 
might worth it if the body of the loop is also optimised, but this is 
getting into the territory covered by tracing JITs.


My kind of approach would try to keep it simple, and that would be 
helped tremendously by special language constructs (something like 
Ruby's 100.times) where you can use a streamlined loop, and possible

unrolling, straight off.

(Personally, if I was creating a byte-code intepreter for Python as-is, 
I would have a -dynamic:on or -dynamic:off switch.)



Here is one of the oldest:

http://www.ibm.com/developerworks/library/l-psyco/index.html


Yes, I tried that long ago. It's very fast on certain benchmarks. (Both 
psyco and pypy can run my lexer at around 170Klps. And this is code 
using string compares and long if-elif chains, that would be crazy in 
any other language. From that point of view, it's very impressive (I can 
only get half that speed using the same methods).


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


Re: WP-A: A New URL Shortener

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 8:28 AM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> […] Thomas 'PointedEars' Lahn […] wrote:
>>> Chris Angelico wrote:
 […] Thomas 'PointedEars' Lahn […] wrote:
> Daniel Wilcox wrote:
>> Cool thanks, highly recommended to use an ORM to deter easy SQL
>> injections.
> That is to crack a nut with a sledgehammer.  SQL injection can be
> easily and more efficiently prevented with prepared statements.  […]
 You don't even need prepared statements. All you need is parameterized
 queries.
>>> A prepared statement in this context uses a parameterized query.
>>>
>>>
> 
>>
>> I know what a prepared statement is. And I know that they are
>> effective. However they are overkill - as I said, you merely need
>> parameterization.
>
> Then enlighten me, please: How is “parameterization” or a “parameterized
> query”, as *you* understand it, different from a prepared statement?

This is a prepared statement:

http://www.postgresql.org/docs/current/static/sql-prepare.html

You use a special "PREPARE" query to create *and store* a half-run
query, and then you execute it afterwards. Back in the 1990s, I had
the option of actually *compiling* my SQL queries as part of my C
code, which would prepare all the queries for future execution. It is
completely different from the dynamic parameterized queries that most
people use.

Parameterization is a more general concept which prepared statements
invariably use, but which general code need not use. A Python database
connector could choose to PREPARE/EXECUTE for every query it's given,
or it could choose to escape all the parameters and embed them, or it
could (if it's using a decent database back-end like PostgreSQL)
simply send the query and its associated parameters as-is. Only one of
these options is a "prepared statement". All three are "parameterized
queries", at least from the POV of Python code.

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


[issue26642] Replace stdout and stderr with simple standard printers at Python exit

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

Serhiy Storchaka added the comment:
> 1. Is there a reason only name is closed, not dunder_name? (Josh's question, 
> but I'm interesting too).

By default, sys.__stdout__ is sys.stdout. Is it ok to close the same file twice?

> 2. Is it worth to first replace standard streams with "standard printers", 
> and then close original streams? This allows to log warnings from closing 
> streams.

Yeah, I tried this locally after sending my patch. I think that we
should keep a strong reference and only "decref" after the stream is
replaced.

> 3. "standard printers" are used at startup and at shutdown. Can we reuse some 
> code? Or save and reuse "standard printers"?

I will check, it's maybe possible to share some code inside pylifecycle.c.

> 4. Daemons close standard streams and fileno(stdout) can return unrelevant 
> value. Perhaps it is not good idea to recreate closed stdout.

Ah yes, while playing with my patch, I noticed that I replaced stdout
even if sys.stdout was NULL or None.

Closed stdout is a different thing. I guess that we can try to call
stdout.closed() and only replaced it with a standard printer it
closed() returns True (don't do it on error nor if closed() returns
false).

--

___
Python tracker 

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



Re: WP-A: A New URL Shortener

2016-03-25 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> […] Thomas 'PointedEars' Lahn […] wrote:
>> Chris Angelico wrote:
>>> […] Thomas 'PointedEars' Lahn […] wrote:
 Daniel Wilcox wrote:
> Cool thanks, highly recommended to use an ORM to deter easy SQL
> injections.
 That is to crack a nut with a sledgehammer.  SQL injection can be
 easily and more efficiently prevented with prepared statements.  […]
>>> You don't even need prepared statements. All you need is parameterized
>>> queries.
>> A prepared statement in this context uses a parameterized query.
>>
>> 

> 
> I know what a prepared statement is. And I know that they are
> effective. However they are overkill - as I said, you merely need
> parameterization.

Then enlighten me, please: How is “parameterization” or a “parameterized 
query”, as *you* understand it, different from a prepared statement?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 2:50 AM, Steven D'Aprano  wrote:
> On Fri, 25 Mar 2016 06:54 am, BartC wrote:
>
>>> In the case of C, the line is limited to working with some specific type
>>> (say, an int32). Even there, if the addition might overflow, the
>>> behaviour is undefined and the compiler can do anything it wants
>>> (including time travel,
>>
>> I'm pretty sure it can't do time travel...
>>
>>   or erasing your hard disk).
>
>
> You are absolutely, and potentially catastrophically, mistaken on that.
>
> Undefined behaviour does not mean "implementation specific behaviour". Nor
> does it mean "something sensible will happen but we don't promise what it
> will be". It means "the compiler can do anything", including ignoring the
> code you actually wrote and substituting its own faster code, which may or
> may not do what your original code did.

C's undefined behaviour is basically "you're not allowed to do this".
The compiler is free to assume that you will never do this, ergo it is
free to write out machine code that is correct only so long as you do
not do this. Let me draw a Python analogy:

1) A well-behaved iterator will return values until it raises
StopIteration, and then raise StopIteration thereafter.
2) An iterator which raises and then returns is thus badly written and
should not exist.
3) A consumer of an iterator is allowed to misbehave in the event that
the iterator returns after raising.
4) Therefore an optimizer is free to *cause* the consumer to misbehave
when given an ill-behaved iterator.

Consider this code:

def zip_forever(*iters, fillvalue=None):
"""Like zip_longest, but without the silly rule that
it should terminate once they all finish"""
while True:
yield tuple(next(it, fillvalue) for it in iters)

If all its iterators are well-behaved, this is identical (modulo
monkey-patching of names like "tuple" and "next") to:

def zip_forever(*iters, fillvalue=None):
yield from zip_longest(*iters, fillvalue=fillvalue)
tup = (None,) * len(iters)
while True: yield tup

Is PyPy/FAT Python/some other optimizer permitted to make this change?
The only difference between C's "undefined behaviour" and Python's way
of doing the spec is the answer to that one question. C says yes,
you're totally allowed to assume that; the end result in all cases
should be indistinguishable; any time you can detect that it optimized
this away, it's because of a bug somewhere else. Is your code allowed
to misbehave when other code has bugs? That, ultimately, is the
question.

Imagine a tightened up subset of the Python language that restricts
certain unusual behaviours. (This has the same purpose as PyPy's
RPython, and for all I know, RPython might do exactly this.) It's a
narrowly-used single purpose language, and its sole guarantee is that
well-written SubPython code will behave the same way in SubPython as
it does in CPython. It might then, for instance, not permit rebinding
of builtins, nor of function default argument replacements, without an
explicit "drop_caches()" call. Code could then be far more
aggressively optimized - but behaviour would become undefined in the
event that you break one of its rules. That's really all that C's
done, and you honestly don't have to get so panicky at the word
"undefined". It's simply "don't do this".

And let's face it... there's a *lot* of undefined behaviour in CPython
once you play with ctypes. Do we have any language guarantees as to
what will happen if you change the value of the integer 7 to now be 8?
Or will you just say "don't do that"?

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> […] It is so blatantly obvious that he knows precisely nothing about
> Python, but still the moderators on this list let him get away with it.

This is a mailing list?  It is moderated?  *Seriously*?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Thomas 'PointedEars' Lahn
c...@isbd.net wrote:

> Occasionally I have to make forays into Javascript, can anyone
> recommend a place similar to this list where Javascript questions can
> be asked?  The trouble is that there are very many usenet Javascript
> lists and it's difficult to guess which one[es] might be good.

There is no Javascript. 

There are no Usenet lists.

This is not only a Python *mailing* list, it is also mirrored as an 
international Usenet _newsgroup_,  (which I am 
reading).

If you can accept all of that, then the international Usenet _newsgroup_ 
 (where I am posting primarily) is for you.
So are other national/language-specific newsgroups on the JavaScripts and 
other ECMAScript implementations.  In your newsreader, search for newsgroups 
whose name contains “javascript”.

Next time, read  and STFW first, and get a real name.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-25 Thread Mark Lawrence

On 25/03/2016 02:49, Michael Torrie wrote:



I've been trying to follow things on this thread, and I understand a bit
about Pythonic ideomatic style and I know what Python is really good at
and some of what it's not so good at, but it seems like one of Bart's
original contentions was that given a certain problem, coded in a
non-pythonic way, got slower under Python 3 than it was under Python 2
(if I recall correctly).  In other words a performance regression.
Somehow this seems to have gotten lost in the squabble over how one
should use Python.



Python 3 is slower, period.  The devs are trying to grab some of that 
back.  I'd still say that the additions in Python 3, many of which were 
backported to 2.6/7, were worth this regression.


--
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: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Ray Cote
On Fri, Mar 25, 2016 at 5:00 PM, Zachary Ware  wrote:

> I'm assuming you're doing `await process_request()` elsewhere, which
> is what's producing your error: you're trying to start the loop within
> a coroutine running on that loop.  loop.run_in_executor() returns a
> Future just like any other coroutine, so process_request just needs
> this:
>
>async def process_request():
>loop = asyncio.get_event_loop()
>results = await loop.run_in_executor(None, blocking_func, 'hello')
>

Yes, that was precisely the directive I needed. This is now working
perfectly.
Thanks
—Ray



-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Zachary Ware
On Fri, Mar 25, 2016 at 3:56 PM, Marko Rauhamaa  wrote:
> Ray Cote :
>
>> I’m trying to perform an synchronous task while using asyncio.
>
> You seem to want to do something you shouldn't be doing. Asyncio does
> not tolerate synchronous/blocking calls. You will need to move those in
> separate threads or processes if you can't turn them into asynchronous
> tasks.

That's exactly what run_in_executor does.

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


Re: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Marko Rauhamaa
Ray Cote :

> I’m trying to perform an synchronous task while using asyncio.

You seem to want to do something you shouldn't be doing. Asyncio does
not tolerate synchronous/blocking calls. You will need to move those in
separate threads or processes if you can't turn them into asynchronous
tasks.


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


Re: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Zachary Ware
On Fri, Mar 25, 2016 at 3:24 PM, Ray Cote
 wrote:
> Hello:
>
> I’m trying to perform an synchronous task while using asyncio.
> I understand the solution is to use run_in_executor.
> I’m not clear on how to add this into an already running event loop.
>
> I’ve found lots of examples showing how to set up a loop and run this, but
> I’m blocked in regards to doing this when the loop is already established.
>
>
> Example code:
>
> def blocking_func(param1):
> # call the blocking call here.
> return results
>
> async def process_request():
> loop = asyncio.get_event_loop()
> block = loop.run_in_executor(None, blocking_func, “hello”)
> results = await loop.run_until_complete(asyncio.gather(*[block, ])
>
> The above code says “loop already running.” because we’re already in an
> async ask that has been awaited. What is the proper method of adding in
> this new synchronous task?

I'm assuming you're doing `await process_request()` elsewhere, which
is what's producing your error: you're trying to start the loop within
a coroutine running on that loop.  loop.run_in_executor() returns a
Future just like any other coroutine, so process_request just needs
this:

   async def process_request():
   loop = asyncio.get_event_loop()
   results = await loop.run_in_executor(None, blocking_func, 'hello')

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


[issue26642] Replace stdout and stderr with simple standard printers at Python exit

2016-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There are some questions.

1. Is there a reason only name is closed, not dunder_name? (Josh's question, 
but I'm interesting too).

2. Is it worth to first replace standard streams with "standard printers", and 
then close original streams? This allows to log warnings from closing streams.

3. "standard printers" are used at startup and at shutdown. Can we reuse some 
code? Or save and reuse "standard printers"?

4. Daemons close standard streams and fileno(stdout) can return unrelevant 
value. Perhaps it is not good idea to recreate closed stdout.

--

___
Python tracker 

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



[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

1. What if only object which directly owns a limited resource will emit a 
ResourceWarning? This can break some tests, but may be these tests are too 
strong? Current GC may be better than when io classes were implemented.

2. An object which indirectly owns a limited resource don't know about this if 
use only public API. It can known about this only if the wrapped object 
provides _dealloc_warn(). Thus _dealloc_warn() extends the API. If allows an 
object which indirectly owns a limited resource emit a resource warning, it may 
be worth to expose _dealloc_warn() or something equivalent as public API.

--

___
Python tracker 

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



Adding run_in_executor task to already existing loop.

2016-03-25 Thread Ray Cote
Hello:

I’m trying to perform an synchronous task while using asyncio.
I understand the solution is to use run_in_executor.
I’m not clear on how to add this into an already running event loop.

I’ve found lots of examples showing how to set up a loop and run this, but
I’m blocked in regards to doing this when the loop is already established.


Example code:

def blocking_func(param1):
# call the blocking call here.
return results

async def process_request():
loop = asyncio.get_event_loop()
block = loop.run_in_executor(None, blocking_func, “hello”)
results = await loop.run_until_complete(asyncio.gather(*[block, ])

The above code says “loop already running.” because we’re already in an
async ask that has been awaited. What is the proper method of adding in
this new synchronous task?

Regards
—Ray
-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

The fix was applied to default in c9bc6614a652 but I got the commit message 
wrong.  I will not attempt to fix it (not sure it is even possible in hg.)

--

___
Python tracker 

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



[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

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



[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 361a92204d4a by Alexander Belopolsky in branch '3.5':
Issue#26616:Fixed a bug in datetime.astimezone() method.
https://hg.python.org/cpython/rev/361a92204d4a

--
nosy: +python-dev

___
Python tracker 

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



Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Ben Bacarisse
Cousin Stanley  writes:

> 
>> Occasionally I have to make forays into Javascript, 
>> can anyone recommend a place similar to this list 
>> where Javascript questions can be asked ?
> 
>
>   Several years back I found 
>   the newsgroup comp.lang.javascript
>   to be helpful 

Still going.  It can't hurt to try.

>   However, I haven't used that group
>   for some time now so don't know
>   the current nature of the group 

I suspect some people are put off answering because there's a poster
whose main pleasure seems to be to nit-pick other people's answers (and
the OP will be told there's no "Javascript" for starters!).  The usual
Usenet thick skin advised.

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


[issue26643] regrtest: rework libregrtest.save_env submodule

2016-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Old code looks much clearer to me.

Consider your example with the 'sys.path' resource. With current code I need to 
understand only 3 simple lines of the code in two close methods. With the patch 
I need to research 4 classes with 16 complicated methods! This is awful!

That was about first two items.

Now about using __subclasses__(). Is it guarantied that the order of classes in 
__subclasses__() is the same as the order of declaration and always will be? 
The order of restoring resources matters. For now if there is needed to change 
the order of restoring resources (I'm sure there will be need to do this in 
future) you need to change only one or two lines. With your patch you need to 
reorder classes declarations. This not only makes the patch larger, but makes 
harder to review the diff and to track the history of the file.

Nicer diff for dictionaries can be an enhancement, but it can be implemented 
without such large rewriting.

--

___
Python tracker 

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



[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
stage: patch review -> commit review

___
Python tracker 

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



[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
versions:  -Python 3.3, Python 3.4

___
Python tracker 

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



[issue26616] A bug in datetime.astimezone() method

2016-03-25 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> When you made your first astimezone() call, (t = u.astimezone()),
> it was made without a tzinfo parameter, and should result in t's
> timezeone being EST by the documentation.

No, u in my test case was selected to be right before the "fall-back" time.  
The clocks in New York are moved back at 2am local, or 6am UTC.  You can verify 
that with zdump:

$ zdump -v America/New_York | grep 2015 | grep Nov
America/New_York  Sun Nov  1 05:59:59 2015 UTC = Sun Nov  1 01:59:59 2015 EDT 
isdst=1
America/New_York  Sun Nov  1 06:00:00 2015 UTC = Sun Nov  1 01:00:00 2015 EST 
isdst=0

so 5am UTC is 1 hour before the transition and is correctly translated to EDT 
by astimezone().

--

___
Python tracker 

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



[issue26643] regrtest: rework libregrtest.save_env submodule

2016-03-25 Thread STINNER Victor

New submission from STINNER Victor:

(I pushed the change 245a16f33c4b, but Serhiy asked me to review it and discuss 
it. So I reverted my change and created this issue.)

I noticed many times that buildbots log "test xxx changed yyy" but this line is 
not enough to debug the issue. I propose to always display the old and new 
value to easy debugging these issues.

Sometimes, I try to reproduce the issue, but I fail to reproduce it locally. I 
may depend on the test execution order and the platform.

Attached patch changes:

* Replace get/restore methods with a Resource class and Resource subclasses
* Create ModuleAttr, ModuleAttrList and ModuleAttrDict helper classes
* Use __subclasses__() to get resource classes instead of using an hardcoded
  list (2 shutil resources were missinged in the list!)
* Don't define MultiprocessingProcessDangling resource if the multiprocessing 
module is missing
* Nicer diff for dictionaries. Useful for the big os.environ dict
* Reorder code to group resources


I chose to use classes to be able to easily customize how "Before/After" (value 
diff) is displayed: the new display_diff() method.

I also wrote helper classes to factorize the code.

Example:

def get_sys_path(self):
return id(sys.path), sys.path, sys.path[:]
def restore_sys_path(self, saved_path):
sys.path = saved_path[1]
sys.path[:] = saved_path[2]

becomes

   class SysPath(ModuleAttrList):
   name = 'sys.path'

When sys.path is modified, currently Python displays the whole (id, object, 
object_copy) tuple which is not easily readable. With my change, it only 
displays object_copy (one list).

I began to write a pretty diff for ModuleAttrList, but it looks non trivial, 
and I'm not sure that it's worth (since lists are quite short).

--
components: Tests
files: save_env.patch
keywords: patch
messages: 262449
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: regrtest: rework libregrtest.save_env submodule
versions: Python 3.6
Added file: http://bugs.python.org/file42293/save_env.patch

___
Python tracker 

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



[issue26591] datetime datetime.time to datetime.time comparison does nothing

2016-03-25 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

Python 3.6.0a0 (default:245a16f33c4b, Mar 25 2016, 14:11:43)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> if datetime.time(22, 15) > datetime.time(16, 0):
... print('works for me')
...
works for me

--
resolution:  -> works for me
stage: test needed -> resolved
status: open -> closed

___
Python tracker 

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



Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread Cousin Stanley


> Occasionally I have to make forays into Javascript, 
> can anyone recommend a place similar to this list 
> where Javascript questions can be asked ?


  Several years back I found 
  the newsgroup comp.lang.javascript
  to be helpful 

  However, I haven't used that group
  for some time now so don't know
  the current nature of the group 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26629] Need an ability to build standard DLLs with distutils

2016-03-25 Thread Steve Dower

Steve Dower added the comment:

Oh, and just saw that you're apparently asking about 2.7. I was referring to 
the 3.5 sources for distutils, so some things may be different in 2.7. But I 
doubt distutils has changed that much since then.

--

___
Python tracker 

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



[issue26629] Need an ability to build standard DLLs with distutils

2016-03-25 Thread Steve Dower

Steve Dower added the comment:

(Obligatory recommendation that you use Cython rather than ctypes, especially 
if you're going to require your users to have a compiler handy - in general 
this isn't recommended on Windows at all; make sure you distribute wheels if 
you want to make your users' lives easiest.)

I haven't tested this, but I believe you want to specify your libraries with 
the `libraries` parameter, not the `extensions` parameter:

LIBRARIES = [
('my_lib', {'sources': ['my_lib.c'], 'include_dirs': ['dirs', 'if', 'you', 
'want'], 'macros': ['DEFINES', 'IF', 'YOU', 'WANT']})
]

setup(
...
libraries=LIBRARIES,
...
)

Then you need to ensure build_clib is run to produce it. I'd imagine that will 
just happen, but I could be wrong.

Again, I haven't tried this myself, but it seems to be the right way to build a 
regular library.

--

___
Python tracker 

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



[issue26631] Unable to install Python 3.5.1 on Windows 10 - Error 0x80070643: Failed to install MSI package.

2016-03-25 Thread Steve Dower

Steve Dower added the comment:

Thanks for the report

You should have another log file near the one you attached (in your 
%LocalAppData%\Temp directory) with "core_JustForMe" in the name. Could you put 
that one up as well?

--

___
Python tracker 

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



[issue26640] xmlrpc.server imports xmlrpc.client

2016-03-25 Thread Brett Cannon

Brett Cannon added the comment:

Yes because the location of the object is based on where it's defined, not 
where you got it from.

While I get the motivation to be a little cleaner in the xmlrpc package, 
"practicality beats purity" here in that the reorg isn't worth it at this point 
in the face of potentially breaking code for little benefit.

Closing as "wont fix"; sorry, Valentin.

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

___
Python tracker 

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



Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Marko Rauhamaa
Steven D'Aprano :

> Undefined behaviour in C is a minefield waiting to blow your program's
> legs off, because the designers of the language made the explicit
> choice that they wanted the language to be as fast and efficient as
> possible, even at the cost of safe, reproducible behaviour.

Yes, although the same could be true for Python as well.

For example, you could have this program:

===begin poof.py
assert 1 < 0
===end poof.py==

When it is run, you might see this:


$ python3 poof.py
python3: the VM vanished in a puff of logic while executing 'poof.py'


Java's Hotspot produces very aggressive optimizations, essentially
identifying bugs in the code and deducing the coder knows the bugs will
never be realized at runtime and so the code paths that lead to the bug
can be removed.


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


Re: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python

2016-03-25 Thread Ethan Furman

On 03/25/2016 06:03 AM, Albert-Jan Roskam wrote:
> Somebody wrote:
>> Somebody else wrote:


I know Python does not have variables, but names.
Multiple names cant then be bound to the same objects.

So this behavior

--> b = 234
--> v = 234
--> b is v
True

according to the above that is ok



But where is the consistency ? if I try :

--> v = 890
--> w = 890
--> v is w
False

It is a little difficult to explain this behavior to a newcommer in Python

Can someone give me the right argument to expose ?


You should not bother with object identity for objects other than None.


No.  The correct answer is: if identity is important either ensure the 
object you are getting back is a singleton (such as None, True, an Enum 
member, etc.) or you assign one name from another name:


--> b = 234
--> v = b
--> b is v
True
--> v = 890
--> w = v
--> v is w
True

If identity is not important, don't use `is`.


A little late to the party, but: how about Ellipsis? Shouldn't "is" also be 
used for that one? (It's rare, I know :))


Ellipsis is a singleton, so `is` is fine.

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2016 10:06 pm, BartC wrote:

> On 25/03/2016 01:02, Dennis Lee Bieber wrote:
>> On Thu, 24 Mar 2016 19:54:54 +, BartC  declaimed the
>> following:
>>
>>
>>>
>>> (I use a dedicated repeat-N-times loop that needs no explicit loop
>>> variable,
> 
>> Well, that sure wouldn't support a Python for-loop...
> 
> If I may, I'll reply to this point outside the group, at this link:
> 
> http://pastebin.com/hfAKN2jg

Why split the discussion to *Pastebin*, of all places?

Anyway, this is (in my opinion) the only relevant part of your comments
there:



[quote]
But it is an optimisation that /could/ be done by the byte-code compiler
when it sees a construct such as:
 
for i in range(100):
   .
and 'i' isn't used within the loop. (I don't know what Python says about the
value of i after the loop terminates.)
[end quote]


i is guaranteed to have the same value outside the loop as it last had
inside the loop, unless you explicitly unbind the name using "del" (or
something equivalent).

So after:

for i in range(100):
pass
print(i)


"99" will be printed. Likewise:

for i in range(100):
if i == 50: break
print(i)


"50" will be printed.


[quote] 
This change would require a new byte-code (one that goes at the end of a
loop, not the start), which probably wouldn't be popular either. And, by
itself, would have very little impact on the majority of programs. (Also,
if loops are that much of a problem, this is where PyPy excels.)
[end quote]


I am pretty sure that PyPy takes lots of efforts to optimize loops, but I
can't tell you precisely what.

I would also expect that Victor Stinner's FAT Python project will
(eventually) look at optimizing such for-loops too. If you see something
like:

for i in range(N):
do_stuff()


and three conditions hold:

(1) i is unused in the loop body;

(2) range is still bound to the expected built-in function, and no
other "range" in a nearer scope (say, a local variable called "range", or a
global) exists to shadow it; and

(3) and the body of the for-loop has no side-effects that might affect the
truth of (1)

then it should be safe to replace this loop with a fast, C loop that just
calls the body of the loop N times. And that in turn might be fully or
partly unrolled, e.g. 

for i in range(4):
spam()

could become:

spam()
spam()
spam()
spam()


(This is a pretty standard compiler optimization technique, and if I recall
correctly, PyPy already does this.)


#1 (is i used in the loop?) can be detected at compile-time. There might be
some tricky corner cases involving calls to nested functions, and of course
any call to eval or exec make the analysis intractable, but I think it is
otherwise easy to tell whether or not i is used in the for-loop.

#2 (is range the expected range) can be handled by assuming it is, and
keeping a guard for the case that it isn't. That's what FAT Python will do.
I think PyPy does something similar.

I don't have an intuition on how hard #3 (does the loop body have any
side-effects that might affect this optimization?) might be, except to say
that the presence of an eval or exec inside the body will probably make the
optimization unsafe.

It wouldn't surprise me if the unmaintained but still working Psycho project
handled this, as well as such newer projects as pyjion, pyston, numba and
theano.

Bart, possibly something you have missed in this discussion: many of the
optimizations you are surprised not to see are not, and may never be, in
the vanilla Python language. But they are being included in language
add-ons. There is a thriving, experimental but still usable, culture of JIT
compilers for Python. Here is one of the oldest:

http://www.ibm.com/developerworks/library/l-psyco/index.html


Pyscho is unmaintained and doesn't work on anything better than 2.6, but the
author has gone on to be one of the lead devs in PyPy, and it has inspired
newer projects like numba and theano. The attitude of the core developers,
especially Guido, is that the reference interpreter CPython should stick to
only the easiest, least controversial optimizations (if any!) and leave the
hard ones to third-party add-ons.


-- 
Steven

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


Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Steven D'Aprano
On Fri, 25 Mar 2016 06:54 am, BartC wrote:

>> In the case of C, the line is limited to working with some specific type
>> (say, an int32). Even there, if the addition might overflow, the
>> behaviour is undefined and the compiler can do anything it wants
>> (including time travel,
> 
> I'm pretty sure it can't do time travel...
> 
>   or erasing your hard disk).


You are absolutely, and potentially catastrophically, mistaken on that.

Undefined behaviour does not mean "implementation specific behaviour". Nor
does it mean "something sensible will happen but we don't promise what it
will be". It means "the compiler can do anything", including ignoring the
code you actually wrote and substituting its own faster code, which may or
may not do what your original code did.

We can presume that no non-malicious C compiler will *intentionally* erase
your hard drive because you added 1 to an integer without checking for
overflow, but it is certainly true that undefined behaviour can lead to any
behaviour at all. Undefined behaviour in C is a major cause of bugs and
security vulnerabilities.

Raymond Chen, one of Microsoft's luminaries, describes how undefined
behaviour can travel backwards in time to affect code that executes
*before* the undefined behaviour occurs:

https://blogs.msdn.microsoft.com/oldnewthing/20140627-00/?p=633/

Many people assume that if your code has undefined behaviour, you might have
no idea what happens from that point on, but at least you can reason
correctly about the state of the program prior to that. THIS IS INCORRECT.
The C standard makes no such promise, and in fact explicitly states that
the effect of undefined behaviour can affect code that runs before the
undefined behaviour occurs.


Here is an excellent three part article about undefined behaviour:

http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html

And three-parter:

http://blog.regehr.org/archives/213
http://blog.regehr.org/archives/226
http://blog.regehr.org/archives/232

Bruce Dawson:

https://randomascii.wordpress.com/2014/05/19/undefined-behavior-can-format-your-drive/

And I love the title of this talk from Robert C Seacord at CERT:

"Dangerous Optimizations and the Loss of Causality"

http://bsidespgh.com/2014/media/speakercontent/DangerousOptimizationsBSides.pdf



Undefined behaviour in C is a minefield waiting to blow your program's legs
off, because the designers of the language made the explicit choice that
they wanted the language to be as fast and efficient as possible, even at
the cost of safe, reproducible behaviour.



-- 
Steven

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


Re: Problem With Embedded Icon and Python 3.4

2016-03-25 Thread Wildman via Python-list
On Fri, 25 Mar 2016 00:34:13 -0500, Zachary Ware wrote:

> On Fri, Mar 25, 2016 at 12:10 AM, Wildman via Python-list
>  wrote:
>> I have a program that I have been trying to rewrite so it will
>> run on Python 2.7 and 3.4.  It has been a pain to say the least.
>> Thank $DIETY for aliases.  Anyway, I got it all working except
>> for one thing.  The program has an embedded icon.  It is displayed
>> in the window's titlebar.  The icon is a 16x16 png that has been
>> base64 encoded using a Linux utility called memencoder.  The code
>> below works perfectly with Python 2.7.  The icon data is complete
>> for anyone that wants to try to run this code:
>>
>> encoded_icon = """\
> [...]
>> I tried converting the icon string to a byte variable like this:
>>
>> encoded_icon = bytes("""\
>> iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj
>> (...)
>> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""")
>>
>>
>> That give me a different error:
>>
>> Traceback (most recent call last):
>>   File "./myprogram.py", line 269, in 
>> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""")
>> TypeError: string argument without an encoding
>>
>> I'm not sure what that means.  I looks like it wants the string
>> to be encoded but it already is.
> 
> The bytes constructor in Python 3 requires you to provide an encoding
> (utf-8, ascii, latin-1, koi8, etc) when passing in a string, otherwise
> it doesn't know what bytes you want and refuses to guess.  You could
> fix this by adding `encoding='ascii'` to the bytes() call–but I'm not
> certain that that would work in 2.7, and there's a much easier method,
> noted later.
> 
>> And why the reference to only
>> the last line of the string?
> 
> Because the traceback would be huge if it included the entire function
> call, and there's no need to.  You can find the error from just that
> line.  It would be arguably more useful to show the first line, but
> that's more difficult to do.
> 
>> I am at a loss here.  Any help would be greatly appreciated.
> 
> What you need here is a bytes literal, which is accomplished by
> prepending a 'b' to the string literal.   Your `encoded_icon = """\`
> just needs to become `encoded_icon = b"""\`.  See here [1] for more
> information.

Thanks for the info and the link.  That fixed the problem.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem With Embedded Icon and Python 3.4

2016-03-25 Thread Wildman via Python-list
On Fri, 25 Mar 2016 01:30:17 -0400, Terry Reedy wrote:

> On 3/25/2016 1:10 AM, Wildman via Python-list wrote:
>> I have a program that I have been trying to rewrite so it will
>> run on Python 2.7 and 3.4.  It has been a pain to say the least.
>> Thank $DIETY for aliases.  Anyway, I got it all working except
>> for one thing.  The program has an embedded icon.  It is displayed
>> in the window's titlebar.  The icon is a 16x16 png that has been
>> base64 encoded using a Linux utility called memencoder.  The code
>> below works perfectly with Python 2.7.  The icon data is complete
>> for anyone that wants to try to run this code:
>>
>> encoded_icon = """\
> 
> To make this literal a bytes literal, prepend 'b'.
> 
> encoded_icon = b'''\

Whoopee, that worked!  Thank you.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26640] xmlrpc.server imports xmlrpc.client

2016-03-25 Thread ProgVal

ProgVal added the comment:

Even if xmlrpc.client imported them in its namespace?

--

___
Python tracker 

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



[issue26543] imaplib noop Debug

2016-03-25 Thread Maciej Szulik

Changes by Maciej Szulik :


--
nosy: +maciej.szulik

___
Python tracker 

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



[issue26636] SystemError while running tests: extra exception raised

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

I hope that the exception will help you to write better software (don't loose 
exceptions) ;-)

--
status: open -> closed

___
Python tracker 

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



[issue26636] SystemError while running tests: extra exception raised

2016-03-25 Thread Denis

Denis added the comment:

Thank you!  
The error  was that some calls in pycrypto code were aggregated and exceptions 
in those calls were ignored.
Here is the patch for pycrypto that fixed the build.

@@ -1427,7 +1429,9 @@ getStrongPrime (PyObject *self, PyObject *args, PyObject 
*kwargs)
Py_BLOCK_THREADS;
res = 1;
res &= getRandomRange (X, lower_bound, upper_bound, randfunc);
+   if (res!=0)
res &= getRandomNBitInteger (y[0], 101, randfunc);
+   if (res!=0)
res &= getRandomNBitInteger (y[1], 101, randfunc);
Py_UNBLOCK_THREADS;

So this code tried to aggregate exceptions before propagating them, that was 
the reason for exception.

--
resolution:  -> not a bug

___
Python tracker 

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



[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

Ok, I now understand the problem better. They are two kinds of io objects:

(1) object which directly or indirectly owns a limited resource like file 
descriptor => must emit a ResourceWarning
(2) object which don't own a limited resource => no ResourceWarning must be 
logged

Examples of (1): FileIO, BufferedReader(FileIO), 
TextIOWrapper(BufferedReader(FileIO))

Examples of (2): BytesIO, BuffereadReader(BytesIO), 
TextIOWrapper(BuffereadReader(BytesIO))


The tricky part is to decide if an object owns a limited resource or not. 
Currently, the io module uses the _dealloc_warn() trick. A close() method tries 
to call _dealloc_warn(), but it ignores any exception when calling 
_dealloc_warn(). BufferedReader calls raw._dealloc_warn(). TextIOWrapper calls 
buffer._dealloc_warn().


For case (1), BufferedReader(FileIO).close() calls FileIO._dealloc_warn() => 
ResourceWarning is logged

For case (2), BufferedReader(BytesIO).close() calls BytesIO._dealloc_warn() 
raises an AttributeError => no warning is logged


Well, we can call this a hack, but it works :-) pyio_res_warn-3.patch 
implements the same hack in _pyio.

--

___
Python tracker 

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



Re: Tkinter --> Why multiple windows

2016-03-25 Thread kevind0718
On Thursday, March 24, 2016 at 9:24:44 PM UTC-4, Wildman wrote:
> On Thu, 24 Mar 2016 13:24:16 -0700, kevind0718 wrote:
> 
> > Hello:
> > 
> > newbie Tkinter question
> > 
> > If I run the code below two windows appear.
> > One empty and one with the text box and button.
> > 
> > Why?  please
> > 
> > KD
> > 
> > 
> > 
> > from Tkinter import *
> > 
> > class MyDialog:
> > def __init__(self, parent):
> > 
> > top = self.top = Toplevel(parent)
> > 
> > Label(top, text="Value").pack()
> > 
> > self.e = Entry(top)
> > self.e.pack(padx=5)
> > 
> > b = Button(top, text="OK", command=self.ok)
> > b.pack(pady=5)
> > 
> > def ok(self):
> > 
> > print "value is", self.e.get()
> > 
> > self.top.destroy()
> > 
> > 
> > root = Tk()
> > 
> > d = MyDialog(root)
> > 
> > root.wait_window(d.top)
> 
> Try this:
> 
> from Tkinter import *
> 
> class MyDialog(Frame):
> 
> def __init__(self, parent):
> Frame.__init__(self, parent)
> self.parent = parent
> self.pack(fill=BOTH, expand=1)
> self.parent.title("MyDialog")
> Label(self, text="Value").pack()
> self.e = Entry(self)
> self.e.pack(padx=5)
> self.b = Button(self, text="OK", command=self.ok)
> self.b.pack(pady=5)
> 
> def ok(self):
> print "value is", self.e.get()
> 
> root = Tk()
> d = MyDialog(root)
> root.mainloop()
> 
> -- 
>  GNU/Linux user #557453
> May the Source be with you.


Looking at the lines below 
As related to the code I posted above.
I believe this code will allow me to instantiate the class
MyDialog, wait until the window is destroyed and then 
continue on my merry way.

root = Tk()
d = MyDialog(root)
root.wait_window(d.top) 


Now if I pass an instance of  Unamepword into the constructor of
MyDialog(unamepword) , I can modify uStr and pWord in MyDialog and 
the local copy will get updated.  
Correct?

class Unamepword:
## 
## class to hold user name and pWord for Database
uName = None
pWord = None
def __init__(self, uStr, pStr):
self.uName = uStr
self.pWord = pStr

Many thanks for your attention to this matter.

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


[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> For io.BytesIO, I fixed the code to inherit correctly IOBase finalizer.

Oh, I forgot to include it in my patch. But it's maybe better to have it in a 
different patch: see attached bytesio_stringio.patch which changes also 
io.StringIO to inherit the IOBase finalizer.

Emitting a ResourceWarning in io.BytesIO and io.StringIO adds a *lot* of 
warnings when running the Python test suite. Since these objects only contain 
memory, no very limited resource like file descriptors, it's probably better to 
*not* log ResourceWarning for them.

--
Added file: http://bugs.python.org/file42292/bytesio_stringio.patch

___
Python tracker 

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



Re: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python

2016-03-25 Thread Chris Angelico
On Sat, Mar 26, 2016 at 12:03 AM, Albert-Jan Roskam
 wrote:
>> You should not bother with object identity for objects other than None.
>
>
> A little late to the party, but: how about Ellipsis? Shouldn't "is" also be 
> used for that one? (It's rare, I know :))

Yes, and also True and False, if you're checking for the specific
values. (Though it's more common in Python to merely care about
truthiness/falsiness.) Other common identity checks include:

if str is bytes:
# Python 2 handling, where "native strings" are byte strings
else:
# Python 3 handling, where "native strings" are text strings

if iter(x) is x:
# x is an iterator, not some other iterable

_SENTINEL = object()
def func(arg=_SENTINEL):
if arg is _SENTINEL:
# arg was not passed

Anyone who says that identity checks are only for None is
significantly over-simplifying things. This isn't necessarily a bad
thing, but it should never be taken to be the whole story.

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


[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> I think we should use one of Martin's option. If there are any issues with 
> garbage collecting, we should fix the garbage collector.

Ok, here is a new simpler proposition: remove all _dealloc_warn() method, and 
simply emit the ResourceWarning in IOBase finalizer.

With this change, all objects which inherit from io.IOBase (or _pyio.IOBase) 
now emits a ResourceWarning if they are not closed explicitly. You have to 
override the __del__() method to prevent this warning.

A lot of new objects start to log ResourceWarning: io.SocketIO, 
_pyio.TextIOWrapper, io.BytesIO, http.client.HTTPResponse, etc.

For io.BytesIO, I fixed the code to inherit correctly IOBase finalizer.

--

A lot of tests start to fail because they emit a lot of ResourceWarning 
warnings. I don't know yet if it's a feature or a bug :-)

--

With the patch, Python starts to logs warnings like:

sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='' 
mode='w' encoding='UTF-8'>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='' 
mode='r' encoding='UTF-8'>

You can use my patch of the issue #26642 to fix these warnings.

ResourceWarning is emited even if FileIO.closefd is false.

Note: It looks like the ResourceWarning is not always displayed. Yet another 
bug?

--
Added file: http://bugs.python.org/file42291/iobase_finalizer.patch

___
Python tracker 

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



[issue25654] test_multiprocessing_spawn ResourceWarning with -Werror

2016-03-25 Thread STINNER Victor

STINNER Victor added the comment:

> Lets open new issue for this.

I opened the issue #26642 "Replace stdout and stderr with simple standard 
printers at Python exit".

--

___
Python tracker 

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



[issue26642] Replace stdout and stderr with simple standard printers at Python exit

2016-03-25 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue26642] Replace stdout and stderr with simple standard printers at Python exit

2016-03-25 Thread STINNER Victor

New submission from STINNER Victor:

The Python shutdown process is complex and fragile.

It was discussed in the issue #25654 to replace stdout and stderr with simple 
"standard printers" (implemented in C, don't depend on other Python objects or 
modules).

Attached patch implements this idea. The patch begins with closing standard 
stream objects (sys.stdin, sys.stdout, sys.stderr), and then replace stdout and 
stderr.

--
files: replace_stdio.patch
keywords: patch
messages: 262436
nosy: haypo
priority: normal
severity: normal
status: open
title: Replace stdout and stderr with simple standard printers at Python exit
versions: Python 3.6
Added file: http://bugs.python.org/file42290/replace_stdio.patch

___
Python tracker 

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



RE: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python

2016-03-25 Thread Albert-Jan Roskam
> To: python-list@python.org
> From: __pete...@web.de
> Subject: Effects of caching frequently used objects, was Re: Explaining  
> names  vs variables  in Python
> Date: Wed, 2 Mar 2016 10:12:48 +0100
> 
> Salvatore DI DIO wrote:
> 
> > Hello,
> > 
> > I know Python does not have variables, but names.
> > Multiple names cant then be bound to the same objects.
> > 
> > So this behavior
> > 
>  b = 234
>  v = 234
>  b is v
> > True
> > 
> > according to the above that is ok
> > 
> > 
> > 
> > But where is the consistency ? if I try :
> > 
>  v = 890
>  w = 890
>  v is w
> > False
> > 
> > It is a little difficult to explain this behavior to a newcommer in Python
> > 
> > Can someone give me the right argument to expose ?
> 
> You should not bother with object identity for objects other than None.


A little late to the party, but: how about Ellipsis? Shouldn't "is" also be 
used for that one? (It's rare, I know :))
Albert-Jan

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


[issue23551] IDLE to provide menu link to PIP gui.

2016-03-25 Thread Aivar Annamaa

Changes by Aivar Annamaa :


--
nosy:  -Aivar.Annamaa

___
Python tracker 

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



[issue26640] xmlrpc.server imports xmlrpc.client

2016-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Moving public classes and functions to other module can break pickle 
compatibility.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



  1   2   >