Re: Call a shell command from Python

2016-10-31 Thread Steve D'Aprano
On Tue, 1 Nov 2016 04:00 pm, Wildman wrote:

> You are correct about that but, in this case grep never "sees" the '$'
> sign.  Bash expands $USER to the actual user name beforehand.  If you
> are on a Linux system, enter this into a terminal to illustrate:
> 
> sudo grep ^$USER\: /etc/shadow

Bash is not involved here. Python is calling grep directly.


You don't have to believe us, you can test this yourself. Create a simple
text file with a single line containing your username, and a simple Python
script that calls grep as you have been:


[steve@ando ~]$ echo $USER
steve
[steve@ando ~]$ cat foo.txt
blah blah steve blah blah
[steve@ando ~]$ cat greptest.py
import subprocess
cmdlist = ['grep', '$USER', 'foo.txt']
p = subprocess.Popen(cmdlist, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
line, err = p.communicate()
print err, line

[steve@ando ~]$ python2.7 greptest.py

[steve@ando ~]$



So there you have it: categorical proof that bash does not expand the
string '$USER'. It cannot: bash is not involved in the subprocess call.
Python calls grep directly.

If you want to expand the '$USER' string from Python, do it yourself:


py> import os
py> os.environ['USER']
'steve'


> If the user name is ben then grep would see this:
> 
> grep ben\: /etc/shadow

If would, if you called grep from bash. But you didn't.


>>> > Maybe you are expecting Bash to be involved somehow (and so “$USER”
>>> > will be substituted by Bash with some other value). That's not what
>>> > happens.
>>>
>>> No, the shell is already running.
>> 
>> I don't know what you mean by this. If you mean that some *other*
>> instances of the shell ar running: that isn't relevant to how your
>> Python program invokes a subprocess.
> 
> I simply meant that the script is run from a terminal.

That's irrelevant. Just because the script is running from a terminal
doesn't mean that the shell can peer deep inside each and every process and
magically apply the shell's string expansion rules.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Call a shell command from Python

2016-10-31 Thread Ben Finney
Wildman via Python-list  writes:

> […] in this case grep never "sees" the '$' sign. Bash expands $USER to
> the actual user name beforehand.

I understand how Bash substitutes variables on the command line.

What I need to repeat, though: In this case, no, Bash doesn't do that
because Bash isn't getting involved. Grep does in fact see the “$” in
the command argument, because nothing ever replaces it.

> >> No, the shell is already running.
> > 
> > I don't know what you mean by this.
>
> I simply meant that the script is run from a terminal.

Which means that shell isn't involved in that command you're invoking
from inside the script.

The Bash instance which invoked your script is now *doing nothing*, and
will never do anything again until control returns to it (by your script
exiting, or suspending, or some other control interruption).

Your script invoking further programs will *not* get the earlier Bash
involved in that process (except in the special cases where those
programs themselves manipulate running processes; ‘sudo’ and ‘grep’ are
not special in this way).

So the way your script was invoked has no bearing on whether Bash will
get involved in what your script does. Your script is *directly*
invoking programs, and if you don't ask for a shell to be involved you
won't get it.

-- 
 \  “… a Microsoft Certified System Engineer is to information |
  `\ technology as a McDonalds Certified Food Specialist is to the |
_o__)   culinary arts.” —Michael Bacarella |
Ben Finney

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


[issue28574] Update bundled pip

2016-10-31 Thread Steve Dower

New submission from Steve Dower:

I know you've already taken the fix I'm most concerned about (the new distlib 
version, https://github.com/pypa/pip/pull/4038), but this is a reminder that we 
really need a new release of pip to bundle with Python 3.6.0 beta 4.

I'm not hugely concerned as to whether it's an 8.2 or a 9.0 (but Ned might have 
a preference).

--
assignee: dstufft
messages: 279849
nosy: dstufft, ned.deily, paul.moore, steve.dower
priority: release blocker
severity: normal
stage: needs patch
status: open
title: Update bundled pip
type: behavior
versions: Python 3.6, Python 3.7

___
Python tracker 

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



[issue28574] Update bundled pip

2016-10-31 Thread Steve Dower

Steve Dower added the comment:

Also, it can go into whatever versions you'd normally insert into. I just 
tagged 3.6 and 3.7 because they're the ones currently broken.

--

___
Python tracker 

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



Re: Call a shell command from Python

2016-10-31 Thread Wildman via Python-list
On Tue, 01 Nov 2016 12:08:52 +1100, Ben Finney wrote:

> Wildman via Python-list  writes:
> 
>> On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote:
>>
>> > One immediate difference I see is that you specify different
>> > arguments to ‘grep’. You have a different pattern for each command.
>> > 
>> > * The ‘^user\:’ pattern matches “user\:” at the start of a line.
>> > 
>> > * The ‘^$USER\:’ pattern I think won't match anything, since “$” matches
>> >   end-of-line and then you expect further characters *past* the end of
>> >   the line. I think that will always fail to match any line.
>>
>> Yes, the '^' indicates the start of the line and the ':' indicates
>> the character where to stop.  The colon has a special meaning so it
>> has to be escaped, '\:'.  The dollar sign precedes a variable.  In
>> this case it is an environment variable.
> 
> The ‘grep’ program you're invoking knows nothing of such variables, and
> the ‘$’ sign means to ‘grep’ what I said above.

You are correct about that but, in this case grep never "sees" the '$'
sign.  Bash expands $USER to the actual user name beforehand.  If you
are on a Linux system, enter this into a terminal to illustrate:

sudo grep ^$USER\: /etc/shadow

If the user name is ben then grep would see this:

grep ben\: /etc/shadow

>> > Maybe you are expecting Bash to be involved somehow (and so “$USER”
>> > will be substituted by Bash with some other value). That's not what
>> > happens.
>>
>> No, the shell is already running.
> 
> I don't know what you mean by this. If you mean that some *other*
> instances of the shell ar running: that isn't relevant to how your
> Python program invokes a subprocess.

I simply meant that the script is run from a terminal.

> The shell is not involved in the command as you invoke it directly as a
> subprocess, without asking for a shell.
> 
>> And $USER will be substituted by the name of the user that invoked the
>> shell.
> 
> It will not, because there is no shell involved: your Python program
> invokes ‘sudo’, which invokes ‘grep’. The shell is never involved in
> that chain, so its substitutions rules are irrelevant.

I think my terminology is causing confusion.  I apologize for that. 

-- 
 GNU/Linux user #557453
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.6.0b3 is now available

2016-10-31 Thread Ned Deily
On behalf of the Python development community and the Python 3.6 release
team, I'm pleased to announce the availability of Python 3.6.0b3. 3.6.0b3
is the third of four planned beta releases of Python 3.6, the next major
release of Python.

Among the new major new features in Python 3.6 are:

* PEP 468 - Preserving the order of **kwargs in a function
* PEP 487 - Simpler customization of class creation
* PEP 495 - Local Time Disambiguation
* PEP 498 - Literal String Formatting
* PEP 506 - Adding A Secrets Module To The Standard Library
* PEP 509 - Add a private version to dict
* PEP 515 - Underscores in Numeric Literals
* PEP 519 - Adding a file system path protocol
* PEP 520 - Preserving Class Attribute Definition Order
* PEP 523 - Adding a frame evaluation API to CPython
* PEP 524 - Make os.urandom() blocking on Linux (during system startup)
* PEP 525 - Asynchronous Generators (provisional)
* PEP 526 - Syntax for Variable Annotations (provisional)
* PEP 528 - Change Windows console encoding to UTF-8 (provisional)
* PEP 529 - Change Windows filesystem encoding to UTF-8 (provisional)
* PEP 530 - Asynchronous Comprehensions

Please see "What’s New In Python 3.6" for more information:

https://docs.python.org/3.6/whatsnew/3.6.html

You can find Python 3.6.0b3 here:

https://www.python.org/downloads/release/python-360b3/

Beta releases are intended to give the wider community the opportunity
to test new features and bug fixes and to prepare their projects to
support the new feature release. We strongly encourage maintainers of
third-party Python projects to test with 3.6 during the beta phase and
report issues found to bugs.python.org as soon as possible. While the
release is feature complete entering the beta phase, it is possible that
features may be modified or, in rare cases, deleted up until the start
of the release candidate phase (2016-12-05). Our goal is have no changes
after rc1. To achieve that, it will be extremely important to get as
much exposure for 3.6 as possible during the beta phase. Please keep in
mind that this is a preview release and its use is not recommended for
production environments

The next pre-release of Python 3.6 will be 3.6.0b4, currently
scheduled for 2016-11-21. More information about the release schedule
can be found here:

https://www.python.org/dev/peps/pep-0494/

--
  Ned Deily
  n...@python.org -- []

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


[issue28573] Python 3.6.0b3 64-bit has no sys._mercurial info

2016-10-31 Thread Steve Dower

New submission from Steve Dower:

The release build for 3.6.0b3 64-bit is missing Mercurial info:

>>> import sys
>>> sys._mercurial
('CPython', '', '')
>>> sys.version
'3.6.0b3 (default, Nov  1 2016, 03:21:01) [MSC v.1900 64 bit (AMD64)]'

The debug build and the 32-bit builds are fine. It needs further investigation, 
but I assume the PGO build is to blame, as we only run PGO on the 64-bit 
release build.

--
assignee: steve.dower
components: Windows
messages: 279848
nosy: ned.deily, paul.moore, steve.dower, tim.golden, zach.ware
priority: release blocker
severity: normal
stage: test needed
status: open
title: Python 3.6.0b3 64-bit has no sys._mercurial info
type: compile error
versions: Python 3.6, Python 3.7

___
Python tracker 

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



[issue27781] Change sys.getfilesystemencoding() on Windows to UTF-8

2016-10-31 Thread Steve Dower

Steve Dower added the comment:

Before 3.6.0 beta 4 I need to make this change permanent. From memory, it's 
just an exception message that needs changing (and PEP 529 becomes final), but 
I'll review the changeset to be sure.

--
nosy: +ned.deily
priority: normal -> release blocker
stage: commit review -> needs patch
versions: +Python 3.7

___
Python tracker 

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



[issue12857] Expose called function on frame object

2016-10-31 Thread Mark Lawrence

Changes by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

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



Re: Need help with coding a function in Python

2016-10-31 Thread Larry Hudson via Python-list

On 10/31/2016 03:09 PM, devers.meetthebadger.ja...@gmail.com wrote:

http://imgur.com/a/rfGhK#iVLQKSW

How do I code a function that returns a list of the first n elements of the 
sequence defined in the link? I have no idea!

So far this is my best shot at it (the problem with it is that the n that i'm 
subtracting or adding in the if/else part does not represent the element's 
position, but just the n that I am plugging into the function):

def reca(n):
rlist=[0]
while len(rlist) < n:
if (rlist[-1]-n) > 0 and (rlist[-1]-n) not in rlist:
rlist.append(rlist[-1]-n)

else:
rlist.append(rlist[-1]+n)

return(rlist)



I'm not looking at your link or your code, just your description of the problem.
Paraphrased:  "A list of the first n elements of a sequence"

No function necessary, just use slicing...

newlist = oldlist[:n]

list:[1,2,3,4,5,6,7,8,9,10][:5] gives [1,2,3,4,5]
tuple:   (1,2,3,4,5,6,7,8,9,10)[:5] gives (1,2,3,4,5)
string:  "Hello there"[:5] gives "Hello"

Works for sequences shorter than n as well, which gives the full (short) 
sequence.

list:[1,2,3][:5] gives [1,2,3]
etc...

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


[issue28548] http.server parse_request() bug and error reporting

2016-10-31 Thread Martin Panter

Changes by Martin Panter :


--
versions: +Python 3.7 -Python 3.5
Added file: http://bugs.python.org/file45300/parse-version.v2.patch

___
Python tracker 

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



[issue12857] Expose called function on frame object

2016-10-31 Thread Nick Coghlan

Nick Coghlan added the comment:

This topic came up in a discussion I was having with Yury, and thanks to 
generators and coroutines, I don't think "f_func" would be the right name for 
an attribute like this, with something more neutral like "f_origin" potentially 
being preferable

The specific runtime debugging use case I have in mind is this:

1. Given a frame reference, navigate to the generator-iterator or coroutine 
that spawned that frame
2. Given gi_back and cr_back doubly-linked counterparts to the current 
gi_yieldfrom and cr_await introspection attributes on generators and 
coroutines, expose the relevant generator and/or coroutine stack in addition to 
the frame stack

These secondary stacks could then potentially be incorporated into traceback 
outputs by default

--
nosy: +yselivanov

___
Python tracker 

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



[issue28542] document cross compilation

2016-10-31 Thread Martin Panter

Martin Panter added the comment:

Regarding 2.7, I guess it depends on your definition of “support”. People have 
been cross-compiling Python 2.7 longer than I have been working on Python. In 
the past I have tried to apply cross compilation fixes to 2.7. But if you are 
only confident about 3.6, let’s just stick with that for the moment.

FWIW, DESTDIR, --prefix, etc are not specific to cross compilation or Android. 
DESTDIR is also useful when building a package/tarball or whatever, rather than 
installing directly. And --prefix would be useful if you don’t have root access 
and want to install to $HOME or somewhere. These settings are mentioned in the 
2.7 README, but it looks like Guido trimmed them out for Python 3.0 (revision 
07d67a9725a7).

--

___
Python tracker 

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



Re: Call a shell command from Python

2016-10-31 Thread Ben Finney
Wildman via Python-list  writes:

> On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote:
>
> > One immediate difference I see is that you specify different
> > arguments to ‘grep’. You have a different pattern for each command.
> > 
> > * The ‘^user\:’ pattern matches “user\:” at the start of a line.
> > 
> > * The ‘^$USER\:’ pattern I think won't match anything, since “$” matches
> >   end-of-line and then you expect further characters *past* the end of
> >   the line. I think that will always fail to match any line.
>
> Yes, the '^' indicates the start of the line and the ':' indicates
> the character where to stop.  The colon has a special meaning so it
> has to be escaped, '\:'.  The dollar sign precedes a variable.  In
> this case it is an environment variable.

The ‘grep’ program you're invoking knows nothing of such variables, and
the ‘$’ sign means to ‘grep’ what I said above.

> > Maybe you are expecting Bash to be involved somehow (and so “$USER”
> > will be substituted by Bash with some other value). That's not what
> > happens.
>
> No, the shell is already running.

I don't know what you mean by this. If you mean that some *other*
instances of the shell ar running: that isn't relevant to how your
Python program invokes a subprocess.

The shell is not involved in the command as you invoke it directly as a
subprocess, without asking for a shell.

> And $USER will be substituted by the name of the user that invoked the
> shell.

It will not, because there is no shell involved: your Python program
invokes ‘sudo’, which invokes ‘grep’. The shell is never involved in
that chain, so its substitutions rules are irrelevant.

-- 
 \ “Try adding “as long as you don't breach the terms of service – |
  `\  according to our sole judgement” to the end of any cloud |
_o__)  computing pitch.” —Simon Phipps, 2010-12-11 |
Ben Finney

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


[issue28123] _PyDict_GetItem_KnownHash ignores DKIX_ERROR return

2016-10-31 Thread Xiang Zhang

Changes by Xiang Zhang :


Added file: http://bugs.python.org/file45299/issue28123_v5.patch

___
Python tracker 

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



Re: Need help with coding a function in Python

2016-10-31 Thread Steve D'Aprano
On Tue, 1 Nov 2016 09:09 am, devers.meetthebadger.ja...@gmail.com wrote:

> http://imgur.com/a/rfGhK#iVLQKSW


Why on earth are you posting a screen shot?

Do you edit your code with Photoshop?

As soon as you post an unnecessary screenshot, you cut the number of people
willing and able to help you in half:

- anyone who is blind or visually impaired and reading this with a 
  screen reader cannot help you, even if they wanted to;

- anyone reading this post somewhere where access to imgur is blocked
  (say, from work);

- anyone who takes one look at the URL and says "F--k it, if they 
  can't be bothered to copy and paste text, I can't be bothered to
  follow the link".


We're volunteers. We're not paid to solve your problem, so if you make it
hard for us, we simply won't bother.


> How do I code a function that returns a list of the first n elements of
> the sequence defined in the link? I have no idea!

I have no idea either, because I cannot see the image. I'll leave you to
guess why I can't.

But the usual way to return a list of the first n elements of a sequence is
with slicing:

first_bunch = sequence[:n]  # a slice from index 0 to just before index n


If sequence is a list, then the slice sequence[:n] will also be a list.
Otherwise you may want to convert it to a list:

first_bunch = list(sequence[:n])

How does slicing work? You can think of it as a faster, more efficient way
of something like this:

def cut_slice(sequence, start=0, end=None):
if end is None:
end = len(sequence)
result = []
for i in range(start, end):
value = sequence[i]
result.append(value)
return result


P.S. any time you think you want a while loop, 90% of the time you don't.
While-loops have their uses, but they're unusual. Whenever you know ahead
of time how many loops will be done, use a for-loop.

While-loops are only for those unusual cases where you don't know how many
times you need to loop.

Use a while-loop for:
- loop *until* something happens;
- loop *while* something happens;


Use a for-loop for:
- loop over each element of a sequence;
- loop a fixed number of times.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


[issue28385] Bytes objects should reject all formatting codes with an error message

2016-10-31 Thread Eric V. Smith

Eric V. Smith added the comment:

I don't have a strong feeling one way or the other. I'd be surprised if anyone 
is catching these errors.

--

___
Python tracker 

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



[issue28248] Upgrade installers to OpenSSL 1.0.2j

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

Thanks for the patch, Mariatta.  Pushed for released in 2.7.13, 3.5.3, and 
3.6.0b3.

--
priority: release blocker -> 
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



[issue28248] Upgrade installers to OpenSSL 1.0.2j

2016-10-31 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 33ad26897e30 by Ned Deily in branch '2.7':
Issue #28248: Update macOS installer build to use OpenSSL 1.0.2j.
https://hg.python.org/cpython/rev/33ad26897e30

New changeset a8799a63feb7 by Ned Deily in branch '3.5':
Issue #28248: Update macOS installer build to use OpenSSL 1.0.2j.
https://hg.python.org/cpython/rev/a8799a63feb7

New changeset c7e551f8c5d8 by Ned Deily in branch '3.6':
Issue #28248: merge from 3.5
https://hg.python.org/cpython/rev/c7e551f8c5d8

New changeset 9e66ffa7a791 by Ned Deily in branch 'default':
Issue #28248: merge from 3.6
https://hg.python.org/cpython/rev/9e66ffa7a791

--

___
Python tracker 

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



[issue28570] httplib mishandles unknown 1XX status codes

2016-10-31 Thread Martin Panter

Martin Panter added the comment:

Consuming and ignoring 1xx responses seems reasonable for general cases. 
Treating 101 (Switching Protocols) as a special case also seems reasonable.

I also agree it would be good to provide an API to return these responses (at 
least after the request is completely sent). Perhaps a new flag, 
c.getresponse(informational=True), or a new method, 
c.get_informational_response(timeout=...). The timeout is for servers that do 
not support “Expect: 100-continue” mode; see Issue 1346874.

There is also Issue 25919 discussing how to handle responses (including 1xx) 
while concurrently sending the request. That is a harder problem, but may be 
solvable with a few new APIs.

--
nosy: +martin.panter

___
Python tracker 

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



[issue28564] shutil.rmtree is inefficient due to listdir() instead of scandir()

2016-10-31 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
dependencies: +Add support of file descriptor in os.scandir()

___
Python tracker 

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



[issue28530] Howto detect if an object is of type os.DirEntry

2016-10-31 Thread Eryk Sun

Eryk Sun added the comment:

To clarify, DirEntry is only exposed in the posix/nt and os modules starting in 
3.6. To get a reference to it in 3.5 you have to fall back on something like 
the following:

import os

try:
from os import DirEntry
except ImportError:
import tempfile
with tempfile.NamedTemporaryFile() as ftemp:
scan = os.scandir(os.path.dirname(ftemp.name))
DirEntry = type(next(scan))
del scan, ftemp, tempfile

In 3.5 os.scandir does not support the with statement or raise a resource 
warning. That behavior was added in 3.6, for which the workaround shouldn't be 
required.

--

___
Python tracker 

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



[issue28208] update sqlite to 3.14.2

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

Thanks for the patch, Mariatta!  Pushed for release in 3.6.0b3.

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

___
Python tracker 

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



[issue28208] update sqlite to 3.14.2

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

[typo in commit message, should be #28208]

New changeset 88e3df38d591 by Ned Deily in branch '3.6':
Issue #28028: Update OS X installers to use SQLite 3.14.2.
https://hg.python.org/cpython/rev/88e3df38d591

--

___
Python tracker 

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



[issue28028] Convert warnings to SyntaxWarning in parser

2016-10-31 Thread Ned Deily

Changes by Ned Deily :


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

___
Python tracker 

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



[issue28028] Convert warnings to SyntaxWarning in parser

2016-10-31 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 88e3df38d591 by Ned Deily in branch '3.6':
Issue #28028: Update OS X installers to use SQLite 3.14.2.
https://hg.python.org/cpython/rev/88e3df38d591

--
nosy: +python-dev

___
Python tracker 

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



[issue28208] update sqlite to 3.14.2

2016-10-31 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 7e48e0557152 by Ned Deily in branch 'default':
Issue #28208: merge from 3.6
https://hg.python.org/cpython/rev/7e48e0557152

--

___
Python tracker 

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



Re: Need help with coding a function in Python

2016-10-31 Thread Paul Rubin
devers.meetthebadger.ja...@gmail.com writes:
> http://imgur.com/a/rfGhK#iVLQKSW ...

> So far this is my best shot at it (the problem with it is that the n
> that i'm subtracting or adding in the if/else part does not represent
> the element's position...

Right, so can you figure out the element's position?  If yes, calculate
it and use it instead of n.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help with coding a function in Python

2016-10-31 Thread MRAB

On 2016-10-31 22:09, devers.meetthebadger.ja...@gmail.com wrote:

http://imgur.com/a/rfGhK#iVLQKSW

How do I code a function that returns a list of the first n elements of the 
sequence defined in the link? I have no idea!

So far this is my best shot at it (the problem with it is that the n that i'm 
subtracting or adding in the if/else part does not represent the element's 
position, but just the n that I am plugging into the function):

def reca(n):
rlist=[0]
while len(rlist) < n:
if (rlist[-1]-n) > 0 and (rlist[-1]-n) not in rlist:
rlist.append(rlist[-1]-n)

else:
rlist.append(rlist[-1]+n)

return(rlist)


When you're calculating a[n], what's n?

Well:

When you're calculating a[1], you already have a[0], or 1 element.

When you're calculating a[2], you already have a[0] and a[1], or 2 elements.

So, in general, when you're calculating a[n], you already have a[0] ... 
a[n - 1], or n elements.


The value of n is the length of the list so far.

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


Re: Recursive generator in Python 3.5

2016-10-31 Thread Gregory Ewing

tpqnn...@gmail.com wrote:


def fg(args):
  if not args:
yield ""
return
  for i in args[0]:
for tmp in fg(args[1:]):
  yield i + tmp
  return


The final return is redundant, since there is an implicit return
at the end, just like an ordinary function. The other one is just
performing an early exit from the iteration. You could write it
without any returns like this:

def fg(args):
  if not args:
yield ""
  else:
for i in args[0]:
  for tmp in fg(args[1:]):
yield i + tmp


this is the Tower of Hanoi with  recursive generator but it do

> not have the 'return' here

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


Need help with coding a function in Python

2016-10-31 Thread devers . meetthebadger . jason
http://imgur.com/a/rfGhK#iVLQKSW

How do I code a function that returns a list of the first n elements of the 
sequence defined in the link? I have no idea!

So far this is my best shot at it (the problem with it is that the n that i'm 
subtracting or adding in the if/else part does not represent the element's 
position, but just the n that I am plugging into the function):

def reca(n):
rlist=[0]
while len(rlist) < n:
if (rlist[-1]-n) > 0 and (rlist[-1]-n) not in rlist:
rlist.append(rlist[-1]-n)

else:
rlist.append(rlist[-1]+n)

return(rlist)
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28513] Document zipfile CLI

2016-10-31 Thread Martin Panter

Martin Panter added the comment:

Apparently (haven’t tried myself) if you put “.. program:: zipfile” before the 
:option: invocations, it changes the default context and you don’t need the 
 bit.

The text in general looks fine. One very minor thing: I would use a hyphen when 
“command line” is a modifier on another noun, i.e. command-line interface, 
command-line options.

--

___
Python tracker 

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



[issue28572] IDLE: add tests for config dialog.

2016-10-31 Thread Terry J. Reedy

Terry J. Reedy added the comment:

msg279176 of #27755 describe experiments with ttk.combobox.

--

___
Python tracker 

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



[issue28571] llist and scipy.stats conflicts, python segfault

2016-10-31 Thread R. David Murray

R. David Murray added the comment:

This involves two third party C extensions, so there isn't really anything for 
us to do here until those projects have taken a look.  If they can identify a 
CPython bug causing this, then we can do something.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue22595] F5 shortcut key not working in IDLE for OSX

2016-10-31 Thread Dave T

Dave T added the comment:

Its on a windows 10 

It doesn't come with the run application but the debug

--
nosy: +Dave T
versions: +Python 2.7 -Python 3.5
Added file: http://bugs.python.org/file45298/Py 2.7.JPG

___
Python tracker 

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



[issue28572] IDLE: add tests for config dialog.

2016-10-31 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Patch makes two types of change to configdialog.  1. Make tested widgets 
visible to their methods can be called.  2. Delete an erroneous command 
argument for General tab radiobutton.  Calling SetKeysType on the General tab 
just redid adjustments on the Keys tab that were already done.

--

___
Python tracker 

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



[issue28571] llist and scipy.stats conflicts, python segfault

2016-10-31 Thread Lluís

Lluís added the comment:

Confirmed with 2.7 as well.

--
versions: +Python 2.7

___
Python tracker 

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



[issue28572] IDLE: add tests for config dialog.

2016-10-31 Thread Terry J. Reedy

New submission from Terry J. Reedy:

The current test_configdialog creates an instance of ConfigDialog.  Time to add 
some real tests so I can comfortably work on multiple other configdialog issues.

  The challenge is to do it so tests run without a blocking mainloop call and 
without IDLE's tcl update calls.  Explicit root.update call can be added if 
needed.  I also want to test without making the dialog visible.  This is a 
problem for at least some event_generate calls, but their seem to be (mostly) 
better options.  Buttons and Radiobuttons for both tk and ttk have an invoke 
method that works fine.  Entry widget insert seems to work also to trigger that 
test action.

Attached are partial tests for two of the four main tabs.

--
assignee: terry.reedy
files: config_dialog_test.diff
keywords: patch
messages: 279829
nosy: terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: IDLE: add tests for config dialog.
type: enhancement
versions: Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45297/config_dialog_test.diff

___
Python tracker 

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



[issue28571] llist and scipy.stats conflicts, python segfault

2016-10-31 Thread Lluís

New submission from Lluís:

I'm running this small script that produces a segfault:

https://gist.github.com/anonymous/d24748d5b6de88b31f18965932744211

My python version is Python 3.5.2 (default, Jun 28 2016, 08:46:01) [GCC 6.1.1 
20160602] on linux. And running scipy version 0.18.1.

Can someone confirm if this segfaults with other systems ?

--
components: Interpreter Core
messages: 279828
nosy: Lluís
priority: normal
severity: normal
status: open
title: llist and scipy.stats conflicts, python segfault
type: crash
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



[issue28570] httplib mishandles unknown 1XX status codes

2016-10-31 Thread Cory Benfield

Cory Benfield added the comment:

101 should probably be special-cased, because in that case the underlying 
protocol is being totally changed.

--

___
Python tracker 

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



[issue28570] httplib mishandles unknown 1XX status codes

2016-10-31 Thread SilentGhost

SilentGhost added the comment:

The fix could be as small as the attached patched, though I'm not sure that is 
the correct way of handling 101 code.

--
keywords: +patch
nosy: +SilentGhost
Added file: http://bugs.python.org/file45296/28570.diff

___
Python tracker 

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



[issue18987] distutils.utils.get_platform() for 32-bit Python on a 64-bit machine

2016-10-31 Thread Michael Felt

Michael Felt added the comment:

FYI: This is 'actual' as I am working on an implementation of a cloud-init 
distro for AIX and it is very difficult to figure out the correct approach for 
a replacement value for os.uname[4] - when comparing with "Linux" logic

I was thinking of using

platform.platform().split("-")[3]

but both are 32-bit on 64-bit hardware:

>>> platform.platform().split("-")
['AIX', '1', '00C291F54C00', 'powerpc', '32bit']
>>> platform.platform().split("-")[4]
'32bit'
>>> platform.platform().split("-")[3]
'powerpc'

>>> platform.platform().split("-")
['Linux', '3.2.0', '4', 'powerpc64', 'ppc64', 'with', 'debian', '7.8']
>>> platform.platform().split("-")[4]
'ppc64'
>>> platform.platform().split("-")[3]
'powerpc64'

This - also - seems tricky re: the placement of the -
>>> platform.platform()
'Linux-3.2.0-4-powerpc64-ppc64-with-debian-7.8'

compared with:
>>> platform.platform()
'AIX-1-00C291F54C00-powerpc-32bit'

Truely, some guidance from "the powers that be" is needed if there is ever to 
be uniformity. And if it 'cannot' be patched on 'old' versions, at least there 
will be a way to hack clarity into code (imho, a patch is better rather than 
hacks creating continued diversity - everyone continues to use their 
understanding of intent, creating new diverse wishes (aka features not 
benefits)) for what the code "must" do - because there are so many projects 
that used it this way (and others that used it that way) 

:)

--

___
Python tracker 

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



[issue18987] distutils.utils.get_platform() for 32-bit Python on a 64-bit machine

2016-10-31 Thread Michael Felt

Michael Felt added the comment:

There are so many places where there are references to where 32-bit and 64-bit 
are referred to - and, in particular, the value of os.uname()[4]

For the discussion I went back to 32-bit Python on AIX

A)
michael@x071:[/data/prj/python/archive/Python-2.7.3]python
Python 2.7.3 (default, Sep 26 2013, 20:43:10) [C] on aix5
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'AIX-1-00C291F54C00-powerpc-32bit'
>>> import os
>>> os.uname()[4]
'00C291F54C00'
>>> import sys
>>> sys.maxsize
2147483647

B)
root@x066:~# python
Python 2.7.3 (default, Mar 14 2014, 12:37:29)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.2.0-4-powerpc64-ppc64-with-debian-7.8'
>>> import os
>>> os.uname()[4]
'ppc64'
>>> import sys
>>> sys.maxsize
2147483647
>>>

The data comes from the same hardware - just different OS.

re: os.uname()[4] and platform.platform()
for AIX os.uname()[4] says next to nothing - the only bit relavant to the 
"machine" are the letters C4 and those are likely to be found on any POWER 32 
and 64-bit (no longer have direct access to 32-bit hardware so must trust the 
documentation on that one) - for AIX platform.platform() does give proper 
machine and interpreter size.

For Linux (debian in this case) os.uname()[4] identifies the hardware platform, 
and platform.platform() "looks" 64-bit to me, but sys.maxsize clearly shows 
this is 32-bit.

I am willing to work on a patch - even digging on the POWER Linux side as well 
- but to write a patch the desired output is needed.

And, I would suggest replacing the -m output with either -M or -p output:
michael@x071:[/data/prj/python/archive/Python-2.7.3]uname -m -M
00C291F54C00 IBM,8203-E4A
michael@x071:[/data/prj/python/archive/Python-2.7.3]uname -m -p
00C291F54C00 powerpc

Again - what is the preferred output. IMHO - platform.platform() comes very 
close for what I would be expecting.
AIX (noise) powerpc 32bit 
or
AIX (noise) powerpc 64bit

Comments? (and has this ever been discussed/specified in a PEP? In another 
discussion someone mentioned something about a wheel specification - but that 
refers back to distutils and IMHO this is "core" first, and distutils (should 
be) following)

--

___
Python tracker 

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



[issue28570] httplib mishandles unknown 1XX status codes

2016-10-31 Thread Cory Benfield

New submission from Cory Benfield:

Long story short


http.client does not tolerate non-100 or 101 status codes from the 1XX block in 
a sensible manner: it treats them as final responses, rather than as 
provisional ones.


Expected behaviour
~~

When http.client receives a 1XX status code that it does not recognise, it 
should either surface these to a user that expects them by means of a callback, 
or it should ignore them and only show the user the eventual final status code. 
This is required by RFC 7231 Section 6.2 (Informational 1xx), which reads:

> A client MUST be able to parse one or more 1xx responses received prior to a 
> final response, even if the client does not expect one. A user agent MAY 
> ignore unexpected 1xx responses.


Actual behaviour


http.client treats the 1XX status code as final. It parses the header block as 
though it were a response in the 2XX or higher range. http.client will assume 
that there is no content in the 1XX response, and so will leave the following 
final response unconsumed in the socket buffer. This means that if the 
HTTPConnection is re-used, the user will see the final response following the 
1XX as the response to the next request, even though it is not.


Steps to reproduce
~~

The following "server" can demonstrate the issue:

import socket
import time

document = b'''

  

title


  
  
Hello, world!
  

'''

s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('localhost', 8080))
s.listen(5)

while True:
new_socket, _ = s.accept()
data = b''

while not data.endswith(b'\r\n\r\n'):
data += new_socket.recv(8192)

new_socket.sendall(
b'HTTP/1.1 103 Early Hints\r\n'
b'Server: socketserver/1.0.0\r\n'
b'Link: ; rel=preload; as=style\r\n'
b'Link: ; rel=preload; as=script\r\n'
b'\r\n'
)
time.sleep(1)
new_socket.sendall(
b'HTTP/1.1 200 OK\r\n'
b'Server: socketserver/1.0.0\r\n'
b'Content-Type: text/html\r\n'
b'Content-Length: %s\r\n'
b'Link: ; rel=preload; as=style\r\n'
b'Link: ; rel=preload; as=script\r\n'
b'Connection: close\r\n'
b'\r\n' % len(document)
)
new_socket.sendall(document)
new_socket.close()


If this server is run directly, the following client can be used to test it:

from http.client import HTTPConnection

c = HTTPConnection('localhost', 8080)
c.request('GET', '/')
r = c.getresponse()

print("Status: {} {}".format(r.status, r.reason))
print("Headers: {}".format(r.getheaders()))
print("Body: {}".format(r.read()))


This client will print

Status: 103 Early Hints
Headers: [('Content-Length', '0'), ('Server', 'socketserver/1.0.0'), ('Link', 
'; rel=preload; as=style'), ('Link', '; 
rel=preload; as=script')]
Body: b''


This response is wrong: the 200 header block is hidden from the client. 
Unfortunately, http.client doesn't allow us to ask for the next response: 
another call to "getresponse()" raises a "ResponseNotReady: Idle" exception.

--
components: Library (Lib)
messages: 279823
nosy: Lukasa
priority: normal
severity: normal
status: open
title: httplib mishandles unknown 1XX status codes
type: behavior
versions: Python 3.7

___
Python tracker 

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



[issue26920] android: test_sys fails

2016-10-31 Thread Xavier de Gaye

Changes by Xavier de Gaye :


--
assignee:  -> xdegaye
components: +Interpreter Core -Cross-Build, Extension Modules
stage:  -> commit review
versions: +Python 3.7

___
Python tracker 

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



[issue26920] android: test_sys fails

2016-10-31 Thread Xavier de Gaye

Xavier de Gaye added the comment:

For the record, on the Android emulator we have now (not sure where this change 
has been made):
>>> sys.getfilesystemencoding()
'utf-8'
>>> locale.getpreferredencoding(False)
'ascii'

So test_ioencoding_nonascii succeeds now. Anyway the problem with this test is 
being fixed at issue 19058.

--

___
Python tracker 

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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Eric V. Smith

Eric V. Smith added the comment:

Chi Hsuan Yen:

I'll investigate, and open another issue as needed.

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

___
Python tracker 

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



Re: Reading Fortran Ascii output using python

2016-10-31 Thread MRAB

On 2016-10-31 17:46, Heli wrote:

On Monday, October 31, 2016 at 6:30:12 PM UTC+1, Irmen de Jong wrote:

On 31-10-2016 18:20, Heli wrote:
> Hi all,
>
> I am trying to read an ascii file written in Fortran90 using python. I am 
reading this file by opening the input file and then reading using:
>
> inputfile.readline()
>
> On each line of the ascii file I have a few numbers like this:
>
> line 1: 1
> line 2: 1000.834739 2000.38473 3000.349798
> line 3: 1000 2000 5000.69394 99934.374638 54646.9784
>
> The problem is when I have more than 3 numbers on the same line such as line 
3, python seems to read this using two reads. This makes the above example will be 
read like this:
>
> line 1: 1
> line 2: 1000.834739 2000.38473 3000.349798
> line 3: 1000 2000 5000.69394
> line 4: 99934.374638 54646.9784
>
> How can I fix this for each fortran line to be read correctly using python?
>
> Thanks in Advance for your help,
>
>

You don't show any code so it's hard to say what is going on.
My guess is that your file contains spurious newlines and/or CRLF combinations.

Try opening the file in universal newline mode and see what happens?

with open("fortranfile.txt", "rU") as f:
for line in f:
print("LINE:", line)


Irmen


Thanks Irmen,

I tried with "rU" but that did not make a difference. The problem is a line 
that with one single write statement in my fortran code :

write(UNIT=9,FMT="(99g20.8)")  value

seems to be read in two python inputfile.readline().

Any ideas how I should be fixing this?

Thanks,


What is actually in the file?

Try opening it in binary mode and print using the ascii function:

with open("fortranfile.txt", "rb") as f:
contents = f.read()

print("CONTENTS:", ascii(contents))

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


Re: Recursive generator in Python 3.5

2016-10-31 Thread tpqnnd01
Thanks for your detail explanation, my problem may be the 'return' keyword. I 
confuse at the point that return come after yield keyword, I wonder what if in 
case this code do not have the 1st return. So, when i try to delete the 1st 
return, the code run with error (the list out of range).

This is actual clear from your example above, when the 1st return is delected, 
the statement flow shall be from (yield '') to (yield i + tmp) when the Next() 
is called. This behaviour shall reach to a statement is: for i in [][0] that 
shall raise an error: list index out of range.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ee82266ad35b by Eric V. Smith in branch '3.6':
Issue 28128: Print out better error/warning messages for invalid string 
escapes. Backport to 3.6.
https://hg.python.org/cpython/rev/ee82266ad35b

New changeset 7aa001a48120 by Eric V. Smith in branch 'default':
Issue 28128: Null merge with 3.6: already applied to default.
https://hg.python.org/cpython/rev/7aa001a48120

--

___
Python tracker 

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



[issue28513] Document zipfile CLI

2016-10-31 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thanks SilentGhost!

--

___
Python tracker 

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



Re: Reading Fortran Ascii output using python

2016-10-31 Thread Irmen de Jong
On 31-10-2016 19:24, Irmen de Jong wrote:
> So there must be something in that line in your file that it considers an EOF.

I meant to type EOL there. (end-of-line/newline).

Irmen

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


[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

Excellent, thanks everyone!  I'll leave this open for re-evaluation for 3.7.

--
priority: release blocker -> 
resolution: duplicate -> 
stage: test needed -> needs patch

___
Python tracker 

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



[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Jason R. Coombs

Jason R. Coombs added the comment:

Testing now...

--

___
Python tracker 

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



Re: Reading Fortran Ascii output using python

2016-10-31 Thread Irmen de Jong
On 31-10-2016 18:46, Heli wrote:

> Thanks Irmen, 
> 
> I tried with "rU" but that did not make a difference. The problem is a line 
> that with one single write statement in my fortran code :
> 
> write(UNIT=9,FMT="(99g20.8)")  value
> 
> seems to be read in two python inputfile.readline(). 
> 
> Any ideas how I should be fixing this?
> 
> Thanks, 
> 

We don't speak Fortran here (at least I don't).
Please show your Python code. What is 'inputfile'?
Also, in Python, the readline method is defined as:

>>> help(io.TextIOBase.readline)
Help on method_descriptor:

readline(...)
Read until newline or EOF.

Returns an empty string if EOF is hit immediately.

So there must be something in that line in your file that it considers an EOF.
Have you tried opening it in a regular text editor and inspecting what the 
characters
are on that particular line?


Irmen

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


Re: Calling Bash Command From Python

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 11:55:26 -0500, Wildman wrote:

> On Mon, 31 Oct 2016 11:05:23 -0400, Random832 wrote:
> 
>> On Mon, Oct 31, 2016, at 10:55, Wildman via Python-list wrote:
>>> I have code using that approach but I am trying to save myself
>>> from having to parse the entire shadow file.  Grep will do it
>>> for me if I can get code right.
>> 
>> Python already has built-in functions to parse the shadow file.
>> 
>> https://docs.python.org/3/library/spwd.html#module-spwd
> 
> I didn't know about that module.  Thanks, this can simplify
> things for me.
> 
>> But you can't use sudo this way if you use that. But why do you want to
>> use sudo from within the python script instead of just running the
>> python script with sudo?
> 
> In view of the module I just learned about, that would be
> a better approach.

I made a ‭discovery that I thought I would share.  When using
sudo to run the script the environment variable $USER will
always return 'root'.  Not what I wanted.  But this will
work:

user = os.environ["SUDO_USER"]
shadow = spwd.getspnam(user)

That will return the actual user name that invoked sudo.

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


[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Jason R. Coombs

Jason R. Coombs added the comment:

Confirmed. Tests are now passing where they were failing before. Thanks for the 
quick response!

--

___
Python tracker 

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



Re: Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-31 Thread Grant Edwards
On 2016-10-31, Wildman via Python-list  wrote:
> On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote:
>> Wildman via Python-list  writes:
>> 
>>> Python 2.7.9 on Linux
>>>
>>> Here is a bash command that I want to run from a python
>>> program:  sudo grep "^user\:" /etc/shadow
>> 
>> Some points to note:
>> 
>> * Those commands are not special to Bash, or any particular shell. They
>>   invoke commands, without AFAIK any specific Bash features. So this is
>>   asking rather to invoke a shell command.

Actually it's not a shell command either.

> Yes, I know.  I perhaps should have used the word "shell" instead
> of bash.  However, bash is a shell.

To most people, "bash command" or "shell command" refers to

 1) a commands built in to bash (or other shell)

 or

 2) a command line that must be interpreted by bash (or other shell) because it
uses I/O redirection, variable substituion, globbing, etc.

Your code does not use bash (or any other shell), nor does it need to.

It's just running the sudo executable.  There are no shells involved,
so using the word shell isn't any better than using the word bash.

-- 
Grant Edwards   grant.b.edwardsYow! I have seen these EGG
  at   EXTENDERS in my Supermarket
  gmail.com... I have read the
   INSTRUCTIONS ...

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


[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

Thanks, Serhiy!  Jason, can you verify that there is no longer a 3.6 regression 
with your tests?

--

___
Python tracker 

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



[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I have rolled back the changes.

--

___
Python tracker 

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



[issue28550] if inline statement does not work with multiple assignment.

2016-10-31 Thread Eric Snow

Changes by Eric Snow :


--
status: pending -> closed

___
Python tracker 

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



Re: Reading Fortran Ascii output using python

2016-10-31 Thread Heli
On Monday, October 31, 2016 at 6:30:12 PM UTC+1, Irmen de Jong wrote:
> On 31-10-2016 18:20, Heli wrote:
> > Hi all, 
> > 
> > I am trying to read an ascii file written in Fortran90 using python. I am 
> > reading this file by opening the input file and then reading using:
> > 
> > inputfile.readline()
> > 
> > On each line of the ascii file I have a few numbers like this:
> > 
> > line 1: 1
> > line 2: 1000.834739 2000.38473 3000.349798 
> > line 3: 1000 2000 5000.69394 99934.374638 54646.9784
> > 
> > The problem is when I have more than 3 numbers on the same line such as 
> > line 3, python seems to read this using two reads. This makes the above 
> > example will be read like this:
> > 
> > line 1: 1
> > line 2: 1000.834739 2000.38473 3000.349798 
> > line 3: 1000 2000 5000.69394 
> > line 4: 99934.374638 54646.9784
> > 
> > How can I fix this for each fortran line to be read correctly using python?
> > 
> > Thanks in Advance for your help, 
> >  
> > 
> 
> You don't show any code so it's hard to say what is going on.
> My guess is that your file contains spurious newlines and/or CRLF 
> combinations.
> 
> Try opening the file in universal newline mode and see what happens?
> 
> with open("fortranfile.txt", "rU") as f:
> for line in f:
> print("LINE:", line)
> 
> 
> Irmen

Thanks Irmen, 

I tried with "rU" but that did not make a difference. The problem is a line 
that with one single write statement in my fortran code :

write(UNIT=9,FMT="(99g20.8)")  value

seems to be read in two python inputfile.readline(). 

Any ideas how I should be fixing this?

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


[issue28564] shutil.rmtree is inefficient due to listdir() instead of scandir()

2016-10-31 Thread Marian Beermann

Marian Beermann added the comment:

The main issue on *nix is more likely that by using listdir you get directory 
order, while what you really need is inode ordering. scandir allows for that, 
since you get the inode from the DirEntry with no extra syscalls - especially 
without an open() or stat().

Other optimizations are also possible. For example opening the directory and 
using unlinkat() would likely shave off a bit of CPU. But the dominating factor 
here is likely the bad access pattern.

--

___
Python tracker 

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



[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Xiang Zhang

Changes by Xiang Zhang :


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

___
Python tracker 

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



Re: Reading Fortran Ascii output using python

2016-10-31 Thread Irmen de Jong
On 31-10-2016 18:20, Heli wrote:
> Hi all, 
> 
> I am trying to read an ascii file written in Fortran90 using python. I am 
> reading this file by opening the input file and then reading using:
> 
> inputfile.readline()
> 
> On each line of the ascii file I have a few numbers like this:
> 
> line 1: 1
> line 2: 1000.834739 2000.38473 3000.349798 
> line 3: 1000 2000 5000.69394 99934.374638 54646.9784
> 
> The problem is when I have more than 3 numbers on the same line such as line 
> 3, python seems to read this using two reads. This makes the above example 
> will be read like this:
> 
> line 1: 1
> line 2: 1000.834739 2000.38473 3000.349798 
> line 3: 1000 2000 5000.69394 
> line 4: 99934.374638 54646.9784
> 
> How can I fix this for each fortran line to be read correctly using python?
> 
> Thanks in Advance for your help, 
>  
> 

You don't show any code so it's hard to say what is going on.
My guess is that your file contains spurious newlines and/or CRLF combinations.

Try opening the file in universal newline mode and see what happens?

with open("fortranfile.txt", "rU") as f:
for line in f:
print("LINE:", line)


Irmen

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


[issue28569] mock.attach_mock should work with any return value of patch()

2016-10-31 Thread Andrey Fedorov

Changes by Andrey Fedorov :


--
title: mock.attach_mock should work with return value of patch() -> 
mock.attach_mock should work with any return value of patch()

___
Python tracker 

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



[issue28569] mock.attach_mock should work with return value of patch()

2016-10-31 Thread Andrey Fedorov

New submission from Andrey Fedorov:

The attach_mock in the following code sample fails silently:

>>> from mock import patch, Mock
>>> p = patch('requests.get', autospec=True)
>>> manager = Mock()
>>> manager.attach_mock(p.start(), 'requests_get')
>>> import requests
>>> requests.get('https://google.com')

>>> manager.mock_calls
[]
>>> p.stop()
>>> manager.mock_calls
[]

It seems this would be a useful use-case, especially given that this code would 
work as-expected if 'requests.get' in the second line were replaced with a path 
to a class.

--
components: Library (Lib)
messages: 279812
nosy: Andrey Fedorov, michael.foord
priority: normal
severity: normal
status: open
title: mock.attach_mock should work with return value of patch()
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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



Reading Fortran Ascii output using python

2016-10-31 Thread Heli
Hi all, 

I am trying to read an ascii file written in Fortran90 using python. I am 
reading this file by opening the input file and then reading using:

inputfile.readline()

On each line of the ascii file I have a few numbers like this:

line 1: 1
line 2: 1000.834739 2000.38473 3000.349798 
line 3: 1000 2000 5000.69394 99934.374638 54646.9784

The problem is when I have more than 3 numbers on the same line such as line 3, 
python seems to read this using two reads. This makes the above example will be 
read like this:

line 1: 1
line 2: 1000.834739 2000.38473 3000.349798 
line 3: 1000 2000 5000.69394 
line 4: 99934.374638 54646.9784

How can I fix this for each fortran line to be read correctly using python?

Thanks in Advance for your help, 
 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Xiang Zhang

Xiang Zhang added the comment:

The bug seems to lies in 
https://hg.python.org/cpython/file/tip/Objects/dictobject.c#l1291. We should 
use oldkeys->dk_nentries instead of numentries.

--

___
Python tracker 

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



[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

Thanks, Jason, for the heads-up.  Serhiy, can you take a look at this quickly?  
I'm going to hold 360b3 until we have a better idea what's going on.

--
priority: normal -> release blocker
resolution: fixed -> duplicate
stage: resolved -> test needed
status: closed -> open

___
Python tracker 

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



[issue26959] pickle: respect dispatch for functions again

2016-10-31 Thread Vsevolod Velichko

Vsevolod Velichko added the comment:

Hi, any progress here?

--

___
Python tracker 

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



[issue28518] execute("begin immediate") throwing OperationalError

2016-10-31 Thread Aviv Palivoda

Aviv Palivoda added the comment:

I looked into this error and I think the problem is the sqlite3_stmt_readonly 
check in _pysqlite_query_execute (cursor.c line 517):

if (self->connection->begin_statement && 
!sqlite3_stmt_readonly(self->statement->st) && !self->statement->is_ddl) {
if (sqlite3_get_autocommit(self->connection->db)) {
result = _pysqlite_connection_begin(self->connection);
if (!result) {
goto error;
}
Py_DECREF(result);
}
}

As you can see we check if the current statement is not readonly and if so we 
start a transaction. The problem is that sqlite3_stmt_readonly return false for 
the "begin immediate" statement. When this happens we open a transaction with 
_pysqlite_connection_begin and then executing the "begin immediate".

I think this is a error in sqlite as the documentation says:
"ransaction control statements such as BEGIN, COMMIT, ROLLBACK, SAVEPOINT, and 
RELEASE cause sqlite3_stmt_readonly() to return true,"
(https://www.sqlite.org/c3ref/stmt_readonly.html)

--
nosy: +palaviv

___
Python tracker 

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



[issue28513] Document zipfile CLI

2016-10-31 Thread SilentGhost

SilentGhost added the comment:

Serhiy, this needs .. program:: zipfile directive specified before cmdoption. 
Without it :option:`-c` links to python's -c, rather than zipfile's. The -l and 
-e are linked correctly, but the option links would have be be changed for all 
three, i.e. to :option:`-c `

--
nosy: +SilentGhost
stage: commit review -> patch review

___
Python tracker 

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



Re: Calling Bash Command From Python

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 11:05:23 -0400, Random832 wrote:

> On Mon, Oct 31, 2016, at 10:55, Wildman via Python-list wrote:
>> I have code using that approach but I am trying to save myself
>> from having to parse the entire shadow file.  Grep will do it
>> for me if I can get code right.
> 
> Python already has built-in functions to parse the shadow file.
> 
> https://docs.python.org/3/library/spwd.html#module-spwd

I didn't know about that module.  Thanks, this can simplify
things for me.

> But you can't use sudo this way if you use that. But why do you want to
> use sudo from within the python script instead of just running the
> python script with sudo?

In view of the module I just learned about, that would be
a better approach.

-- 
 GNU/Linux user #557453
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28199] Compact dict resizing is doing too much work

2016-10-31 Thread Jason R. Coombs

Jason R. Coombs added the comment:

In https://github.com/pypa/setuptools/issues/836, I've pinpointed this commit 
as implicated in dictionaries spontaneously losing keys. I have not yet 
attempted to replicate the issue in a standalone environment, and I'm hoping 
someone with a better understanding of the implementation can devise a 
reproduction that distills the issue that setuptools seems only to hit in very 
specialized conditions.

Please let me know if I can help by providing more detail in the environment 
where this occurs or by filing another ticket. Somewhere we should capture that 
this is a regression pending release in 3.6.0b3 today, and for that reason, I'm 
adding Ned to this ticket.

--
nosy: +jason.coombs, ned.deily

___
Python tracker 

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



[issue28544] Implement asyncio.Task in C

2016-10-31 Thread Brett Cannon

Brett Cannon added the comment:

Just an FYI, for testing code that has both pure Python and C versions you can 
follow the advice in https://www.python.org/dev/peps/pep-0399/#details . And if 
you want to really simplify things you start down the road of what 
test_importlib uses: 
https://github.com/python/cpython/blob/master/Lib/test/test_importlib/util.py#L81
 .

--
nosy: +brett.cannon

___
Python tracker 

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



[issue26919] on Android python fails to decode/encode command line arguments

2016-10-31 Thread Xavier de Gaye

Changes by Xavier de Gaye :


--
title: android: test_cmd_line fails -> on Android python fails to decode/encode 
command line arguments

___
Python tracker 

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



Re: Recursive generator in Python 3.5

2016-10-31 Thread Steve D'Aprano
On Tue, 1 Nov 2016 12:39 am, tpqnn...@gmail.com wrote:

> I have some confuse about the recursive generator where the code mixing
> Yield and return keywork as below. I understand that "return" keywork just
> raise StopIteration exception but can not understanding in depth, so,
> could some one explain me about the actual function of two "return"
> keyworks in case it have other function and mechanism of for running this
> code segment below:

What part confuses you? The recursion, or the generator?

In a generator, "yield" outputs a value. "return" ends the generator. Return
is optional: reaching the end of the generator is the same as return.

So this generator:

def gen():
yield 1
yield 2
return  # optional


will output 1, then 2, then stop.

This generator:

def gen(*args):
if not args:
yield ""
return
for a in args:
   yield a
return  # optional

will either output "", then stop, or it will output each of the arguments
given, then stop.

Now let's look at your recursive call version:


> def fg(args):
>   if not args:
> yield ""
> return
>   for i in args[0]:
> for tmp in fg(args[1:]):
>   yield i + tmp
>   return

Let's start with a simple call:

list(fg([]))


args is empty, so it will output "" and halt.


list(fg(["ab"]))

args[0] is "ab", so it will loop:

for c in "ab":

Inside this loop, it loops again, this time over the rest of the arguments.
There are no more arguments, so the recursive call to fg() will yield "".

So the generator outputs "a" + "" (which is "a"); then it outputs "b" + ""
(which is "b"). Then it halts.

Second example:

list(fg(["xy", "ab"]))

args[0] is "xy", so it will loop:

for c in "xy":

Inside this loop, it loops again, this time over the rest of the arguments.
There is one more argument, "ab", so the recursive call to fg() is like:

fg(["ab"])

But we have already seen what happens when you call fg(["ab"]): it
outputs "a", then "b", then halts.

So now we have:

for c in "xy":
for d in ("a", "b"):
yield c + d

so you will get "xa", "xb", "ya", "yb".



Last example:

list(fg(["PQR", "xy", "ab"]))

will loop over "PQR", then as the inner loop it will loop over
fg(["xy", "ab"]). But we already have seen that. So you will get:

"Pxa", "Pxb", "Pya", "Pyb",
"Qxa", "Qxb", "Qya", "Qyb",
"Rxa", "Rxb", "Rya", "Ryb"

and then halt.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


[issue26919] android: test_cmd_line fails

2016-10-31 Thread Xavier de Gaye

Changes by Xavier de Gaye :


--
assignee:  -> xdegaye
components: +Interpreter Core -Cross-Build, Library (Lib)
stage:  -> commit review
versions: +Python 3.7

___
Python tracker 

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



[issue28530] Howto detect if an object is of type os.DirEntry

2016-10-31 Thread Brett Cannon

Brett Cannon added the comment:

As mentioned, this issue is fixed in Python 3.6 by exposing os.DirEntry which 
is just a direct import of what is in the posix module (which is the same thing 
as the nt module; name changes depending on the OS so just ignore the posix/nt 
part of all of this). And we can't backport the addition to the os module as 
that would break backwards-compatibility in a bug fix release. So I'm closing 
this as out of date.

--
nosy: +brett.cannon
resolution:  -> out of date
status: open -> closed

___
Python tracker 

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



[issue26919] android: test_cmd_line fails

2016-10-31 Thread Xavier de Gaye

Xavier de Gaye added the comment:

An interactive session confirms that the problem is indeed with the command 
line arguments of python invoked by subprocess (and the problem is fixed by the 
patch):

>>> from test.support import FS_NONASCII
>>> cmd = "assert(ord(%r) == %s)" % (FS_NONASCII, ord(FS_NONASCII))
>>> exec(cmd)
>>> import subprocess, sys
>>> subprocess.run([sys.executable, '-c', cmd])
Unable to decode the command from the command line:
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 12-13: 
surrogates not allowed
CompletedProcess(args=['/data/data/org.bitbucket.pyona/python/bin/python', 
'-c', "assert(ord('\xe6') == 230)"], returncode=1)

--

___
Python tracker 

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



[issue28568] Build files in PC/VS9.0 contain an outdated sqlite version number

2016-10-31 Thread Anselm Kruis

New submission from Anselm Kruis:

Python 2.7 only. Tested with 2.7.12.

Commit fa68df1d5e65 for #19450 changes the sqlite version for Python 2.7 on 
Windows from 3.6.21 to 3.8.11.0, but only for the build files in PCbuild. The 
documentation states, that the build files under PC\VS9.0 are also fully 
supported, but they still refer to sqlite version 3.6.21. This causes the 
command "PC\VS9.0\build.bat -r -e" to fail, because it first fetches sqlite 
3.9.11.0 from svn.python.org and then tries to build sqlite 3.6.21, which is of 
course not available.

The attached patch fixes the problem.

--
components: Build, Windows
files: fix-sqlite-version.patch
keywords: patch
messages: 279802
nosy: anselm.kruis, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Build files in PC/VS9.0 contain an outdated sqlite version number
type: compile error
versions: Python 2.7
Added file: http://bugs.python.org/file45295/fix-sqlite-version.patch

___
Python tracker 

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



[issue28564] shutil.rmtree is inefficient due to listdir() instead of scandir()

2016-10-31 Thread Josh Rosenberg

Josh Rosenberg added the comment:

You need to cache the names up front because the loop is unlinking entries, and 
readdir isn't consistent when the directory entries are mutated between calls. 
https://github.com/kripken/emscripten/issues/2528

FindFirstFile/FindNextFile likely has similar issues, even if they're not 
consistently seen (due to DeleteFile itself not guaranteeing deletion until the 
last handle to the file is closed).

scandir might save some stat calls, but you'd need to convert it from generator 
to list before the loop begins, which would limit the savings a bit.

--
nosy: +josh.r

___
Python tracker 

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



Re: Calling Bash Command From Python

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 08:13:54 +, Jon Ribbens wrote:

> On 2016-10-31, Wildman  wrote:
>> Here is a bash command that I want to run from a python
>> program:  sudo grep "^user\:" /etc/shadow
>>
>> If I enter the command directly into a terminal it works
>> perfectly.  If I run it from a python program it returns an
>> empty string.  Below is the code I am using.  Suggestions
>> appreciated.
>>
>> cmdlist = ["sudo", "grep", '"^$USER\:"', "/etc/shadow"]
>> p = subprocess.Popen(cmdlist,
>>  stdout=subprocess.PIPE,
>>  stderr=subprocess.PIPE)
>> shadow, err = p.communicate()
>> print shadow
> 
> Slightly surprised that nobody's pointed out that in your bash
> invocation, the first argument to grep is:
> 
> ^user\:
> 
> and in the Python code it is:
> 
> "$USER\:"
> 
> Your cmdlist should read:
> 
> ["sudo", "grep", r"^user\:", "/etc/shadow"]
> 
> or if you really want it to do the same as the bash:
> 
> ["sudo", "grep", "^" + os.environ["USER"] + r"\:", "/etc/shadow"]

The above line works perfectly.  I didn't occur to me to use the
'r' modifier.  Thank you.

Still one thing is odd.  No matter what, if I use the environment
variable $USER in the code, it won't work.  Just returns an empty
string.   At this point that is a non-issue tho.
Thanks again.

-- 
 GNU/Linux user #557453
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28028] Convert warnings to SyntaxWarning in parser

2016-10-31 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
versions:  -Python 3.6

___
Python tracker 

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



[issue28542] document cross compilation

2016-10-31 Thread Xavier de Gaye

Xavier de Gaye added the comment:

New patch, less verbose and taking into account the previous posts.

--
Added file: http://bugs.python.org/file45294/readme_4.patch

___
Python tracker 

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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

The error message is much better now, thanks you all!

Seems the ^ pointer is not always correct. For example, in the function scope 
it's correct:

$ cat test.py 
def foo():
s = 'C:\Program Files\Microsoft'

$ python3.7 -W error test.py
  File "test.py", line 2
s = 'C:\Program Files\Microsoft'
   ^
SyntaxError: invalid escape sequence \P

On the other hand, top-level literals confuses the pointer:

$ cat test.py   
s = 'C:\Program Files\Microsoft'

$ python3.7 -W error test.py
  File "test.py", line 1
s = 'C:\Program Files\Microsoft'
   ^
SyntaxError: invalid escape sequence \P

Is that expected?

Using 259745f9a1e4 on Arch Linux 64-bit

--

___
Python tracker 

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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Tim Graham

Tim Graham added the comment:

The patch is working well to identify warnings when running Django's test 
suite. Thanks!

--

___
Python tracker 

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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Eric V. Smith

Eric V. Smith added the comment:

I'll work on this as soon as I can, coordinating with Ned.

--

___
Python tracker 

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



[issue28028] Convert warnings to SyntaxWarning in parser

2016-10-31 Thread Emanuel Barry

Changes by Emanuel Barry :


--
priority: high -> normal

___
Python tracker 

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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Emanuel Barry

Emanuel Barry added the comment:

Even better than what I was aiming for :)

--
dependencies:  -Convert warnings to SyntaxWarning in parser
priority: deferred blocker -> release blocker

___
Python tracker 

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



Re: Recursive generator in Python 3.5

2016-10-31 Thread Chris Angelico
On Tue, Nov 1, 2016 at 1:50 AM,   wrote:
>
> Please see the exampl I just got it below, this is the Tower of Hanoi with 
> recursive generator but it do not have the 'return' here, do you have the 
> advice for this term:
>
> def A001511():
> yield 1
> b=1
> for x in A001511():
> yield x+1
> yield 1
>
>
> trial=A001511()
> for i in range(10):
> a=next(trial)
> print(a)

As soon as you get to the end of the function, it returns.

When you iterate over a generator, you run it to completion, taking
all the values it yields.

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


[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Eric V. Smith

Eric V. Smith added the comment:

I agree it would be nice to get this in to 3.6. I'm not sure I'd go so far as 
to say it's a must and can't wait for 3.6.1. It's a non-trivial change, and 
it's up to Ned to say if it can go in to 3.6.

If you don't run with -Wall or -Werror, then you won't notice any new behavior 
with invalid escapes, correct?

Maybe post to python-dev and see if we can get more reviewers?

--

___
Python tracker 

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



Re: Calling Bash Command From Python

2016-10-31 Thread Random832
On Mon, Oct 31, 2016, at 10:55, Wildman via Python-list wrote:
> I have code using that approach but I am trying to save myself
> from having to parse the entire shadow file.  Grep will do it
> for me if I can get code right.

Python already has built-in functions to parse the shadow file.

https://docs.python.org/3/library/spwd.html#module-spwd

But you can't use sudo this way if you use that. But why do you want to
use sudo from within the python script instead of just running the
python script with sudo?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Ned Deily

Ned Deily added the comment:

I agree that the current behavior for 3.6 is very user-unfriendly so I think 
the risks of making such an extensive change at this point in the release cycle 
are outweighed by the severity of the problem.  So let's get it into 3.6 now; 
there's still time for it to make 360b3.

--
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



[issue28128] Improve the warning message for invalid escape sequences

2016-10-31 Thread Emanuel Barry

Emanuel Barry added the comment:

As Nick pointed out in an earlier message on this thread and as Serhiy observed 
on GitHub issues, backporting this patch to 3.6 is a must. Large projects' use 
of Python 3.6 has shown that it's hard to track down the actual cause of the 
error; it only makes sense to improve that before the final release.

Serhiy, are you working on #28028 alongside this, or can it be removed from the 
dependencies?

--

___
Python tracker 

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



Re: Calling Bash Command From Python

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 09:12:57 +0100, Peter Otten wrote:

> Wildman via Python-list wrote:
> 
>> Python 2.7.9 on Linux
>> 
>> Here is a bash command that I want to run from a python
>> program:  sudo grep "^user\:" /etc/shadow
>> 
>> If I enter the command directly into a terminal it works
>> perfectly.  If I run it from a python program it returns an
>> empty string.  Below is the code I am using.  Suggestions
>> appreciated.
>> 
>> cmdlist = ["sudo", "grep", '"^$USER\:"', "/etc/shadow"]
>> p = subprocess.Popen(cmdlist,
>>  stdout=subprocess.PIPE,
>>  stderr=subprocess.PIPE)
>> shadow, err = p.communicate()
>> print shadow
> 
> What happens if you hardcode $USER? Compare:
> 
 subprocess.Popen(["sudo", "echo", "$USER"], 
> stdout=subprocess.PIPE).communicate()
> ('$USER\n', None)
> 
> That should explain the empty result. Possible fix:
> 
 subprocess.Popen(["sudo", "echo", os.environ["USER"]], 
> stdout=subprocess.PIPE).communicate()
> ('user\n', None)
> 
> While a shell should work, too, 
> 
 subprocess.Popen("sudo echo $USER", stdout=subprocess.PIPE, 
> shell=True).communicate()
> ('petto\n', None)
> 
> I'd prefer the os.environ lookup.

I have code using that approach but I am trying to save myself
from having to parse the entire shadow file.  Grep will do it
for me if I can get code right.

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


Re: Call a shell command from Python (was: Calling Bash Command From Python)

2016-10-31 Thread Wildman via Python-list
On Mon, 31 Oct 2016 15:44:13 +1100, Ben Finney wrote:

> Wildman via Python-list  writes:
> 
>> Python 2.7.9 on Linux
>>
>> Here is a bash command that I want to run from a python
>> program:  sudo grep "^user\:" /etc/shadow
> 
> Some points to note:
> 
> * Those commands are not special to Bash, or any particular shell. They
>   invoke commands, without AFAIK any specific Bash features. So this is
>   asking rather to invoke a shell command.

Yes, I know.  I perhaps should have used the word "shell" instead
of bash.  However, bash is a shell.

>   Nothing wrong with that; but on that basis, I've changed the subject
>   field.
> 
> * You're asking to invoke the ‘sudo’ command, which itself is designed
>   to switch to a separate user identity and run another program.

Yes, I know.

> * The above command is (I assume) typed into a shell, but your Python
>   program never invokes Bash or any other shell.

The program is run in a shell so invocation is not needed.

>> If I enter the command directly into a terminal it works perfectly.
> 
> Note that ‘sudo’ is specifically designed to be invoked interactively,
> seeking to verify that the current user has credentials to run the
> command.
> 
> Note further that ‘sudo’ will record when the *current user session*
> last invoked ‘sudo’ and seek re-verification if that is too long in the
> past.
> 
> Both of these are security measures, and are designed to avoid
> non-interactive use of ‘sudo’. Rather, it's meant to be used
> interactively by a real, present human with credentials to run the
> command.

Yes, I know all that.

>> If I run it from a python program it returns an empty string.
> 
> You can also check the exit status of a command; ‘grep’ will give
> different exit status for a match versus no match.
> 
>> Below is the code I am using.  Suggestions
>> appreciated.
>>
>> cmdlist = ["sudo", "grep", '"^$USER\:"', "/etc/shadow"]
> 
> One immediate difference I see is that you specify different arguments
> to ‘grep’. You have a different pattern for each command.
> 
> * The ‘^user\:’ pattern matches “user\:” at the start of a line.
> 
> * The ‘^$USER\:’ pattern I think won't match anything, since “$” matches
>   end-of-line and then you expect further characters *past* the end of
>   the line. I think that will always fail to match any line.

Yes, the '^' indicates the start of the line and the ':' indicates
the character where to stop.  The colon has a special meaning so it
has to be escaped, '\:'.  The dollar sign precedes a variable.  In
this case it is an environment variable.

The Linux shadow file contains information about the users of the
system.  It has the user name, encrypted password, salt, encryption
type and other information.  The format is such that the user name
is at the start of the line ending with a colon.  Here is an example:

wildman:$6$hODbsJJp$/NWGXZ3fMIVB4U.v/oLtAv.CnL0l0I39.IwsDx1ZAlKW3wUSjTfwJdnQvOMpYNbqNqqFfZ52vgYWBmnjsaX9R.:16177:0:9:7:::


>> p = subprocess.Popen(cmdlist,
>>  stdout=subprocess.PIPE,
>>  stderr=subprocess.PIPE)
>> shadow, err = p.communicate()
> 
> Maybe you are expecting Bash to be involved somehow (and so “$USER” will
> be substituted by Bash with some other value). That's not what happens.

No, the shell is already running.  And $USER will be substituted by the
name of the user that invoked the shell.

> Instead, the ‘subprocess.Popen.communicate’ method will invoke the
> program directly, without involving a shell. See the documentation for
> ‘subprocess.Popen’.

I will look into that.  Thanks for the reply.

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


Re: Recursive generator in Python 3.5

2016-10-31 Thread tpqnnd01
Hi Chris,

Please see the exampl I just got it below, this is the Tower of Hanoi with 
recursive generator but it do not have the 'return' here, do you have the 
advice for this term:

def A001511():
yield 1
b=1
for x in A001511():
yield x+1
yield 1


trial=A001511()
for i in range(10):
a=next(trial)
print(a)
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26163] FAIL: test_hash_effectiveness (test.test_set.TestFrozenSet)

2016-10-31 Thread Eric Appelt

Eric Appelt added the comment:

If I understand the reporting properly all tests so far have used SipHash24:

Python 3.7.0a0 (default:5b33829badcc+, Oct 30 2016, 17:29:47) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_config_var("Py_HASH_ALGORITHM")
0
>>> import sys
>>> sys.hash_info.algorithm
'siphash24'

It sounds like it is worth it for me to be more rigorous and perform a battery 
of tests using FNV and then SipHash24 to compare:

- Performing no dispersion after the frozenset hash is initially computed from 
XORing entry hashes (control)
- Performing dispersion using an LCG after the frozenset hash is initially 
computed from XORing entry hashes (current approach)
- Performing dispersion using the selected hash algorithm (FNV/SipHash24) after 
the frozenset hash is initially computed from XORing entry hashes (proposed 
approach)

I'll take the six plots and merge them into a single PNG, and also post my 
(short)testing and plotting scripts for reproducibility and checking of the 
results.

I can also write a regression test if you think that would be good to have in 
the test suite (perhaps skipped by default for time), where instead of using 
the same seven letters a-g as test strings and varying PYTHONHASHSEED, I could 
perform the letter test for n=7 with 1 different sets of short random 
strings to see if any fell below threshold.

--

___
Python tracker 

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



  1   2   >