[issue25596] regular files handled as directories in the glob module

2015-11-10 Thread Xavier de Gaye

Xavier de Gaye added the comment:

This second patch rewrites the conditionals that decide whether to call 
_iglob() recursively, in a more natural way and without changing the behavior 
from the first patch.
Note that when 'dirname == pathname', then basename is empty and glob2() or 
glob1() are not called.

The patch also refactors the code with a new _listdir() function.

--
Added file: http://bugs.python.org/file40999/glob_isdir_2.patch

___
Python tracker 

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



[issue25263] test_tkinter fails randomly on the buildbots "AMD64 Windows10" (3.4, 3.5, 3.x)

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Tk bug looks fixed in next releases of Tk 8.5 and 8.6. Here is a patch that 
adds a workaround for the test.

--
keywords: +patch
stage:  -> patch review
type:  -> behavior
Added file: http://bugs.python.org/file41000/tkinter_test_use_workaround.patch

___
Python tracker 

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



RE: python PEP suggestion

2015-11-10 Thread Dan Strohl
You mentioned that it is a bit contrary to how Python currently works, I am not 
sure I understand that, can you elaborate a bit?


"Conditional execution, indexing (__index__), numeric conversions (__float__ 
also), and displaying are special cases related to syntax operations.  
You have left out the use of abstract base classes.  An iterable that can be 
used as a mapping can register itself as a mapping.  Json could check whether 
something is a sequence or mapping and iterate to get values or pairs of 
values."


All of the above is true, and all of the above are various tools that can work 
(and I have used most of them from time to time).  However, there is a limit to 
how many different types of special methods that should be built in, built in, 
what if I want to build an object that would return a datetime or bytearray 
object as needed, or something more esoteric, or if I wanted to provide 
different types of data depending on the calling object?  

What I thinking about is something that allows the called object to return 
information based on the calling object, (or at least based on what the calling 
object wants to ask for) in a manner that makes the most sense.

This _seems_ like it fits pretty well with Python's module / library / 
orientation...  the library authors often do not know anything about the  ones 
using their objects (and should not have to).  With something like this, it 
allows the library author to have a "standard" way of saying, "I want data in 
this format".  That could be simply saying "I am json and want data that will 
work for me", or it could be saying "I want a datetime from you".  Then, even 
if the called / passed object is not mappable, or is a subclass of something 
totally different, the called object has the ability to respond in a way that 
the author of the called object chooses.

If, for example, I choose to implement an object as a mapping object (using 
__getitem__, subclassing userdict, using collections.abc.Mapping, or whatever), 
I am in general only going to be able to answer a call to object[key] one way.  
I could certainly do a custom method or property but then we get back to both 
authors needing to coordinate more.


Functions that unnecessarily restrict inputs to subclasses of list or dict will 
not be solved by this.


Yup, it doesn't solve everything, it just provides another tool that people 
*could* use to write interoperable libraries and objects.


Of course, the tranformation would be unidirectional.


Again, yup, just like if I implemented "MyObject.__str__()", it does not 
guarantee that I did "MyObject('a_string')" it would work (and often doesn't).


The excessive indents of 31 and 15 spaces make the rest of this post 
unnecessarily hard to read.


Sorry about that, damn outlook tabs being expanded to stupid numbers I guess.  
I will do better next time..

Does any of that help?

Dan



-Original Message-
From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] On 
Behalf Of Terry Reedy
Sent: Sunday, November 08, 2015 2:27 PM
To: python-list@python.org
Subject: Re: python PEP suggestion

On 11/6/2015 1:21 PM, Dan Strohl wrote:
> All,
>
> I wanted to run the following thought past the list as a possible PEP 
> enhancement suggestion to see if it feels like something that is worth 
> proposing.   I know it is not in the PEP format at this point, I can, and 
> will, clean it up if needed, I am just trying to throw it against the wall at 
> this point to see if it resonates... (or if it falls flat and goes "splat" 
> ).
>
> Thoughts?

At first glance, plausible, but I am not sure needed, and it seems a bit 
contrary to how Python currently works.



> New special method name to allow for more flexible object type 
> casting/access, and extend type() to cast objects using this special method 
> name.
>
> Overview:
>
> Have a new special method name that would allow a given objects to request 
> information from another object in a given type, or to cast an object into a 
> different type, and extend the built in type() function to use this.
>
> Rationale:
> There is currently __str__, __int__, and __bool__ that allow me to 
> tell an object how it should reply to a request for these types of 
> basic data types.  However if I want to access a copy of the objet in 
> dict form, or as a list, or if I am trying to convert something using 
> json, there is no standard way of doing that for a custom object (I 
> know I can do __getitem__ and/or __iter__, but I many processes don't 
> try these if the object is not a subclass of dict or list/tuple)

Conditional execution, indexing (__index__), numeric conversions (__float__ 
also), and displaying are special cases related to syntax operations.  
Functions that unnecessarily restrict inputs to subclasses of list or dict will 
not be solved by this.  You have left out the use of abstract base classes.  An 
iterable that can be used as a mapping can register itself as a 

[issue25596] regular files handled as directories in the glob module

2015-11-10 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
nosy: +serhiy.storchaka
priority: normal -> low
stage:  -> patch review

___
Python tracker 

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



[issue25594] enum docs outdated re attribute access

2015-11-10 Thread Ethan Furman

Ethan Furman added the comment:

Nope, that would be a bug.

--
assignee: docs@python -> ethan.furman
stage:  -> test needed
type:  -> behavior

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote:

> Ulli Horlacher  wrote:
>> Peter Otten <__pete...@web.de> wrote:
> 
>> > - consider shutil.copyfileobj to limit memory usage when dealing with
>> > data
>> >   of arbitrary size.
>> > 
>> > Putting it together:
>> > 
>> > with open(sz, "wb") as szo:
>> > shutil.copyfileobj(u, szo)
>> 
>> This writes the http stream binary to the file. without handling it
>> manually chunk by chunk?
> 
> I have a problem with it: There is no feedback for the user about the
> progress of the transfer, which can last several hours.
> 
> For small files shutil.copyfileobj() is a good idea, but not for huge
> ones.

Indeed. Have a look at the source code:

def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf)

As simple as can be. I suggested the function as an alternative to writing 
the loop yourself when your example code basically showed

dest.write(source.read())

For the huge downloads that you intend to cater to you probably want your 
script not just to print a dot on every iteration, you need expected 
remaining time, checksums, ability to stop and resume a download and 
whatnot.

Does the Perl code offer that? Then why rewrite?

Or are there Python libraries that do that out of the box? Can you reuse 
them?



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


[issue25598] Fix memory_hex (#9951) for non-contiguous buffers

2015-11-10 Thread Stefan Krah

New submission from Stefan Krah:

memory_hex from #9951 fails for non-contiguous buffers.

--
assignee: skrah
files: memhex.diff
keywords: patch
messages: 254454
nosy: skrah
priority: normal
severity: normal
status: open
title: Fix memory_hex (#9951) for non-contiguous buffers
type: crash
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41002/memhex.diff

___
Python tracker 

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



[issue25597] unittest.mock does not wrap dict objects correctly

2015-11-10 Thread Darragh Bailey

New submission from Darragh Bailey:

Both unittest.mock and the backported release for earlier pythons don't appear 
to support mocking of dictionary objects.

Specifically I'm expecting that any of the methods used to test for membership, 
or get items from a mock object wrapping a dictionary should succeed. However 
it appears that MagicMock doesn't appear to support this.

Attached file shows an attempt to use different methods with a wrapped 
dictionary object where only the '.get()' method appears to work as expected.

--
files: test-mock-wraps-dict.py
messages: 254453
nosy: Darragh Bailey
priority: normal
severity: normal
status: open
title: unittest.mock does not wrap dict objects correctly
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file41001/test-mock-wraps-dict.py

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Ulli Horlacher  wrote:
> Peter Otten <__pete...@web.de> wrote:

> > - consider shutil.copyfileobj to limit memory usage when dealing with data
> >   of arbitrary size.
> > 
> > Putting it together:
> > 
> > with open(sz, "wb") as szo:
> > shutil.copyfileobj(u, szo)
> 
> This writes the http stream binary to the file. without handling it
> manually chunk by chunk?

I have a problem with it: There is no feedback for the user about the
progress of the transfer, which can last several hours.

For small files shutil.copyfileobj() is a good idea, but not for huge ones.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25589] test_ascii_formatd fails on Mac when built with Intel compiler

2015-11-10 Thread R. David Murray

R. David Murray added the comment:

Someone can correct me if I'm wrong, but my expectation would be that since we 
use ICC for the main compile on the ICC buildbots, we also compile the bundled 
ctypes using it.  It is hard to see how any of the other modules would affect 
this.

--

___
Python tracker 

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



[issue25589] test_ascii_formatd fails on Mac when built with Intel compiler

2015-11-10 Thread Chris Hogan

Chris Hogan added the comment:

I guess since no one can reproduce the error, it must be a problem with how I'm 
building it.  We build our own dependencies (zlib, bzip, sqlite3, openssl, 
etc.) with the Intel compiler, so it could be any number of things causing the 
issue. Closing as not a bug.

--
resolution:  -> not a bug
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: IDLE quits unexpectedly when about to open or creat a new file

2015-11-10 Thread Terry Reedy

On 11/10/2015 6:01 AM, Chris Angelico wrote:

On Tue, Nov 10, 2015 at 9:46 PM,   wrote:

I need help to find out what's going on. I did some research, but I couldn't 
find anything to solve this problem:

- I open the IDLE program;


From the Start menu icon, let us presume.


- I go to the 'File' menu;


Of the shell window, I presume.


- I select the 'New File' option


This should create an empty EditorWindow instance.


- IDLE quits.


Puzzling.  The shell window is a subclass of EditorWindow, so 
EditorWindow.__init__ has already run once -- without the extra stuff 
added by the subclass.



I run the IDLE version 3.3.3 on Windows 8.1 Pro.
Should I install the most recent version?


That would be a good idea in general.  But first try what Chris 
suggested below.  I am about half sure that the specific problem is on 
your system.  It is possible that you need to delete something in 
HOMEDIR/.idlerc/ but lets see what the error message is.  Have you been 
using IDLE a while, or just started?



That sounds like a very interesting problem. Can you try running it
from the command line, please? I'm not sure how to open one up from
Win 8, but it should be in the Start menu somewhere, or possibly press
Windows+R and type "cmd". With that up, type this:

python -m idlelib.idle

That should open up the same IDLE window that you know and recognize.
Do the exact same thing that caused the unexpected termination, and
then you should go back to the command prompt - hopefully with some
sort of error message. Copy and paste that message (as text, please,
not an image) into an email; that information could be very helpful.


--
Terry Jan Reedy

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


[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread Guido van Rossum

Guido van Rossum added the comment:

Hm... I don't know what answer you would expect. Who says your mock shouldn't 
behave like a coroutine? In general, passing mocks to functions is likely to 
return a mock -- even boolean functions.

Can you provide more context?

--

___
Python tracker 

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



[issue6598] calling email.utils.make_msgid frequently has a non-trivial probability of generating colliding ids

2015-11-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3c0a817ab616 by Serhiy Storchaka in branch '3.4':
Issue #6598: Avoid clock wrapping around in test_make_msgid_collisions.
https://hg.python.org/cpython/rev/3c0a817ab616

New changeset e259c0ab7a69 by Serhiy Storchaka in branch '3.5':
Issue #6598: Avoid clock wrapping around in test_make_msgid_collisions.
https://hg.python.org/cpython/rev/e259c0ab7a69

New changeset d1c11a78b43a by Serhiy Storchaka in branch 'default':
Issue #6598: Avoid clock wrapping around in test_make_msgid_collisions.
https://hg.python.org/cpython/rev/d1c11a78b43a

New changeset bdd257d60da2 by Serhiy Storchaka in branch '2.7':
Issue #6598: Avoid clock wrapping around in test_make_msgid_collisions.
https://hg.python.org/cpython/rev/bdd257d60da2

--

___
Python tracker 

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



[issue25594] enum docs outdated re attribute access

2015-11-10 Thread SilentGhost

SilentGhost added the comment:

Here is the test, it seems to have been 2545bfe0d273 that caused it 
(issue23486): test passes prior to it and fails on it (and I assume uniformly 
after).

--
keywords: +patch
Added file: http://bugs.python.org/file41003/test_issue25594.diff

___
Python tracker 

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



[issue25598] Fix memory_hex (#9951) for non-contiguous buffers

2015-11-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f3d8bb3ffa98 by Stefan Krah in branch '3.5':
Iaaue #25598: Fix memory_hex from #9951 for non-contiguous buffers.
https://hg.python.org/cpython/rev/f3d8bb3ffa98

--
nosy: +python-dev

___
Python tracker 

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



[issue9951] introduce bytes.hex method (also for bytearray and memoryview)

2015-11-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f3d8bb3ffa98 by Stefan Krah in branch '3.5':
Iaaue #25598: Fix memory_hex from #9951 for non-contiguous buffers.
https://hg.python.org/cpython/rev/f3d8bb3ffa98

--

___
Python tracker 

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



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread Theron Luhn

New submission from Theron Luhn:

>>> asyncio.iscoroutinefunction(unittest.mock.Mock())


This is an unexpected response, both in type (Mock rather than boolean) and 
value (truthy).

inspect.iscoroutinefunction behaves as expected.

Workaround:

>>> m = unittest.mock.Mock()
>>> m._is_coroutine = False
>>> asyncio.iscoroutinefunction(m)
False

--
components: asyncio
messages: 254457
nosy: Theron Luhn, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.iscoroutinefunction returns unexpected results when presented 
with unittest.mock.Mock
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote:

> > I have a problem with it: There is no feedback for the user about the
> > progress of the transfer, which can last several hours.
> > 
> > For small files shutil.copyfileobj() is a good idea, but not for huge
> > ones.
> 
> Indeed. Have a look at the source code:
> 
> def copyfileobj(fsrc, fdst, length=16*1024):
> """copy data from file-like object fsrc to file-like object fdst"""
> while 1:
> buf = fsrc.read(length)
> if not buf:
> break
> fdst.write(buf)
> 
> As simple as can be

Oooops - that's all?!


> I suggested the function as an alternative to writing 
> the loop yourself when your example code basically showed

Good idea :-)


> For the huge downloads that you intend to cater to you probably want your 
> script not just to print a dot on every iteration, you need expected 
> remaining time, checksums, ability to stop and resume a download and 
> whatnot.
> 
> Does the Perl code offer that?

Of course, yes. For download AND upload.



> Then why rewrite?

There is no more a Perl compiler for windows which supports https.



> Or are there Python libraries that do that out of the box?

No.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue6598] calling email.utils.make_msgid frequently has a non-trivial probability of generating colliding ids

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

http://buildbot.python.org/all/builders/x86%20Tiger%202.7/builds/3246/steps/test/logs/stdio
==
FAIL: test_make_msgid_collisions (email.test.test_email.TestMiscellaneous)
--
Traceback (most recent call last):
  File 
"/Users/db3l/buildarea/2.7.bolen-tiger/build/Lib/email/test/test_email.py", 
line 2434, in test_make_msgid_collisions
pass
  File "/Users/db3l/buildarea/2.7.bolen-tiger/build/Lib/contextlib.py", line 
24, in __exit__
self.gen.next()
  File "/Users/db3l/buildarea/2.7.bolen-tiger/build/Lib/test/test_support.py", 
line 1570, in start_threads
raise AssertionError('Unable to join %d threads' % len(started))
AssertionError: Unable to join 5 threads

--

Threads that should be finished for 3 seconds can't be finished for 15 minutes. 
It looks as clock() wrapped around. From clock (3) manpage:

Note that the time can wrap around.  On a 32-bit system where 
CLOCKS_PER_SEC equals 100 this function will return the same value 
approximately every 72 minutes.

The solution is to use monotonic() (time() on older releases) instead of 
clock().

--

___
Python tracker 

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



[issue25593] _sock_connect_cb can be called twice resulting in InvalidStateError

2015-11-10 Thread Guido van Rossum

Guido van Rossum added the comment:

Please show us how to repro -- there's no way we can figure out how this 
"impossible" event could happen in your code without understanding your code. 
Is it possible that multiprocessing forked your event loop or something 
similarly esoteric?

--

___
Python tracker 

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



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread STINNER Victor

STINNER Victor added the comment:

>>> asyncio.iscoroutinefunction(unittest.mock.Mock())


Yeah, I already had this issue when I wrote unit tests using mock :-/ I didn't 
find an obvious fix for this issue, and it's quite easy to workaround it.

It looks like the "m._is_coroutine = False" is not used in asyncio tests. I 
don't recall how I worked around the issue in asyncio tests...

--

___
Python tracker 

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



[issue24848] Warts in UTF-7 error handling

2015-11-10 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
resolution:  -> fixed
stage: patch 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



Re: using binary in python

2015-11-10 Thread kent nyberg
On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote:
> Your questions are somewhat difficult to answer because you misunderstand
> binary.  The key is that EVERYTHING in a computer is binary.  There are NO
> EXCEPTIONS, it's all binary ALL the time.  The difference comes about in how
> this binary data is displayed and manipulated.  I want to emphasize, ALL the
> DATA is binary.
> 

Thanks alot for taking the time.
I get it now. I sort of, but not fully, misunderstood the conecpt of binary 
files. 
The thing I was after; and the thing Im playing with now after a more 
succesfull time with google, 
is writing more specific things to a file than just strings.
English is not my native language so please forgive me, but
I wanted to write specifc 16bit codes, and read them. And later play with 
bitwise operations on them. Sort of.
It might not make sense at all, but hey..  it doesnt have to.
Thanks anyway. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using binary in python

2015-11-10 Thread mm0fmf via Python-list

On 10/11/2015 20:14, Dennis Lee Bieber wrote:

The Ada language defines the end of Text file to consist of


It is 15 years this month since I last worked in place that used Ada. I 
think that calls for a wee dram to celebrate ;-)

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


[issue25339] sys.stdout.errors is set to "surrogateescape"

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The default encoding of sys.stdio and sys.stdout is determined by (in order of 
increasing precedence):

1. locale
2. PYTHONIOENCODING
3. Py_SetStandardStreamEncoding()

The default error handler before 3.5 was determined by:

1. 'strict'
2. PYTHONIOENCODING
3. Py_SetStandardStreamEncoding()

The default error handler since 3.5 (issue19977) is determined by:

1. PYTHONIOENCODING
2. locale
3. Py_SetStandardStreamEncoding()

Even if you explicitly specified the error handler by PYTHONIOENCODING, it 
doesn't have effect in POSIX locale. This doesn't look right to me. I think the 
order should be the same as for encoding.

Proposed patch makes PYTHONIOENCODING to override locale default for error 
handler.

--
keywords: +patch
stage:  -> patch review
Added file: http://bugs.python.org/file41004/default_io_error_handle.patch

___
Python tracker 

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



[issue25594] enum instance attribute access possible

2015-11-10 Thread SilentGhost

Changes by SilentGhost :


--
components:  -Documentation
stage: test needed -> needs patch
title: enum docs outdated re attribute access -> enum instance attribute access 
possible

___
Python tracker 

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



Re: using binary in python

2015-11-10 Thread Mark Lawrence

On 10/11/2015 20:36, mm0fmf via Python-list wrote:

On 10/11/2015 20:14, Dennis Lee Bieber wrote:

The Ada language defines the end of Text file to consist of


It is 15 years this month since I last worked in place that used Ada. I
think that calls for a wee dram to celebrate ;-)


Followed by a chorus or two of the Ian Dury song about Ada to put the 
icing on the cake.


--
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: using binary in python

2015-11-10 Thread Random832
Dennis Lee Bieber  writes:
>   To be strict -- a text file has  system defined means of marking
> line endings. UNIX/Linux uses just a  character; Windows uses the pair
> . TRS-DOS used just  for end of line. Some operating systems
> may have used count-delimited formats (and then there is the VMS FORTRAN
> segmented records with start and end segment bits).

Another possibility would be fixed-length records. The ANSI C standard
permits a maximum line length (no less than 254) and for trailing spaces
to be ignored.

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


bitwise operator, bits dont go into bitbucket..?

2015-11-10 Thread kent nyberg
Im reading about bitwise operators and is it true to say they dont work 100% as 
in C?
bitwise operators in C seem to result in bits going to the so called bitbucket. 
For example, 0b0001. Shifting it >> 1  in C it seems to add on zero to the 
left and the 1 to the right gets throwned away.

But doing it in python just adds one more bit, from the left.  
That is, 0b0001 >> 1 = 0b1.

Bitwise operators in C (when reading examples,) gives some time code that check 
specific bits by
shifting the bits left and right to make every bit but the specific one to 
zeros. 
As I understand bitwise operators in python, this is not possible then?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using subprocess to capture a progress line

2015-11-10 Thread Chris Angelico
On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson  wrote:
> I've written a command-line "wrapper" for youtube-dl, executing
> youtube-dl as a subprocess.
>
> --
> youtube-dl reports download progress on one line. I.E. the line is
> overwritten numerous times with no carriage return until the
> downloading is finished.
> --
>

Sounds to me like a possible buffering problem. But since youtube-dl
is implemented in Python, you might find it easier to "pip install
youtube_dl" and work with the methods directly:

>>> import youtube_dl
>>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"])

Should be possible to manipulate around the outside of that.

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


Re: Using subprocess to capture a progress line

2015-11-10 Thread Tim Johnson
* Chris Angelico  [151110 14:35]:
> On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson  wrote:
> > I've written a command-line "wrapper" for youtube-dl, executing
> > youtube-dl as a subprocess.
> >
> > --
> > youtube-dl reports download progress on one line. I.E. the line is
> > overwritten numerous times with no carriage return until the
> > downloading is finished.
> > --
> >
> 
> Sounds to me like a possible buffering problem. But since youtube-dl
> is implemented in Python, you might find it easier to "pip install
> youtube_dl" and work with the methods directly:
> 
> >>> import youtube_dl
> >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"])

  Frankly, I'd prefer - in the long run - to use youtube_dl (the
  module).

  But, when I do as you have suggested (and have tried previously) I
  get the following:

  youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor

  I've briefly researched the error and so far haven't come up with an
  solution - guessing that other setup code is needed ...

  As for the buffering issue, at this point, I'll try  using a
  lower-level function like sys.stdout.write when the line 
  tests for '[download]' and 'ETA'.

  :) more elegant solutions welcome. I do intend to investigate
  using youtube_dl, once subprocess has been dealt with.

  thanks for the quick reply

-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

Wow this is tricky to get right. Victor, you are right to not trust 
TemporaryDirectory, because when cleanup() fails you don’t get a second chance, 
and it will leave the directory behind.

According to the Microsoft _mkdir() web page 
, Windows would raise 
ENOTEMPTY for removing the current directory. Maybe it is time to drop the 
win32 skip check as well?

Here is a patch based on aix_2.patch, but also removing the redundant win32 
skip. And “import errno” was no longer needed. I only tested it on Linux 
though, which supports removing the cwd.

--
Added file: http://bugs.python.org/file41005/test_deleted_cwd_aix_3.patch

___
Python tracker 

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



[issue25437] Issue with ftplib.FTP_TLS and server forcing SSL connection reuse

2015-11-10 Thread Stephen Ash

Changes by Stephen Ash :


--
nosy: +Stephen Ash

___
Python tracker 

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



Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Ben Finney
Pablo Lucena  writes:

> In order to keep the SSH session open and not have to re-establish it
> across function calls, I would like to do add an argument to
> "do_stuff" which can optionally return the SSH session along with the
> data returned from the SSH session, as follows:
>
> def do_stuff(device, return_handle=False):
> with manager(device) as conn:
> output = conn.send_command("show ip route")
> #process output...
> if return_handle:
> return (processed_output, conn)
> else:
> return processed_output

Since you're making it the caller's responsibility to deal with the
context manager, why not require the caller to *provide* the context
manager in the first place::

def do_stuff(conn):
""" Do stuff via the device connection `conn`.

:param conn: The context manager for the device connection.
:return: The processed output.

"""
with conn:
output = conn.send_command("show ip route")
#process output...
return processed_output

Also, note that if you just unconditionally want to return the output,
do it *outside* the ‘with’ block.

Then your caller is the one responsible for creating the connection
manager, and has the option of interrogating it further if it needs to::

bsu5000_conn = make_connection("bsu5000")
gen = do_stuff(bsu5000_conn)
do_more_things_with(bsu5000_conn)

-- 
 \   “I don't know anything about music. In my line you don't have |
  `\ to.” —Elvis Aaron Presley (1935–1977) |
_o__)  |
Ben Finney

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


Re: using binary in python

2015-11-10 Thread Random832
Dennis Lee Bieber  writes:
>   Given that a dram is 1/8 of a "fluid ounce" that leads to the
> conclusion that a "wee dram" is based on US standard fluid once,

29.6 ml

> vs British standard fluid ounce...

28.4 ml

It's our _pints_ that are smaller than yours, not our ounces.

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


OT: Re: using binary in python

2015-11-10 Thread mm0fmf via Python-list

On 10/11/2015 21:02, Dennis Lee Bieber wrote:

On Tue, 10 Nov 2015 20:36:52 +, mm0fmf via Python-list
 declaimed the following:


On 10/11/2015 20:14, Dennis Lee Bieber wrote:

The Ada language defines the end of Text file to consist of


It is 15 years this month since I last worked in place that used Ada. I
think that calls for a wee dram to celebrate ;-)


Given that a dram is 1/8 of a "fluid ounce" that leads to the
conclusion that a "wee dram" is based on US standard fluid once, vs British
standard fluid ounce...


My language preferences do tend to be the extremes: Python for quick
throw-away stuff, Ada for more formal stuff (since it has a much more
rigorous syntax than Pascal, Modula-2, C/C++, Java -- no optional block
delimiters, no dangling else, etc.)

Unfortunately, as a hobbyist dabbler at home, I can't justify the time
to port an Ada compiler to Arduino, TIVA, Propeller, Beaglebone (though the
latter may just be a case of porting the hardware access). So... I'm stuck
with variants of C for those devices (again, excluding the Linux based
Beaglebone)



I escaped having to produce new code in Ada, I merely had to run some 
scripts that added the compiled C binaries into the Ada gloop!


C user since 1983, C++ user since 2002, Python and C# since 2010. I 
regularly pinch myself that it seems to be painfully easy to be 
productive using Python compared to the other langauges!

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


[issue25558] Use static asserts in C code

2015-11-10 Thread STINNER Victor

STINNER Victor added the comment:

This issue can now be closed, no?

(I don't think that it's worth to add a new macro and make the existing macro 
more strict.)

--

___
Python tracker 

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



Re: bitwise operator, bits dont go into bitbucket..?

2015-11-10 Thread Chris Angelico
On Wed, Nov 11, 2015 at 9:27 AM, kent nyberg  wrote:
> Im reading about bitwise operators and is it true to say they dont work 100% 
> as in C?
> bitwise operators in C seem to result in bits going to the so called 
> bitbucket.
> For example, 0b0001. Shifting it >> 1  in C it seems to add on zero to 
> the left and the 1 to the right gets throwned away.
>
> But doing it in python just adds one more bit, from the left.
> That is, 0b0001 >> 1 = 0b1.

I'm not sure what you're expecting Python to do here, but
right-shifting the integer 1 results in the integer 0:

>>> 0b01 >> 1
0

> Bitwise operators in C (when reading examples,) gives some time code that 
> check specific bits by
> shifting the bits left and right to make every bit but the specific one to 
> zeros.
> As I understand bitwise operators in python, this is not possible then?

If you want to check specific bits (in C or Python, either way), it's
much more common to use bitwise AND than bit shifts:

>>> 0b100011011101010110 & 0b0001
16
>>> print(bin(_))
0b1

This will be either the same number as the right hand side (if the bit
had been set) or zero (if it hadn't).

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


Re: bitwise operator, bits dont go into bitbucket..?

2015-11-10 Thread kent nyberg
On Wed, Nov 11, 2015 at 09:33:38AM +1100, Chris Angelico wrote:
> On Wed, Nov 11, 2015 at 9:27 AM, kent nyberg  wrote:

> 
> If you want to check specific bits (in C or Python, either way), it's
> much more common to use bitwise AND than bit shifts:
> 
> >>> 0b100011011101010110 & 0b0001
> 16
> >>> print(bin(_))
> 0b1
> 

So, to check if 0b010[this one bit]010 is set,   i do   & 0b0001000

That is,  I set just that one to 1 in the other and then the & operator will 
make it return
0 if its not set. Since every other is zero, the return will be zero if its 
not. Since & operator sets 0
if not both are 1. Right?  

Id so, Thanks.   

My misunderstanding was that
0b01000   (for example,) first could be shifted left. To become 0b1.
And then shifted right to become 0b1. 
The shifting would turn every other digit to 0 and leave only the wanted one 
untouched. 
That way, I could check if its 0 or 1.  If you understand my own logic of how 
it works.
But I got it wrong,  and I think I know how to do it with & operator.

> This will be either the same number as the right hand side (if the bit
> had been set) or zero (if it hadn't).
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Using subprocess to capture a progress line

2015-11-10 Thread Tim Johnson
Using python 2.7.6 on ubuntu 14.04 
The application in question is run with bash and gnome-terminal :

I've written a command-line "wrapper" for youtube-dl, executing
youtube-dl as a subprocess.

--
youtube-dl reports download progress on one line. I.E. the line is
overwritten numerous times with no carriage return until the
downloading is finished.
--

The following code runs the youtube-dl command and reports each line
as output by youtube-dl
###
p = subprocess.Popen(list(args), stderr=subprocess.STDOUT,
 stdout=subprocess.PIPE)
while True:
line = p.stdout.readline()
if not line:
break
tmp = line.strip()
print tmp
###

However this method not does show the download progress _until_ the
download is complete. 

To clarify : follows is output from my app running youtube-dl.
I've annotated the line in question with '###'

[youtube] ZIgnHPqp0Dk: Downloading webpage
[youtube] ZIgnHPqp0Dk: Downloading video info webpage
[youtube] ZIgnHPqp0Dk: Extracting video information
[youtube] ZIgnHPqp0Dk: Downloading js player en_US-vfljDEtYP
[youtube] ZIgnHPqp0Dk: Downloading DASH manifest
[download] Destination: Someday Soon - Judy Collins 1969.avi.m4a
### the line below is not seen until download is finished.
[download] 100% of 7.58MiB in 00:12.85KiB/s ETA 00:00
[ffmpeg] Correcting container in "Someday Soon - Judy Collins 1969.avi.m4a"
[ffmpeg] Destination: Someday Soon - Judy Collins 1969.avi.mp3
Deleting original file Someday Soon - Judy Collins 1969.avi.m4a (pass -k to 
keep)

Is there a way to code subprocess so the the progress is being
shown? In my case lines being output aren't being shown unless a
newline is sent, or so I understand it.

FYI : the need for this function in this case is trivial, but the
solution will be enlightening for me and have other uses, I'll bet.

thanks

-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25597] unittest.mock does not wrap dict objects correctly

2015-11-10 Thread R. David Murray

R. David Murray added the comment:

Looking at the source, it's not clear that wraps is supported for __ methods, 
despite what the documentation implies.  That is, MagicProxy doesn't seem to 
look at the wraps information.  I suspect it is doable, but it may be an 
enhancement request rather than a bug fix, I'm not sure.

--
nosy: +michael.foord, r.david.murray, rbcollins

___
Python tracker 

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



Re: Using subprocess to capture a progress line

2015-11-10 Thread Tim Johnson
* Tim Johnson  [151110 14:55]:
> * Chris Angelico  [151110 14:35]:
> > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson  wrote:
> > > I've written a command-line "wrapper" for youtube-dl, executing
> > > youtube-dl as a subprocess.
> > >
> > > --
> > > youtube-dl reports download progress on one line. I.E. the line is
> > > overwritten numerous times with no carriage return until the
> > > downloading is finished.
> > > --
> > >
> > 
> > Sounds to me like a possible buffering problem. But since youtube-dl
> > is implemented in Python, you might find it easier to "pip install
> > youtube_dl" and work with the methods directly:
> 
>   As for the buffering issue, at this point, I'll try  using a
>   lower-level function like sys.stdout.write when the line 
>   tests for '[download]' and 'ETA'.
That method doesn't work ... so far. Oh well.
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Keeping context-manager object alive through function calls

2015-11-10 Thread Pablo Lucena
I am running into a bit of an issue with keeping a context manager open
through function calls. Here is what I mean:

There is a context-manager defined in a module which I use to open SSH
connections to network devices. The "setup" code handles opening the SSH
sessions and handling any issues, and the teardown code deals with
gracefully closing the SSH session. I normally use it as follows:

from manager import manager
def do_stuff(device):
with manager(device) as conn:
output = conn.send_command("show ip route")
#process output...
return processed_output

In order to keep the SSH session open and not have to re-establish it
across function calls, I would like to do add an argument to "do_stuff"
which can optionally return the SSH session along with the data returned
from the SSH session, as follows:

def do_stuff(device, return_handle=False):
with manager(device) as conn:
output = conn.send_command("show ip route")
#process output...
if return_handle:
return (processed_output, conn)
else:
return processed_output


I would like to be able to call this function "do_stuff" from another
function, as follows, such that it signals to "do_stuff" that the SSH
handle should be returned along with the output.

def do_more_stuff(device):
data, conn = do_stuff(device, return_handle=True)
output = conn.send_command("show users")
#process output...
return processed_output

However the issue that I am running into is that the SSH session is closed,
due to the do_stuff function "returning" and triggering the teardown code
in the context-manager (which gracefully closes the SSH session).

I have tried converting "do_stuff" into a generator, such that its state is
suspended and perhaps causing the context-manager to stay open:

def do_stuff(device, return_handle=False):
with manager(device) as conn:
output = conn.send_command("show ip route")
#process output...
if return_handle:
yield (processed_output, conn)
else:
yield processed_output

And calling it as such:

def do_more_stuff(device):
gen = do_stuff(device, return_handle=True)
data, conn = next(gen)
output = conn.send_command("show users")
#process output...
return processed_output

However this approach does not seem to be working in my case, as the
context-manager gets closed, and I get back a closed socket.

Is there a better way to approach this problem? Maybe my generator needs
some more work...I think using a generator to hold state is the most
"obvious" way that comes to mind, but overall should I be looking into
another way of keeping the session open across function calls?

Thanks


-- 
*Pablo Lucena*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using binary in python

2015-11-10 Thread Random832
Dennis Lee Bieber  writes:
>
>   Given that a dram is 1/8 of a "fluid ounce" that leads to the
> conclusion that a "wee dram" is based on US standard fluid once,

29.6 ml

> vs British standard fluid ounce...

28.4 ml

It's our _pints_ that are smaller than yours, not our ounces.

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


Re: using binary in python

2015-11-10 Thread Michael Torrie
On 11/10/2015 02:29 PM, kent nyberg wrote:
> On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote:
>> Your questions are somewhat difficult to answer because you misunderstand
>> binary.  The key is that EVERYTHING in a computer is binary.  There are NO
>> EXCEPTIONS, it's all binary ALL the time.  The difference comes about in how
>> this binary data is displayed and manipulated.  I want to emphasize, ALL the
>> DATA is binary.
>>
> 
> Thanks alot for taking the time.
> I get it now. I sort of, but not fully, misunderstood the conecpt of binary 
> files. 
> The thing I was after; and the thing Im playing with now after a more 
> succesfull time with google, 
> is writing more specific things to a file than just strings.
> English is not my native language so please forgive me, but
> I wanted to write specifc 16bit codes, and read them. And later play with 
> bitwise operations on them. Sort of.
> It might not make sense at all, but hey..  it doesnt have to.
> Thanks anyway. :)

You're correct; it doesn't make that much sense.  If it were me I'd
write out my numbers in text format to the file. You can always read
them back in and covert them to a number.

Just a quick couple of notes on "binary" vs "text".  In the old days on
Windows, the difference between "binary" and "ascii" when it came to
file reading was simply the interpretation of the end-of-line marker.
Whenever you wrote out a \n, it got silently converted to two bytes,
0x0d 0x0a.  If you were trying to write a jpeg file, for example, this
would corrupt things as you well know.  In the Unix world, we never
worried about such things because the end-of-line marker was simple
0x0a.  It was never translated and never was expanded silently.  So when
it came to how we worked with files, there was no difference between
binary and ascii modes as far as the C library open() was concerned.

Now with Python 3, we now again do have to think about the distinction
between "text" and "binary" when working with files.  If we want to open
a text file, we have to open it while specifying the expected text
encoding, whether that is UTF-8, UCS-2, UTF-16, or some other old and
esoteric encoding.  That is to say when Python reads from a text file,
there is always going to be a decoding process going on where text file
bytes are read in, and then converted into unicode characters.  When
writing a text file out, unicode characters have to be encoded into a
series of bytes.  If Python knows what encoding we want, then it can do
this automatically as we write to the file.

In Python 3 opening a file for binary will read in raw bytes and you can
manipulate them however you wish.

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


[issue25594] enum docs outdated re attribute access

2015-11-10 Thread SilentGhost

New submission from SilentGhost:

In enum docs[0], there is a suggestion that the attribute access on members 
should raise an AttributeError:

>>> Color.red.blue
Traceback (most recent call last):
...
AttributeError: 'Color' object has no attribute 'blue'

which is demonstrably wrong in either 3.5 or 3.6. I presume that's a doc issue 
and I'd be glad to propose the patch as soon as someone more familiar with the 
module could confirm that.

[0] https://docs.python.org/3.6/library/enum.html#finer-points

--
assignee: docs@python
components: Documentation, Library (Lib)
messages: 254436
nosy: SilentGhost, barry, docs@python, eli.bendersky, ethan.furman
priority: normal
severity: normal
status: open
title: enum docs outdated re attribute access
versions: Python 3.5, Python 3.6

___
Python tracker 

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



Re: Calulation in lim (1 + 1 /n) ^n when n -> infinite

2015-11-10 Thread Salvatore DI DIO
Thank you very much Peter
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting response by email reply message

2015-11-10 Thread Laura Creighton
In a message of Mon, 09 Nov 2015 23:09:50 -0800, zljubi...@gmail.com writes:
>> If what you really need is a voting application, you can look at
>> https://github.com/mdipierro/evote  which the PSF uses for its elections.
>
>It is not a voting application (I will have more than yes/no answers).
>I just want to keep an example simple.
>
>Anyway, I will look into voting application you have suggested in order to see 
>the way how they do it. Thanks.

Their is no demand for 'yes/no answers' -- you can typically vote for
7 people out of 15 candidates for the board, for instance.  But, once
you get to the website you can serve up webpages, using web2py which
presents the voters with a webpage full of whatever you want to render,
including text boxes that let you do arbitrary submissions.

The hard problem being solved here is that only a select list of people
(whom you reach through email) can vote, 
they can do so during some arbitrary period of time (your election period) 
but they do not have to all be on-line at the same time, 
everybody who is legally allowed to vote can change their minds about whom
to vote for and re-submit a vote again, invalidating the earlier one,
and anonymity -- even the election commissioner who holds the election 
does not know who it was that any voter voted for, only that they voted.

And it also keeps track of vote totals.  There are also things to enable
you to present the candidates in different orders for different sets
of voters, as the order in which a list is dished up seems to effect the
outcome, with implications for 'election fairness'.

Thus the whole app is about accountablity.  The tiny web page you serve
up to the people is a tiny bag you bolt into its side. :)  Which makes
the whole thing way, way, way to heavy-weight for most purposes.

However, if accountability is what you need, then it would probably
be easier to adapt the election app to do what you want then to
reinvent all this stuff.

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


Re: Extracting and summing student scores from a JSON file using Python 2.7.10

2015-11-10 Thread Pete Dowdell

On 10/11/15 08:12, Bernie Lazlo wrote:

> > import json
> >import urllib
> >url ="http://www.wickson.net/geography_assignment.json;
> >response = urllib.urlopen(url)
> >data = json.loads(response.read())


All good up to data. Now:
# make a list of scores
scores = [d['score'] for d in data['comments']  if 
isinstance(d['score'], int) ]

# analysis
total_scores = sum(scores)
average_score= total_scores/float(len(scores))
min_score, max_score = min(scores), max(scores)

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


Re: Getting response by email reply message

2015-11-10 Thread Laura Creighton
In a message of Tue, 10 Nov 2015 11:23:21 +0100, Laura Creighton writes:
>Their is no demand for 'yes/no answers' -- you can typically vote for

s/Their/There/

...

>the whole thing way, way, way to heavy-weight for most purposes.

s/to/too/
also s/heavy-weight/heavyweight/ depending on where in the world you
live, out of scope for this correction.

Sorry about that.  I need more caffeine.

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


[issue25586] socket.sendall broken when a socket has a timeout

2015-11-10 Thread Jakub Stasiak

Jakub Stasiak added the comment:

That's fair and thanks for the links.

Please find a quick patch attached, feel free to use that or any modification 
of it. While I believe the documentation is technically correct right now it 
won't hurt to clarify this I think.

--
keywords: +patch
Added file: http://bugs.python.org/file40994/socket-docs.patch

___
Python tracker 

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



Re: Question about math.pi is mutable

2015-11-10 Thread Antoon Pardon
Op 10-11-15 om 00:29 schreef Ben Finney:
>
> Who is doing what to whom? The user of the library isn't doing anything
> to the library author, so what is it the library author would consent
> to? Instead, you seem to be trying to assert a *power* of the library
> author to restrict the library user. Such a power is not granted by
> Python.

Python is not at liberty to grant or deny such a power. Python is just
a vehicle in which code is written. The author of a library can restrict
its use anyway he sees fit.

> Instead, the library author is obliged to treat the library user as an
> adult who consents to the freedoms inherent to Python's design, and to
> not restrict their use of the library needlessly.

There is no such obligation. And if it was an obligation, you can hardly
talk about consenting. Consenting adults mean that either party can
decide on conditions. Once one party is obligated it is no longer consenting.

-- 
Antoon Pardon

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


Re: Question about math.pi is mutable

2015-11-10 Thread Laura Creighton
In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes:
>Steven D'Aprano  writes:
>
>> Ben, I fear that you are not paying attention to me :-)
>
>Possibly, though I also think there's miscommunication in this thread.
>
>You speak of “compile time” and “run time”. You also speak of what the
>compiler can do, at run time.
>
>I am a Bear of Little Brain, but: Isn't anything that the *compiler*
>does, by definition done at *compile* time?

No.

We used to have a pretty strict defintion about what a compiler was, and
what an interpreter was.  You did the compile things at compile time,
and then you the the interpreter things at runtime.

No more.  We have Just in Time compilers.  They do their compiling
at run time.  Or perhaps 'there is no such thing as compile time
any more'.

Laura

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


Re: help in pexpect multiprocessing

2015-11-10 Thread harirammanohar159
On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm...@gmail.com  wrote:
> Hi,
> 
> I am using multiprocessing with pexpect, issue is whenever i call a function 
> which is having expect(), its throwing error which is genuine as multiple 
> threads are processing it same time (i/o prompt same time by multiple 
> processes..so issues in picture...), so i want to use lock for that section 
> alone to avoid it, but still fails in implementing it...can you help me
> 
> username = input('Enter your username: ')
> password = getpass.getpass()
> 
> s = pxssh.pxssh()
> s.login ('host','username','password')
> s.sendline ('ps -ef|grep java')
> s.prompt(timeout=1)
> 
> Try 1:
> 
> if condition == 'met':
>np = len(list1)
>p = multiprocessing.Pool(np)
>p.map(stop, [(ds) for ds in list1])
> 
> def stop(ds):
> s.sendline ('cd /usr')
> if condition:
> lock = threading.Lock()
> lock.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> lock.release()
> s.prompt(timeout=200)
> print('stopped ds...')
> 
> Try 2:
> 
> if condition == 'met':
> lock = Lock()
> for ds in list1:
> Process(target=stop, args=(ds,lock)).start()
> 
> def stop(ds,l):
> s.sendline ('cd /usr')
> if condition:
> l.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> l.release()
> s.prompt(timeout=200)
> print('stopped ds...')
> 
> Both are giving me same trace..
> 
> pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" 
> is 0, but there was no child process. Did someone else call waitpid() on our 
> process?
> 
> Thanks in Advance

Hi,

can any one check it out
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-10 Thread Terry Reedy

On 11/9/2015 9:37 PM, Steven D'Aprano wrote:


The compiler doesn't need to decide *in advance* whether the attribute might
have changed. It knows whether it has changed or not *at runtime*.


You are using 'compiler' when you should, to avoid confusion, use 
'interpreter'.



It's one thing to say that *in principle* any function might modify or
shadow builtins. That's true, because we don't know what's inside the
function. But the compiler knows, because it actually executes the code


'interpreter'


inside the function and can see what happens when it does. It doesn't have
to predict in advance whether or not calling `func(x)` shadows the builtin
`len` function, *it can see for itself* whether it did or not.

At compile time, `func(x)` might do anything. But at runtime, we know
exactly what it did, because it just did it.

Imagine that the compiler keeps track of whether or not builtins has been


/compiler/code compiled by the compiler and interpreted by the 
interpreter (which could be the CPU)/



modified. Think of it as a simple "dirty" flag that says "yes, builtins is
still pristine" or "no, something may have shadowed or modified the
builtins". That's fairly straight-forward: builtins is a dict, and the
compiler can tell whether or not __setitem__ etc has been called on that
dict. Likewise, it can keep track of whether or not a global has been
created that shadows builtins: some of that can be done statically, at
compile-time, but most of it needs to be done dynamically, at runtime.


This is more or less Victor Stinner's proposal, and he has a working 
prototype that runs nearly all the test suite.  He now plans to refine 
it and measure changes in space and time usage.



If the flag is set, the compiler knows that the optimization is unsafe and
it has to follow the standard name lookup, and you lose nothing: the
standard Python semantics are still followed. But if the flag is clear, the
compiler knows that nothing has shadowed or modified builtins, and a whole
class of optimizations are safe. It can replace a call to (say) len(x) with
a fast jump, avoiding an unnecessary name lookup in globals, and another
unnecessary name lookup in builtins. Or it might even inline the call to
len. Since *most* code doesn't play tricks with builtins, the overhead of
tracking these changes pays off *most* of the time -- and when it doesn't,
the penalty is very small.



--
Terry Jan Reedy

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


Re: Question about math.pi is mutable

2015-11-10 Thread Ben Finney
Laura Creighton  writes:

> In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes:
> >I am a Bear of Little Brain, but: Isn't anything that the *compiler*
> >does, by definition done at *compile* time?
>
> No.
>
> We used to have a pretty strict defintion about what a compiler was,
> and what an interpreter was. You did the compile things at compile
> time, and then you the the interpreter things at runtime.
>
> No more. We have Just in Time compilers. They do their compiling at
> run time. Or perhaps 'there is no such thing as compile time any
> more'.

Very well. I argued on the basis of what could be determined at the time
Steven refers to as “compile time”, i.e. before any part of the module
begins to run.


Steven D'Aprano  writes:

> Python -- yes, even CPython -- has a runtime compiler. When you import
> a module, it is compiled (if needed) just before the import. Likewise,
> when you call the `compile`, `eval` or `exec` built-ins, the compiler
> operates.
>
> I'm not calling this a JIT compiler, because the simple-minded
> compilation performed by `compile` etc doesn't use any run-time
> information. It just statically compiles the code to byte-code.

That's what I though. I'm aware of JIT compilers, and was pretty sure
Python doesn't have them. What's more, if it operates at a whole-module
level, and not later than when the module is imported.

Under those conditions, I maintain my objection to the proposed
optimisation.

The proposal is explicitly for optimisations made by the Python
compiler. As proposed, it only seems to be worthwhile once Python no
longer has a distinct “compiler” and “interpreter” is dissolved. Until
then, it seems pointless.

-- 
 \ “There is something wonderful in seeing a wrong-headed majority |
  `\   assailed by truth.” —John Kenneth Galbraith, 1989-07-28 |
_o__)  |
Ben Finney

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


Re: Extracting and summing student scores from a JSON file using Python 2.7.10

2015-11-10 Thread Bernie Lazlo
On Monday, 9 November 2015 22:54:05 UTC-5, wayne@gmail.com  wrote:
> On Monday, 9 November 2015 22:27:40 UTC-5, Denis McMahon  wrote:
> > On Mon, 09 Nov 2015 15:52:45 -0800, Bernie Lazlo wrote:
> > 
> > > This should be a simple problem but I have wasted hours on it. Any help
> > > would be appreciated. [I have taken my code back to almost the very
> > > beginning.]
> > > 
> > > The student scores need to be summed.
> > > 
> > > import json import urllib url =
> > > "http://www.wickson.net/geography_assignment.json;
> > > response = urllib.urlopen(url)
> > > data = json.loads(response.read())
> > > lst1 = list(data.items())
> > > print lst1
> > 
> > I find that pprint.pprint is useful for looking at data structures.
> > 
> > Having looked at the data, and then using appropriate substitutions for 
> >  and  in the following:
> > 
> > sumscore = 0
> > students = 0
> > 
> > for dic in :
> > sumscore = sumscore + dic[]
> > students += 1
> > 
> > print 'Sum of', students, 'scores is', sumscore
> > print 'Average of', students, 'scores is', sumscore / students
> > 
> > It was trivial to generate:
> > 
> > Sum of 50 scores is 3028
> > Average of 50 scores is 60
> > 
> > -- 
> > Denis McMahon
> =
Thanks for the reply, Denis. I hope this comes as easily to me some day. :-) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extracting and summing student scores from a JSON file using Python 2.7.10

2015-11-10 Thread Bernie Lazlo
On Monday, 9 November 2015 18:53:06 UTC-5, Bernie Lazlo  wrote:
> This should be a simple problem but I have wasted hours on it. Any help would 
> be appreciated. [I have taken my code back to almost the very beginning.]
> 
> The student scores need to be summed.
> 
> import json
> import urllib
> url = "http://www.wickson.net/geography_assignment.json;
> response = urllib.urlopen(url)
> data = json.loads(response.read())
> lst1 = list(data.items())
> print lst1

Pete, thanks for the input. Sometimes it just takes a suggestion to break past 
the "brick wall".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help in pexpect multiprocessing

2015-11-10 Thread harirammanohar159
On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm...@gmail.com  wrote:
> Hi,
> 
> I am using multiprocessing with pexpect, issue is whenever i call a function 
> which is having expect(), its throwing error which is genuine as multiple 
> threads are processing it same time (i/o prompt same time by multiple 
> processes..so issues in picture...), so i want to use lock for that section 
> alone to avoid it, but still fails in implementing it...can you help me
> 
> username = input('Enter your username: ')
> password = getpass.getpass()
> 
> s = pxssh.pxssh()
> s.login ('host','username','password')
> s.sendline ('ps -ef|grep java')
> s.prompt(timeout=1)
> 
> Try 1:
> 
> if condition == 'met':
>np = len(list1)
>p = multiprocessing.Pool(np)
>p.map(stop, [(ds) for ds in list1])
> 
> def stop(ds):
> s.sendline ('cd /usr')
> if condition:
> lock = threading.Lock()
> lock.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> lock.release()
> s.prompt(timeout=200)
> print('stopped ds...')
> 
> Try 2:
> 
> if condition == 'met':
> lock = Lock()
> for ds in list1:
> Process(target=stop, args=(ds,lock)).start()
> 
> def stop(ds,l):
> s.sendline ('cd /usr')
> if condition:
> l.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> l.release()
> s.prompt(timeout=200)
> print('stopped ds...')
> 
> Both are giving me same trace..
> 
> pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" 
> is 0, but there was no child process. Did someone else call waitpid() on our 
> process?
> 
> Thanks in Advance

Hi,

I am able to manage it by using process queues, thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help in pexpect multiprocessing

2015-11-10 Thread Pablo Lucena
I think the problem is that you cannot pass around an open socket via
pickle. Whats the error message you are getting?

Try adding the session establishment code to the stop function, so that
each new process opens a session to the server and executes the command.

def stop(ds):
s = pxssh.pxssh()
​​
s.login ('host','username','password')
s.sendline ('ps -ef|grep java')
s.prompt(timeout=1)
s.sendline ('cd /usr')
if condition:
lock = threading.Lock()
lock.acquire()
s.expect('Enter username:')
s.sendline ('user')
s.expect('Enter password:*')
s.sendline('pass')
lock.release()
s.prompt(timeout=200)
print('stopped ds...')


if condition == 'met':
   np = len(list1)
   p = multiprocessing.Pool(np)
   p.map(stop, [(ds) for ds in list1])

On Mon, Nov 9, 2015 at 7:37 AM,  wrote:

> Hi,
>
> I am using multiprocessing with pexpect, issue is whenever i call a
> function which is having expect(), its throwing error which is genuine as
> multiple threads are processing it same time (i/o prompt same time by
> multiple processes..so issues in picture...), so i want to use lock for
> that section alone to avoid it, but still fails in implementing it...can
> you help me
>
> username = input('Enter your username: ')
> password = getpass.getpass()
>
> s = pxssh.pxssh()
> s.login ('host','username','password')
> s.sendline ('ps -ef|grep java')
> s.prompt(timeout=1)
>
> Try 1:
>
> if condition == 'met':
>np = len(list1)
>p = multiprocessing.Pool(np)
>p.map(stop, [(ds) for ds in list1])
>
> def stop(ds):
> s.sendline ('cd /usr')
> if condition:
> lock = threading.Lock()
> lock.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> lock.release()
> s.prompt(timeout=200)
> print('stopped ds...')
>
> Try 2:
>
> if condition == 'met':
> lock = Lock()
> for ds in list1:
> Process(target=stop, args=(ds,lock)).start()
>
> def stop(ds,l):
> s.sendline ('cd /usr')
> if condition:
> l.acquire()
> s.expect('Enter username:')
> s.sendline ('user')
> s.expect('Enter password:*')
> s.sendline('pass')
> l.release()
> s.prompt(timeout=200)
> print('stopped ds...')
>
> Both are giving me same trace..
>
> pexpect.ExceptionPexpect: isalive() encountered condition where
> "terminated" is 0, but there was no child process. Did someone else call
> waitpid() on our process?
>
> Thanks in Advance
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
*Pablo Lucena*
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Victor for your review. Here is fixed patch that implements your 
suggestions.

--
Added file: http://bugs.python.org/file40997/test_deleted_cwd_aix_2.patch

___
Python tracker 

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



[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

And here is simple alternative patch based on Martin's original suggestion in 
msg236122.

--
Added file: http://bugs.python.org/file40998/test_deleted_cwd_aix_alt.patch

___
Python tracker 

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



Re: Using subprocess to capture a progress line

2015-11-10 Thread Tim Johnson
* Tim Johnson  [151110 14:55]:
> * Chris Angelico  [151110 14:35]:
> > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson  wrote:
> > > I've written a command-line "wrapper" for youtube-dl, executing
> > is implemented in Python, you might find it easier to "pip install
> > youtube_dl" and work with the methods directly:
<<...> > 
> > >>> import youtube_dl
> > >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"])
> 
>   Frankly, I'd prefer - in the long run - to use youtube_dl (the
>   module).
> 
>   But, when I do as you have suggested (and have tried previously) I
>   get the following:
> 
>   youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor
> 
It looks as if the developers are constantly upgrading. I just
upgraded youtube_dl

sudo pip install --upgrade youtube_dl

And ran the code which is provided under the topic 
"EMBEDDING YOUTUBE-DL"
at 
https://github.com/rg3/youtube-dl/blob/master/README.md

At I got a successful download, AFAICS
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Swig + Numpy.i with a const int16_t pointer

2015-11-10 Thread shriphanip
I am trying to wrap the following function with SWIG so I can call it from 
Python. The signature is:

```
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, 
size_t frame_length);
```

I have the following SWIG file: 
https://gist.github.com/shriphani/92c587ea4c32bafc9d97

At the end of this, I get the following error: webrtc_vad.i:22: Warning 453: 
Can't apply (int16_t const *IN_ARRAY1,unsigned int DIM1). No typemaps are 
defined.

If I drop the unsigned bit in the signature, then it compiles fine but the 
function signature is carried as-is (i.e. the function expects an int pointer 
and all that business).

Does anyone have a solution?

Regards,
Shriphani
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2015 11:14 pm, Ben Finney wrote:

>> Python -- yes, even CPython -- has a runtime compiler. When you import
>> a module, it is compiled (if needed) just before the import. Likewise,
>> when you call the `compile`, `eval` or `exec` built-ins, the compiler
>> operates.
>>
>> I'm not calling this a JIT compiler, because the simple-minded
>> compilation performed by `compile` etc doesn't use any run-time
>> information. It just statically compiles the code to byte-code.
> 
> That's what I though. I'm aware of JIT compilers, and was pretty sure
> Python doesn't have them. 

What do you think PyPy is then?

CPython is intentionally a pretty simple-minded compiler. Even no-brainer
constant folding is mildly controversial among some Python devs. But
CPython isn't "Python", it is just the reference implementation. Nuitka
aims to be an optimized AOT (Ahead Of Time) Python compiler, and PyPy is
already a state of the art (if not cutting edge) JIT Python compiler.

And if Victor Skinner's experimental FAT Python works out, even CPython
itself will gain some simple JIT techniques, rather similar to what Psycho
was doing ten years ago.


> What's more, if it operates at a whole-module 
> level, and not later than when the module is imported.

Now you're getting into implementation details of the JIT compiler. Can it
track entities across modules? How exactly does it operate?

PyPy is a "tracing JIT", which (if I have understood correctly) means it
actually analyses the code as it runs, using knowledge gained at runtime to
dynamically decide what to compile. This means that PyPy is best suited to
code that has long-running loops, and not well suited to scripts that don't
run for a long time. But another (hypothetical) JIT compiler might be more
like Psycho.


> Under those conditions, I maintain my objection to the proposed
> optimisation.
> 
> The proposal is explicitly for optimisations made by the Python
> compiler. As proposed, it only seems to be worthwhile once Python no
> longer has a distinct “compiler” and “interpreter” is dissolved. Until
> then, it seems pointless.

Python has not had a distinct "compiler" and "interpreter" since about
version 0.1. The execution module of Python as a dynamic byte-code
compiled, interpreted language with eval and exec *depends* on the compiler
being available during the execution phase, i.e. at runtime.

Some of the things I've suggested already exist, and have proven that they
work: Psycho and PyPy, to say nothing of similar technologies for other
equally dynamic languages such as Javascript and Smalltalk. Others are
state of the art compiler techniques -- they might not have been applied to
*Python* but that's only because nobody has got around to it, not because
it can't be done.

I daresay that there are implementation challenges to making Python faster
than it is without compromising on the semantics of the language, but there
is nothing fundamentally impossible about the idea.

Ben, I know that the IT crowd is rather conservative, and the Python
community even more so, but at the point where you are denying the
possibility of technologies which *already exist* I think that things have
got a bit out of hand. It's a bit like somebody getting on Twitter to
tweet "A globally interconnected communication network allowing computers
all over the world to communicate? Impossible! And even if it were
possible, nobody would use it."

;-)

 

-- 
Steven

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


[issue25590] tab-completition on instances repeatedly accesses attribute/descriptors values

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

getattr-once.patch handles my first two points. It backports the set() change, 
and avoids the hasattr() check. I guess we apply this to 3.4+; expect merge 
conflicts with 3.6.

As for the last point, I will make another patch to include special attributes 
that don’t actually exist yet, where they are currently omitted. Would we 
consider this a new feature for 3.6? Going by Serhiy’s logic in 
 I would say yes.

--
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file41006/getattr-once.patch

___
Python tracker 

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



[issue25586] socket.sendall broken when a socket has a timeout

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

That was kind of what I had in mind. The only change I would make is to restore 
the comma to “On error (including socket timeout), an exception . . .”. I’ll 
try to commit this in a few days if nobody has anything else to say.

--
stage:  -> patch review

___
Python tracker 

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



IDLE quits unexpectedly when about to open or creat a new file

2015-11-10 Thread trindadegoncalves
Hello,

I need help to find out what's going on. I did some research, but I couldn't 
find anything to solve this problem:

- I open the IDLE program;
- I go to the 'File' menu;
- I select the 'New File' option
- IDLE quits.

I run the IDLE version 3.3.3 on Windows 8.1 Pro.
Should I install the most recent version?

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


[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

test_deleted_cwd in test_importlib is failed on AIX.

http://buildbot.python.org/all/builders/PPC64%20AIX%203.x/builds/4318/steps/test/logs/stdio
==
ERROR: test_deleted_cwd 
(test.test_importlib.import_.test_path.Source_FinderTests)
--
Traceback (most recent call last):
  File 
"/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/test/test_importlib/import_/test_path.py",
 line 169, in test_deleted_cwd
os.chdir(path)
  File 
"/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/tempfile.py", 
line 807, in __exit__
self.cleanup()
  File 
"/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/tempfile.py", 
line 811, in cleanup
_shutil.rmtree(self.name)
  File 
"/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/shutil.py", 
line 478, in rmtree
onerror(os.rmdir, path, sys.exc_info())
  File 
"/home/shager/cpython-buildarea/3.x.edelsohn-aix-ppc64/build/Lib/shutil.py", 
line 476, in rmtree
os.rmdir(path)
OSError: [Errno 16] Device busy: '/tmp/tmp2xdxtq6x'

--

Proposed patch fixes the test. It also uses more verbose wording to create and 
remove temporary directory to be sure that caught exception was written by 
removing the directory, not by creating or changing CWD.

See also issue22834.

--
components: Tests
files: test_deleted_cwd_aix.patch
keywords: patch
messages: 254438
nosy: David.Edelsohn, brett.cannon, martin.panter, serhiy.storchaka, zach.ware
priority: normal
severity: normal
stage: patch review
status: open
title: test_deleted_cwd in test_importlib is failed on AIX
type: behavior
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file40995/test_deleted_cwd_aix.patch

___
Python tracker 

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



Re: IDLE quits unexpectedly when about to open or creat a new file

2015-11-10 Thread Chris Angelico
On Tue, Nov 10, 2015 at 9:46 PM,   wrote:
> I need help to find out what's going on. I did some research, but I couldn't 
> find anything to solve this problem:
>
> - I open the IDLE program;
> - I go to the 'File' menu;
> - I select the 'New File' option
> - IDLE quits.
>
> I run the IDLE version 3.3.3 on Windows 8.1 Pro.
> Should I install the most recent version?
>

That sounds like a very interesting problem. Can you try running it
from the command line, please? I'm not sure how to open one up from
Win 8, but it should be in the Start menu somewhere, or possibly press
Windows+R and type "cmd". With that up, type this:

python -m idlelib.idle

That should open up the same IDLE window that you know and recognize.
Do the exact same thing that caused the unexpected termination, and
then you should go back to the command prompt - hopefully with some
sort of error message. Copy and paste that message (as text, please,
not an image) into an email; that information could be very helpful.

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


[issue25596] regular files handled as directories in the glob module

2015-11-10 Thread Xavier de Gaye

New submission from Xavier de Gaye:

The glob module happily joins names of regular files together with 
os.path.join() or attempts to list the files contained into a regular file 
(sic). The same 'except os.error' statement is used to handle both these cases 
and the case of a non readable directory.

The attached patch makes the code more correct and easier to understand.

--
components: Library (Lib)
files: glob_isdir.patch
keywords: patch
messages: 254440
nosy: xdegaye
priority: normal
severity: normal
status: open
title: regular files handled as directories in the glob module
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file40996/glob_isdir.patch

___
Python tracker 

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



[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-10 Thread Xavier de Gaye

Xavier de Gaye added the comment:

New issue 25596 entered: regular files handled as directories in the glob 
module.

Thanks for fixing this Serhiy.

--

___
Python tracker 

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



[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread STINNER Victor

STINNER Victor added the comment:

-1, review on Rietveld.

--
nosy: +haypo

___
Python tracker 

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



Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> Ben, I fear that you are not paying attention to me :-)
> 
> Possibly, though I also think there's miscommunication in this thread.
> 
> You speak of “compile time” and “run time”. You also speak of what the
> compiler can do, at run time.
> 
> I am a Bear of Little Brain, but: Isn't anything that the *compiler*
> does, by definition done at *compile* time?

In a manner of speaking, yes, of course. But you've missed the critical
issue: when is compile time?

If you're like most people, you probably are thinking about an execution
model where the compiler analyses the source code statically, using nothing
but what can be seen in the source code, then hands over some sort of
compiled byte code to be run by an interpreter or machine code that is
executed by the CPU. The compiler and interpreter are completely distinct.

If so, you're stuck with an obsolete model of computation, like somebody
trying to understand modern chemistry based on the "planetary orbit" model
of the atom.

So when is compile time? Of course, in some languages (like C, or Pascal)
compilation occurs as a distinct stage before you can run the code. But
that's not necessarily true for all compilers. "Just In Time" compilers
operate while the program is running, compiling code just before it is
executed. The distinction between compiler and interpreter is gone, or at
least weakened.

Python -- yes, even CPython -- has a runtime compiler. When you import a
module, it is compiled (if needed) just before the import. Likewise, when
you call the `compile`, `eval` or `exec` built-ins, the compiler operates.

I'm not calling this a JIT compiler, because the simple-minded compilation
performed by `compile` etc doesn't use any run-time information. It just
statically compiles the code to byte-code.

But the fact that it happens *at runtime* is significant, because in
principle there is a lot more information available to the compiler, if it
were intelligent enough to make use of it. For example, suppose you execute
this Python snippet:

result = x + 2

At static compile time, looking just at the source, you may not know what
value x is, or even whether or not x actually exists, so you're forced to
go through the standard Python semantics to determine what the result is:

py> from dis import dis
py> dis("result = x + 1")
  1   0 LOAD_NAME0 (x)
  3 LOAD_CONST   0 (1)
  6 BINARY_ADD
  7 STORE_NAME   1 (result)
 10 LOAD_CONST   1 (None)
 13 RETURN_VALUE


But a JIT compiler gets to compile code right before that line is due to
execute. By the time the JIT compiler gets to see that line of code, it can
already know whether or not name "x" exists, and if so, which namespace it
is in. It knows what value "x" has. The compiler can choose what byte code,
or even machine code, to generate, using information available just before
that code is needed.

Suppose it knows that "x" is bound to an float. Then it can cast the int 1
to the machine floating point double 1.0 and generate code that adds that
to a float. That's likely to be tens of times faster than the BINARY_ADD
op-code, which has to do a whole lot of type-checking, method calling, and
creating and disposing of objects to add the two values.

Only if "x" is unknown, or if it is some type that doesn't have a convenient
optimization, does the JIT compiler generate the standard (but unoptimized)
BINARY_ADD op-code.

Provided that, on average, the book-keeping needed by the JIT compiler is
outweighed by the gains, the whole process counts as a win.

Now, CPython doesn't include a JIT compiler. But PyPy does, and it is much
more sophisticated than anything I could explain. I'm not the only one:

https://glyph.twistedmatrix.com/2012/02/this-isnt-how-pypy-works-but-it-might.html

If you remember Psycho, that might help. Psycho (according to its creator)
isn't a "true" JIT compiler, but it's close enough. Psycho would generate
machine code -- actual low level code running in the CPU or FPU, not byte
code -- for certain Python operations, plus guard code that ensured the
machine code was only called when it was safe to do so. So this is long
proven technology.

More about JIT compilation on Wikipedia:

https://en.wikipedia.org/wiki/Just-in-time_compilation



-- 
Steven

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


Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Steven D'Aprano
On Wednesday 11 November 2015 09:36, Pablo Lucena wrote:

> I am running into a bit of an issue with keeping a context manager open
> through function calls. Here is what I mean:
[...]
> In order to keep the SSH session open and not have to re-establish it
> across function calls, I would like to do add an argument to "do_stuff"
> which can optionally return the SSH session along with the data returned
> from the SSH session, as follows:

That won't work. The whole point of the "with" statement is to automatically 
close the context manager when you leave the with statement. If you don't 
want it automatically closed, *don't use with*.

There's nothing wrong with manually opening and closing the connection, if 
that's what you need. Open the ssh connection, pass it to your various 
functions, and close it only when you are done with it.

Or, and this might be a better solution, move the with block up a level. 
Instead of putting it in "do_stuff" and the assorted other functions, open 
the connection *before* you call these functions:


def main():
setup()
with manager(device) as conn:
do_stuff(conn)
do_more_stuff(conn)
do_even_more_stuff(conn)
# Now we're finally done.
sys.exit(0)



[...]
> I have tried converting "do_stuff" into a generator, such that its state
> is suspended and perhaps causing the context-manager to stay open:
[...]
> However this approach does not seem to be working in my case, as the
> context-manager gets closed, and I get back a closed socket.
> 
> Is there a better way to approach this problem? Maybe my generator needs
> some more work...I think using a generator to hold state is the most
> "obvious" way that comes to mind, but overall should I be looking into
> another way of keeping the session open across function calls?

You might be able to get some awful hack using generators working, but it 
will be ugly, confusing and fragile. This is a sign you are abusing the 
context manager and using it in a way that goes against the design of the 
feature. Consider some future maintainer (perhaps even yourself, in six 
months or a year), reading the code, and completely puzzled why the SSH 
connection isn't closed when the with block is exited.



-- 
Steve

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


[issue25600] argparse, argument_default=argparse.SUPPRESS seems to have no effect

2015-11-10 Thread mcer45

New submission from mcer45:

The parameter argument_default=argparse.SUPPRESS seems to have no effect.
Example:

=

help_dirs='ahoy

parser = argparse.ArgumentParser(
   formatter_class=argparse.RawDescriptionHelpFormatter,
   description='Makes the calendar for the "year"',
   epilog=textwrap.dedent(help_dirs))
parser.add_argument("user",  help='the user directory with the required
structure in ./')
parser.add_argument("year",  type=int,  help='the year for this calendar
and also the directory for the output')
parser.add_argument("-acc","--acc",
default='no',nargs='?',choices=['yes','no'],const='yes',
help='accomodate ratio according to the
cover photo, default=no')
parser.add_argument("--color",default='gold', choices=['gold'],
help='default color: gold')
args = parser.parse_args(['mc', '2015'])
print(args)
del parser
del args



parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS,
   formatter_class=argparse.RawDescriptionHelpFormatter,
   description='Makes the calendar for the "year"',
   epilog=textwrap.dedent(help_dirs))
parser.add_argument("user",  help='the user directory with the required
structure in ./')
parser.add_argument("year",  type=int,  help='the year for this calendar
and also the directory for the output')
parser.add_argument("-acc","--acc",
default='no',nargs='?',choices=['yes','no'],const='yes',
help='accomodate ratio according to the
cover photo, default=no')
parser.add_argument("--color",default='gold', choices=['gold'],
help='default color: gold')
args = parser.parse_args(['mc', '2015'])


===

The results in both cases are the  same:
Namespace(acc='no', color='gold', user='mc', year=2015)

I hoped the defaults will be suppressed.

--
components: Library (Lib)
messages: 254478
nosy: bethard, mcer45
priority: normal
severity: normal
status: open
title: argparse, argument_default=argparse.SUPPRESS seems to have no effect
type: behavior
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



Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Wednesday 11 November 2015 00:26, BartC wrote:

> Does the Python language specify how it is to be compiled and executed?

Not in so many words, but there are limitations on what you can do based on 
the specified semantics of Python.

But so long as you meet those semantics, you can implement them any 
reasonable way you like:

- CPython uses one specific implementation written in C;

- PyPy uses a powerful tracing JIT compiler written in an intermediate 
language RPython;

- IronPython uses the .Net CLR virtual machine;

- Jython uses the Java virtual machine;

- there was an experimental version of Python using the Parrot virtual 
machine;

etc. Those implementations will naturally perform differently. For example, 
I believe that IronPython *generally* is faster than CPython, with some 
exceptions.


> If not, then you can use any interpretation you like, provided the
> program gives the expected results.

Precisely.

> That includes using a static compilation pass that generates byte-code,
> even if it is only done immediately before running the main module, or
> just before performing an import operation on another.

That's what CPython already does.


> Anything is possible. But the chances are that if you are running
> CPython, then it will probably include a discrete byte-code compiler.

Since compile, eval and exec are Python built-ins, if it doesn't include a 
byte-code compiler, it isn't Python. It's just a subset of Python.



>> execute this Python snippet:
>>
>> result = x + 2
[...]
>> But a JIT compiler gets to compile code right before that line is due to
>> execute. By the time the JIT compiler gets to see that line of code, it
>> can already know whether or not name "x" exists, and if so, which
>> namespace it is in. It knows what value "x" has.
> 
> How does it do that? How is the 'x+1' even stored in the machine?

That depends entirely on the implementation of the compiler.


> Suppose the preceding lines are:
> 
> if random+bit()==1:
>x=920.5
> else:
>x=[8,5,4,9,1,7,6,3,2]
> 
> or:
> 
> if some_condition: del x
> 
> it will probably know as much about x as the static compiler does!

Not at all. The difference is, having called rand_bit() and tested whether 
it is 1, the compiler takes a branch:

- it binds 920.5 to x

- or it binds [8, 5, 4, ...] to x

The compiler knows which branch it just took, *because it just took it*. If 
it doesn't know which branch it just took, it isn't a JIT compiler! It's 
just a classic, old-fashioned interpreter with no smarts.

So, having just bound some value to x, the compiler knows that x is a float 
(or a list), and can optimize the next instruction, which is "x + 1".

CPython can't do that, because it doesn't have the infrastructure to perform 
the necessary book-keeping. And it probably never will do that, because 
Guido likes the fact that CPython is simple enough for him to understand. 
He's happy for PyPy and other third-party implementations to do the clever 
stuff.



-- 
Steven

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


[issue25590] tab-completition on instances repeatedly accesses attribute/descriptors values

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

uncreated-attr.patch is against the 3.6 branch, and includes the excessive 
getattr() test, and new code to include uncreated attribute names. I added a 
paragraph to What’s New describing the new completion behaviour.

--
Added file: http://bugs.python.org/file41007/uncreated-attr.patch

___
Python tracker 

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



[issue25590] tab-completition on instances repeatedly accesses attribute/descriptors values

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Both patches LGTM. Thank you Martin.

> Would we consider this a new feature for 3.6?

We can consider this a fix of the regression in issue449227. But this behavior 
here is so long. I agree with applying it to 3.6 only.

For nicer Mercurial history, it would be better to apply both patches 
separately in 3.6.

Would not be simpler to use uninitialized slot attribute in test_uncreated_attr?

--
assignee:  -> martin.panter
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



[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Martin's original code looked nicer to me. It' a pity we can't use it.

test_deleted_cwd_aix_3.patch LGTM. Thanks Martin!

--
assignee:  -> serhiy.storchaka

___
Python tracker 

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



[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d4dc36586f24 by Serhiy Storchaka in branch '3.5':
Issue #25595: Fixed test_deleted_cwd in test_importlib on AIX.
https://hg.python.org/cpython/rev/d4dc36586f24

New changeset 3f392050d519 by Serhiy Storchaka in branch 'default':
Issue #25595: Fixed test_deleted_cwd in test_importlib on AIX.
https://hg.python.org/cpython/rev/3f392050d519

--
nosy: +python-dev

___
Python tracker 

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



[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch 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



Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Chris Angelico
On Wed, Nov 11, 2015 at 9:36 AM, Pablo Lucena  wrote:
> And calling it as such:
>
> def do_more_stuff(device):
> gen = do_stuff(device, return_handle=True)
> data, conn = next(gen)
> output = conn.send_command("show users")
> #process output...
> return processed_output

The first question needs to be: When *is* conn to be closed? What
you've done here is abandon all of the benefit of the context manager,
because it's no longer clear when you're done with the connection.
Here's an alternative: Turn your generator into another context
manager.

from contextlib import contextmanager

@contextmanager
def do_stuff(device):
with manager(device) as conn:
output = conn.send_command("show ip route")
#process output...
yield (processed_output, conn)

def do_stuff_now(device):
with do_stuff(device) as (out, conn):
return out

This forces you to separate the return_handle=True and
return_handle=False modes into two separate functions, but since one
is defined in terms of the other, you don't have a massive maintenance
burden. (Backward compatibility might have you call the first one
do_stuff_with_handle and the second one gets the name do_stuff. Or
whatever names make sense. Handwave.)

So now you can use do_stuff_now() the way you were using do_stuff(),
and if you want to keep using the handle afterward, you use it like
this:

def do_more_stuff(device):
with do_stuff(device) as (data, conn):
output = conn.send_command("show users")
#process output...
return processed_output

This guarantees that the device will be closed as you depart do_more_stuff.

There are other ways, but this is an easy way to build context
managers on top of context managers.

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


Re: bitwise operator, bits dont go into bitbucket..?

2015-11-10 Thread Chris Angelico
On Wed, Nov 11, 2015 at 9:56 AM, kent nyberg  wrote:
> So, to check if 0b010[this one bit]010 is set,   i do   & 0b0001000
>
> That is,  I set just that one to 1 in the other and then the & operator will 
> make it return
> 0 if its not set. Since every other is zero, the return will be zero if its 
> not. Since & operator sets 0
> if not both are 1. Right?
>
> Id so, Thanks.

Exactly! It's common to have named constants for things that matter to
you; for example, you can find out if a file/directory is
world-writable like this:

>>> import stat
>>> os.stat("/").st_mode & stat.S_IWOTH
0
>>> os.stat("/tmp").st_mode & stat.S_IWOTH
2

So my root directory is not world writable (result of zero), and the
/tmp directory is. (This is not surprising.) The S_IWOTH constant is
simply the integer 2, but giving it a name makes it a bit easier to
see what's going on in the code. (Not that the name is abundantly
clear... it could be improved on. But it's better than just '2'.)

> My misunderstanding was that
> 0b01000   (for example,) first could be shifted left. To become 0b1.
> And then shifted right to become 0b1.
> The shifting would turn every other digit to 0 and leave only the wanted one 
> untouched.
> That way, I could check if its 0 or 1.  If you understand my own logic of how 
> it works.
> But I got it wrong,  and I think I know how to do it with & operator.

That's true of right shifting, but when you left shift, you're
depending on a specific word size. Even in C, it's possible to get
burned by that (eg when you move from 32-bit to 64-bit), and in
Python, integers have infinite size. If you definitely want that
behaviour, you can do this:

(0b01000 << 1) & 0b1

which will mask off your result to just five bits, giving you the
"drop the top bit" effect. But for bit testing and manipulation, it's
way easier to use AND/OR/XOR than shifts.

The one place you might want to use bit shifts is in _creating_ those
constants. For instance:

STYLE_FOO = 1 << 0
STYLE_BAR = 1 << 1
STYLE_BAZ = 1 << 2
STYLE_ABC = 1 << 3
STYLE_QWE = 1 << 4
STYLE_XYZ = 1 << 5

>From this table, it's obvious that they've been assigned successive
bits. You can do the same with an enumeration:

>>> class Style(enum.IntEnum):
... FOO = 1 << 0
... BAR = 1 << 1
... BAZ = 1 << 2
... ABC = 1 << 3
... QWE = 1 << 4
... XYZ = 1 << 5
...
>>> Style.BAR

>>> Style.QWE


And then you can test to see if some style was chosen:

>>> widget = Style.FOO | Style.QWE
>>> widget & Style.ABC
0
>>> widget & Style.QWE
16

Does that make things a bit easier to read?

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


[issue25498] Python 3.4.3 core dump with simple sample code

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Added new comments on Rietveld. Would be nice to add tests for read-only and 
non-contiguous buffers.

eryksun, what is your real name? What we have to add in the Misc/ACKS file?

--

___
Python tracker 

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



[issue24661] CGIHTTPServer: premature unescaping of query string

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

The CGI server no longer unquotes the query string thanks to the fix for Issue 
24657. The fix should be in the next (2.7.11) release.

--
nosy: +martin.panter
resolution:  -> out of date
stage:  -> resolved
status: open -> closed
superseder:  -> CGIHTTPServer module discard continuous '/' letters from params 
given by GET method.
type:  -> behavior
versions: +Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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



[issue25583] os.makedirs with exist_ok=True raises PermissionError on Windows 7^

2015-11-10 Thread Daniel Plachotich

Daniel Plachotich added the comment:

Yes, it's probably a better solution. If had been more careful, I wouldn't have 
scribbled so much text here :) .

But is there any sense in adding Windows-specific test with EACCES since the 
problem with errno may affect other platforms as well (at least in theory)? 
It's not a Windows-only issue.

--

___
Python tracker 

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



Re: Question about math.pi is mutable

2015-11-10 Thread BartC

On 10/11/2015 11:34, Steven D'Aprano wrote:

On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote:




I am a Bear of Little Brain, but: Isn't anything that the *compiler*
does, by definition done at *compile* time?


In a manner of speaking, yes, of course. But you've missed the critical
issue: when is compile time?

If you're like most people, you probably are thinking about an execution
model where the compiler analyses the source code statically, using nothing
but what can be seen in the source code, then hands over some sort of
compiled byte code to be run by an interpreter or machine code that is
executed by the CPU. The compiler and interpreter are completely distinct.


Does the Python language specify how it is to be compiled and executed?

If not, then you can use any interpretation you like, provided the 
program gives the expected results.


That includes using a static compilation pass that generates byte-code, 
even if it is only done immediately before running the main module, or 
just before performing an import operation on another.



If so, you're stuck with an obsolete model of computation, like somebody
trying to understand modern chemistry based on the "planetary orbit" model
of the atom.

So when is compile time? Of course, in some languages (like C, or Pascal)
compilation occurs as a distinct stage before you can run the code. But
that's not necessarily true for all compilers.


C can also be interpreted from source as you go along, although it can 
be very difficult (but probably not as difficult as implementing PyPy).


Anything is possible. But the chances are that if you are running 
CPython, then it will probably include a discrete byte-code compiler.



execute
this Python snippet:

result = x + 2

At static compile time, looking just at the source, you may not know what
value x is, or even whether or not x actually exists, so you're forced to
go through the standard Python semantics to determine what the result is:

py> from dis import dis
py> dis("result = x + 1")
   1   0 LOAD_NAME0 (x)
   3 LOAD_CONST   0 (1)
   6 BINARY_ADD
   7 STORE_NAME   1 (result)
  10 LOAD_CONST   1 (None)
  13 RETURN_VALUE


But a JIT compiler gets to compile code right before that line is due to
execute. By the time the JIT compiler gets to see that line of code, it can
already know whether or not name "x" exists, and if so, which namespace it
is in. It knows what value "x" has.


How does it do that? How is the 'x+1' even stored in the machine? 
Suppose the preceding lines are:


   if random+bit()==1:
  x=920.5
   else:
  x=[8,5,4,9,1,7,6,3,2]

or:

   if some_condition: del x

it will probably know as much about x as the static compiler does! And a 
static compiler can still do a surprising bit of analysis, such as 
transforming the the first if-statement above, followed by your return 
statement, into:


   if random_bit()==1:
  return 922.5
   else:
  raise_error()

But we're trying to find ways of avoiding a dictionary lookup, ie a 
LOAD_GLOBAL or LOAD_NAME. If static analysis of the entire source can 
yield fixed tables of such names as 'x', even if subject to runtime 
alterations, then why not do that if it means possible faster access.



More about JIT compilation on Wikipedia:

https://en.wikipedia.org/wiki/Just-in-time_compilation


JIT covers a lot including straightforward translation of byte-code for 
a statically language, into native code.


In a language like Python, it's rather more elaborate.

And PyPy, as you hinted, is complelely different. I don't think it even 
attempts to JIT compile your example, it JIT compiles some repeatedly 
executed pathways in a program some way removed from the Python code or 
even its interpreter.


Or something like that... Whatever it is, it's more like magic. But what 
I started discussing here are ways of making a regular Python 
interpreter more efficient. I think that with projects such as PyPy, 
people are less interested with speeding up CPython, for one thing 
because it is not going to speed things up by ten times, so there seems 
little point.


--
BartC


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


[issue25263] test_tkinter fails randomly on the buildbots "AMD64 Windows10" (3.4, 3.5, 3.x)

2015-11-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 385b3aaf8401 by Serhiy Storchaka in branch '3.4':
Issue #25263: Fixed the tkinter.test.test_tkinter.test_font.FontTest test
https://hg.python.org/cpython/rev/385b3aaf8401

New changeset db168611c6c8 by Serhiy Storchaka in branch '3.5':
Issue #25263: Fixed the tkinter.test.test_tkinter.test_font.FontTest test
https://hg.python.org/cpython/rev/db168611c6c8

New changeset 0632642c30dd by Serhiy Storchaka in branch 'default':
Issue #25263: Fixed the tkinter.test.test_tkinter.test_font.FontTest test
https://hg.python.org/cpython/rev/0632642c30dd

New changeset f81e357b2318 by Serhiy Storchaka in branch '2.7':
Issue #25263: Fixed the tkinter.test.test_tkinter.test_font.FontTest test
https://hg.python.org/cpython/rev/f81e357b2318

--

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote:

> if u.getcode() == 200:
>   print(u.read(),file=szo,end='')
>   szo.close()
> else:
>   die('cannot get %s - server reply: %d' % (szurl,u.getcode()))

More random remarks:

- print() gives the impression that you are dealing with text, and using it
  with binary strings will produce surprising results when you migrate to
  Python 3:

Python 2:

>>> from __future__ import print_function
>>> print(b"foo")
foo

Python 3:

>>> print(b"foo")
b'foo'

- with open(...) ensures that the file is closed when an exception occurs.
  It doesn't matter here as your script is going to die() anyway, but using
  with is a got habit to get into.
- consider shutil.copyfileobj to limit memory usage when dealing with data
  of arbitrary size.

Putting it together:

with open(sz, "wb") as szo:
shutil.copyfileobj(u, szo)



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


Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote:


> > It works with Linux, but not with Windows 7, where the downloaded 7za.exe
> > is corrupt: it has the wrong size, 589044 instead of 587776 Bytes.
> > 
> > Where is my error?
> 
> > sz = path.join(fexhome,'7za.exe')
> > szurl = "http://fex.belwue.de/download/7za.exe;
> > 
> >try:
> >   szo = open(sz,'w')
> 
> Open the file in binary mode to avoid the translation of "\n" into "\r\n":
> 
> szo = open(sz, 'wb')

Damn.. I should have known this!

Ok, now it works like on Linux. Windows is such a *BEEEP* *CENSORED*


> > except (IOError,OSError) as e:
> >   die('cannot write %s - %s' % (sz,e.strerror))
> 
> Unrelated, but I recommend that you let the exceptions bubble up for easier 
> debugging.

die() is my debugging function :-)


> Python is not Perl ;)

*sigh* This is the problem ;-)
I am a Perl programmer for more than 25 years... 

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
I am currently developing a program which should run on Linux and Windows.
Later it shall be compiled with PyInstaller. Therefore I am using Python 2.7

My program must download http://fex.belwue.de/download/7za.exe

I am using this code:

sz = path.join(fexhome,'7za.exe')
szurl = "http://fex.belwue.de/download/7za.exe;

   try:
  szo = open(sz,'w')
except (IOError,OSError) as e:
  die('cannot write %s - %s' % (sz,e.strerror))
import urllib2
printf("\ndownloading %s\n",szurl)
try:
  req = urllib2.Request(szurl)
  req.add_header('User-Agent',useragent)
  u = urllib2.urlopen(req)
except urllib2.URLError as e:
  die('cannot get %s - %s' % (szurl,e.reason))
except urllib2.HTTPError as e:
  die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
if u.getcode() == 200:
  print(u.read(),file=szo,end='')
  szo.close()
else:
  die('cannot get %s - server reply: %d' % (szurl,u.getcode()))

It works with Linux, but not with Windows 7, where the downloaded 7za.exe is
corrupt: it has the wrong size, 589044 instead of 587776 Bytes.

Where is my error?


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25595] test_deleted_cwd in test_importlib is failed on AIX

2015-11-10 Thread STINNER Victor

STINNER Victor added the comment:

test_deleted_cwd_aix_alt.patch: I don't trust tempfile.TemporaryDirectory(), I 
prefer your patch.

test_deleted_cwd_aix_2.patch looks good to me.

--

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Peter Otten
Ulli Horlacher wrote:

> I am currently developing a program which should run on Linux and Windows.
> Later it shall be compiled with PyInstaller. Therefore I am using Python
> 2.7
> 
> My program must download http://fex.belwue.de/download/7za.exe
> 
> I am using this code:

> It works with Linux, but not with Windows 7, where the downloaded 7za.exe
> is corrupt: it has the wrong size, 589044 instead of 587776 Bytes.
> 
> Where is my error?

> sz = path.join(fexhome,'7za.exe')
> szurl = "http://fex.belwue.de/download/7za.exe;
> 
>try:
>   szo = open(sz,'w')

Open the file in binary mode to avoid the translation of "\n" into "\r\n":

szo = open(sz, 'wb')

> except (IOError,OSError) as e:
>   die('cannot write %s - %s' % (sz,e.strerror))

Unrelated, but I recommend that you let the exceptions bubble up for easier 
debugging.

Python is not Perl ;)

> import urllib2
> printf("\ndownloading %s\n",szurl)
> try:
>   req = urllib2.Request(szurl)
>   req.add_header('User-Agent',useragent)
>   u = urllib2.urlopen(req)
> except urllib2.URLError as e:
>   die('cannot get %s - %s' % (szurl,e.reason))
> except urllib2.HTTPError as e:
>   die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
> if u.getcode() == 200:
>   print(u.read(),file=szo,end='')
>   szo.close()
> else:
>   die('cannot get %s - server reply: %d' % (szurl,u.getcode()))
> 


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


[issue25263] test_tkinter fails randomly on the buildbots "AMD64 Windows10" (3.4, 3.5, 3.x)

2015-11-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The other failure is not Windows specific. It can be reproduced if run test_tk 
twice. FontTest.setUpClass() incorrectly call parent's method and the root 
attribute is set in parent class. tearDownClass() sets the root attribute to 
None in child class, and this overrides parent's attribute. The test in the 
second run passes self.root (is None) to font.Font constructor, and this is 
interpreted as no the root argument passed.

--

___
Python tracker 

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



Re: corrupt download with urllib2

2015-11-10 Thread Ulli Horlacher
Peter Otten <__pete...@web.de> wrote:
> Ulli Horlacher wrote:
> 
> > if u.getcode() == 200:
> >   print(u.read(),file=szo,end='')
> >   szo.close()
> > else:
> >   die('cannot get %s - server reply: %d' % (szurl,u.getcode()))
> 
> More random remarks:

Always welcome - I am here to learn :-)


> - print() gives the impression that you are dealing with text, and using it
>   with binary strings will produce surprising results when you migrate to
>   Python 3:
> 
> Python 2:
> 
> >>> from __future__ import print_function

I already have this in my code, to make a later transition to Python 3
easier.


> >>> print(b"foo")
> foo
> 
> Python 3:
> 
> >>> print(b"foo")
> b'foo'

Bad.
Is there a better alternative to write arbitrary binary data?


> - with open(...) ensures that the file is closed when an exception occurs.
>   It doesn't matter here as your script is going to die() anyway, but using
>   with is a got habit to get into.

When an error occurs I do want to write more data, anyway.


> - consider shutil.copyfileobj to limit memory usage when dealing with data
>   of arbitrary size.
> 
> Putting it together:
> 
> with open(sz, "wb") as szo:
> shutil.copyfileobj(u, szo)

This writes the http stream binary to the file. without handling it
manually chunk by chunk?

Great. This would be my next task! You are answering my questions, before
I ask them! :-)

Background: I am rewriting my Perl program fexsend in Python.
fexsend transfers files up to TB range, see:
http://fex.rus.uni-stuttgart.de/



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25583] os.makedirs with exist_ok=True raises PermissionError on Windows 7^

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

It is good to add a regression test for any bug if it’s not too hard. Yes this 
is not a Windows-only issue, but I understand it is much simpler to produce 
with Windows. Otherwise you need a special file system setup and a more obscure 
OS.

Please review my patch. It would be good to confirm that the test fails on 
Windows if the fix is not applied. I have only tested this on Linux, and 
indirectly via Wine.

--
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file41008/makedirs-exist.patch

___
Python tracker 

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



Re: using binary in python

2015-11-10 Thread Larry Hudson via Python-list

On 11/10/2015 12:14 PM, Dennis Lee Bieber wrote:

On Mon, 9 Nov 2015 22:20:25 -0800, Larry Hudson via Python-list
 declaimed the following:


Of course it can.  The only difference a text file and a binary file is the way 
it's opened.
Text files are opened with 'r' or 'w', while binary files are opened with 'rb' 
or 'wb'.  Being
different modes, the reading/writing is handled differently.  One obvious 
difference, the lines
of a text file are marked by ending them with a newline character, so it's easy 
to read/write
the text line-by-line.  But the data in a binary file is completely arbitrary 
and is much


To be strict -- a text file has  system defined means of marking
line endings. UNIX/Linux uses just a  character; Windows uses the pair
. TRS-DOS used just  for end of line. Some operating systems
may have used count-delimited formats (and then there is the VMS FORTRAN
segmented records with start and end segment bits).

The main purpose of my message was to get across the idea of separating the actual data (as 
binary values) and the way this data is displayed (to the user/programmer).  They are two 
entirely different concepts, and the OP was obviously confused about this.  But of course, 
you're right -- I was careless/imprecise in some of my descriptions.


 -=- Larry -=-

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


[issue25498] Python 3.4.3 core dump with simple sample code

2015-11-10 Thread Martin Panter

Martin Panter added the comment:

I propose this patch, based on Eryksun’s patch (thanks Eryksun). New changes:

* Added test case
* Applied Serhiy’s review suggestion
* Changed the new BufferError exceptions back to TypeError to match previous 
behaviour and test cases

--
nosy: +eryksun
Added file: http://bugs.python.org/file41009/ctypes_from_buffer_3.patch

___
Python tracker 

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



  1   2   >