RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Gregory Ewing wrote, on Monday, April 03, 2017 4:23 PM
> 
> Deborah Swanson wrote:
> > All my guesses were based on the
> > single variable (the most common type) examples I found. I just
didn't 
> > think of putting a colon after 'label', and found nothing to suggest

> > that's what I should do.
> 
> Hmmm, I'm not sure what the docs could do to make that any 
> clearer. The key:value syntax is part of *every* dict 
> comprehension (it's the only thing that distinguishes a dict 
> comprehension from a set comprehension).

I guess I saw a lot of examples that weren't clearly using the key:value
syntax, and all of it was so unfamiliar, that pattern just didn't stand
out to me. But it's starting to now, and that's the direction I need to
go in for dict comprehensions.

> > Despite my earlier words and protestations that I did look for two 
> > variable dict comprehensions, fairly diligently, I am taking what
you 
> > said seriously.
> 
> Don't feel too bad. Sometimes it's hard to know what to 
> google for, even for experienced people! Also it's hard for 
> doc writers to anticipate how less experienced people will 
> think. It wouldn't have occurred to me to use the phrase "two 
> variable dict comprehension" when writing documentation.

Yes, I was pretty sure the terminology I phrased the question with
wasn't correct, but I didn't know the right words to say, or where to
look them up, so I just tried to be as descriptive as I could.

But I accomplished my purpose in asking the question, even if it was
poorly put, and I've received quite a bit of good information, the
terminology I couldn't put my finger on, and some solid pointers of
directions to go in the future.
 
> Another thing it's important to be able to do is see through
> to the principles behind things, and then use those 
> principles to solve new problems that aren't explicitly 
> covered in any docs or examples.

Ah, yes, there's the rub. But it's true, from cooking to car mechanics
to Python coding, the key is in becoming familiar with the subject, and
hands on is the best teacher. (Yes, yes, we could have a discussion
about the role of education, but I'll say that it's seeing it all in
motion for yourself many times that seals the teaching into something
you know and don't need to be told.)

> The general principle behind all the forms of comprehension
> is that they consist of a prototypical element, followed by 
> some clauses that generate values for that element.
> 
> The syntax for the prototypical element mirrors that of the 
> corresponding display. So, for a dict comprehension, the 
> prototypical element has the form 'key:value', where 'key' 
> and 'value' are arbitrary expressions. From there, it's just 
> a matter of figuring out what to put into those expressions.
> 
> In your case, another part of the puzzle is the fact that
> you can unpack a tuple obtained from a for-loop into
> variables. That's a general feature of for-loops, both
> inside and outside of comprehensions, so you probably
> won't find it mentioned explicitly under the heading of
> dict comprehensions.
> 
> > Maybe it would be worthwhile to scrape the whole mess and have it in

> > searchable text form.
> 
> The HTML Python docs have a "Search" box, although I haven't 
> really used it so I don't know how well it works. 

It sucks, in a phrase. You're presented with a list of web page titles,
very few of which seem to have much to do with the Python language topic
you type into the search box. If you're interested in theoretical
dissertations you'll be pleased, but if you're looking for barebones
mechanical descriptions of the language you'll be wasting your time, in
my experience.

> In my 
> experience, Google with a site search often works a lot 
> better than search functions provided by sites themselves.

Yes, I used to use Google's site search on a regular basis but somehow
got out of the habit. It likely can't be beat if you know which website
will have the answer you're looking for, but the old Google truly shown
at finding places you didn't already know about.

> > I hope you won't be miffed though if I still come up empty handed
and 
> > come back here to ask again.
> > 
> > Deborah
> > 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Appending data to a json file

2017-04-03 Thread Oren Ben-Kiki
You _can_ just extend a JSON file without loading it, but it will not be
"fun".

Say the JSON file contains a top-level array. The final significant
character in it would be a ']'. So, you can read just a reasonably-sized
block from the end of the file, find the location of the final ']',
overwrite it with a ',' followed by your additional array entry/entries,
with a final ']'.

If the JSON file contains a top-level object, the final significant
character would be a '}'. Overwrite it with a ',' followed by your
additional object key/value pairs, with a final '}'.

Basically, if what you want to append is of the same kind as the content of
the file (array appended to array, or object to object):

- Locate final significant character in the file
- Locate first significant character in your appended data, replace it with
a ','
- Overwrite the final significant character in the file with your patched
data

It isn't elegant or very robust, but if you want to append to a very large
JSON array (for example, some log file?), then it could be very efficient
and effective.

Or, you could use YAML ;-)


On Tue, Apr 4, 2017 at 8:31 AM, dieter  wrote:

> Dave  writes:
>
> > I created a python program that gets data from a user, stores the data
> > as a dictionary in a list of dictionaries.  When the program quits, it
> > saves the data file.  My desire is to append the new data to the
> > existing data file as is done with purely text files.
>
> Usually, you cannot do that:
> "JSON" stands for "JavaScript Object Notation": it is a text representation
> for a single (!) JavaScript object. The concatenation of two
> JSON representations is not a valid JSON representation.
> Thus, you cannot expect that after such a concatenation, a single
> call to "load" will give you back complete information (it might
> be that a sequence of "load"s works).
>
> Personally, I would avoid concatenated JSON representations.
> Instead, I would read in (i.e. "load") the existing data,
> construct a Python object from the old and the new data (likely in the form
> of a list) and then write it out (i.e. "dump") again.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Appending data to a json file

2017-04-03 Thread dieter
Dave  writes:

> I created a python program that gets data from a user, stores the data
> as a dictionary in a list of dictionaries.  When the program quits, it
> saves the data file.  My desire is to append the new data to the
> existing data file as is done with purely text files.

Usually, you cannot do that:
"JSON" stands for "JavaScript Object Notation": it is a text representation
for a single (!) JavaScript object. The concatenation of two
JSON representations is not a valid JSON representation.
Thus, you cannot expect that after such a concatenation, a single
call to "load" will give you back complete information (it might
be that a sequence of "load"s works).

Personally, I would avoid concatenated JSON representations.
Instead, I would read in (i.e. "load") the existing data,
construct a Python object from the old and the new data (likely in the form
of a list) and then write it out (i.e. "dump") again.

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


[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Changes by Senthil Kumaran :


--
resolution:  -> fixed
stage: needs patch -> resolved
status: open -> closed
type: enhancement -> behavior

___
Python tracker 

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



[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Senthil Kumaran added the comment:


New changeset 0f9ceaf322cc9358373167115fd4c21ab2d9ad50 by Senthil Kumaran in 
branch '3.5':
bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) (#986)
https://github.com/python/cpython/commit/0f9ceaf322cc9358373167115fd4c21ab2d9ad50


--

___
Python tracker 

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



Re: Obtain Ceritificate Information from Invalid or Self-Signed Certificate in Python

2017-04-03 Thread dieter
Kenneth Buckler  writes:
> I'm working on a Python 2.7.13 (Win x64) script to verify SSL certificates,
> and alert for problems. Specifically, I'm looking to return the date the
> cert expires or did expire. However, I'm running into an issue where the
> script will return information only if the certificate is valid.

You may need to tell the Python socket library that you are
ready to accept any certificate - even expired ones.

I see below, that you already have tried that
("conn._https_verify_certificates(enable=False)") but it failed.
The reason: "_https_verify_certificates" is a function of the "ssl"
module, not a method of "SSLSocket" instances.
It is used to switch (globally) the behavior for verifying certificates,
not locally for a specific "SSLSocket".

Given the architecture of the "ssl" module (with the component
classes "socket", "SSLContext" and "SSLSocket"), the most likely
place to control the certificate verification is the "SSLContext".
And indeed, it has an attribute "verify_mode" to control this behaviour.


Likely, there is an alternative to disable certificate
verification in your case: the "ssl" module has the function
"get_server_certificate"; you could try to perform a normal
ssl connection and if this fails due to certificate problems,
you could fetch the certificate with the above function and analyse it.

> ...
> Per https://docs.python.org/2/library/ssl.html I tried to use
> conn._https_verify_certificates(enable=False) to disable certificate
> validation, but get an error that the attribute _https_verify_certificates
> doesn't exist.
> ...

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


[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Senthil Kumaran added the comment:


New changeset cb1e002c07622e027e80a3843d27a623d1617430 by Senthil Kumaran in 
branch '3.6':
bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) (#985)
https://github.com/python/cpython/commit/cb1e002c07622e027e80a3843d27a623d1617430


--

___
Python tracker 

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



Version 2 of my natural language steganographical scheme released

2017-04-03 Thread Mok-Kong Shen


Version 2 of my natural language steganographical scheme 
WORDLISTTEXTSTEGANOGRAPHY
is available on my home page http://mokkong-shen.privat.t-online.de , 
together with

a few other cryptological and steganographical software of mine. See update
notes in it for the differences to earlier versions. I regret that in 
the earlier
versions a sentence was unfortunately missing in the explanation of how 
to do the
examples, with the consequence that new users might have difficulties 
with the

examples.

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Thank you Nate, for all these sources to study. Python was very easy for
me to learn in 2 online courses, but it's been all uphill since then.
I've learned a lot and for that I'm grateful, but there's so much
farther to go.

I've appreciated our discussions, but I am in fact a very sick person
and my illness has come back again tonight. I can probably reply to a
few more posts and then you won't see me again for awhile.

But many thanks again, and I will begin reading the material you
suggested.

Deborah


Nathan Ernst wrote, on Monday, April 03, 2017 3:37 PM

No worries, Deborah.


Python is by most measurements a relatively easy/simple language to
learn, but there are always the dusty corners. If you've not already, I
recommend going through the online Python tutorial in it's entirety
(https://docs.python.org/3/tutorial/index.html).


After that, learn the language syntax that wasn't covered in the
tutorial by reading the Language Reference
(https://docs.python.org/3/reference/index.html). The tutorial should be
fairly easy for a straight beginner to follow. The language reference
assumes a little higher-level understanding of programming language
grammar.  The Python Language Reference uses a modified BNF syntax (BNF
being Backus-Naur form. You can read about BNF at
https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form). To be honest,
I'm not sure what modifications Python uses to BNF, maybe someone else
can shed some light (or skin) on it.


After you'd done those, peruse the standard library. I don't recommend
deep reading there at this point, but at least a cursory reading so
you're cognizant of libraries that are built-in that may help do things
may you want to do now, or in the future (i.e. make a web request, parse
JSON or XML, handle datetimes).


Remember: Python comes with batteries included.


-Nate


On Mon, Apr 3, 2017 at 5:09 PM, Deborah Swanson
 wrote:

Nathan Ernst wrote, on April 03, 2017 1:59 PM
>
> I was a bit surprised when I looked at the language reference
> for 3.6.x. I expected there'd be a direct link to
> comprehensions, but there's not.
>
> You have to know what you're looking for:
>
> 6.2.5: List Displays
> 6.2.6: Set Displays
> 6.2.7: Dictionary Displays
>
> And, then, click on the appropriate element of the sub
> grammar to find the appropriate syntax.
>
> So, it took me about 30 seconds to find the appropriate
> grammars, when I expected it'd only take about 5 seconds,
> since I'm very familiar with the python docs & how the
> grammar documentation is laid out.  I can fully understand
> how someone less familiar with the documentation might have a
> harder time finding the grammar than I did.
>
> FWIW, If one was completely new to Python, even knowing the
> syntax is known as a "comprehension" might be unknown. I
> certainly didn't know what a comprehension was when I was
> learning Python. A coworker showed me, some 13 years ago.
>
> Regards,
> Nate

Thanks Nate, for your comprehension of the plight of many, if not most,
newish Python coders. And it certainly doesn't help to ask the list to
fill in some of the holes and be met with criticism for asking, but I
digress. It is what it is.

Before I started reading the list a few months ago, I'd heard of list
comprehensions in an article I'd read, and hardly understood the gist of
it. But look at me now Ma, I've learned not only how to use list
comprehensions but also a small tribe of other kinds of comprehensions!

(If there's a moral to this story, heck if I know exactly what it is.
"Keep on trying" is as good as any.)

Deborah


> On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill
>  wrote:
>
> > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson
> >  wrote:
> > > Regular updates as the docs are updated would be a good idea too.
> > > It's obvious that today's Google isn't up to it, although
> it occurs
> > > to me that I haven't tried Google's site search on python.org.
> >
> > So, when you search google for the phrase "dict comprehension" or
> > "dictionary comprehension", nothing useful comes up for
> you?  When I
> > search either of those phrases, I get lots of useful
> results, all of
> > which spell out how to do what you were originally asking about.  I
> > know Google search results are skewed by past usage, but
> I'm surprised
> > that you didn't find anything useful in the first couple of search
> > results.
> >
> > When I do a search for 'dict comprehension' I get a boxed result
> > linking to PEP 274 as the first hit, then two Stack Overflow
> > questions, both of which demonstrate how to do dictionary
> > comprehensions.  Following that is another link to PEP 274,
> a link to
> > the Python docs on data structures (which does talk about dict
> > comprehensions, but it's way down on the page), and then links to a
> > bunch of tutorials.  If you had to judge based on my search
> results,
> > Google does a fine job of answering python questions, 

[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Changes by Senthil Kumaran :


--
pull_requests: +1158

___
Python tracker 

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



[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Changes by Senthil Kumaran :


--
pull_requests: +1157

___
Python tracker 

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



[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Senthil Kumaran added the comment:


New changeset 02e12138000da834f23719521a011fa93763384d by Senthil Kumaran 
(csabella) in branch 'master':
bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947)
https://github.com/python/cpython/commit/02e12138000da834f23719521a011fa93763384d


--

___
Python tracker 

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



[issue29725] sqlite3.Cursor doesn't properly document "arraysize"

2017-04-03 Thread Senthil Kumaran

Senthil Kumaran added the comment:

Thanks for working on this.

row_factory seems to be another parameter that can be set in the Cursor object. 
https://github.com/python/cpython/blob/master/Modules/_sqlite/cursor.c#L65 

This can addressed in a different issue/ pr.

--
nosy: +orsenthil

___
Python tracker 

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



[issue29976] urllib.parse clarify what ' ' in schemes mean

2017-04-03 Thread Senthil Kumaran

Senthil Kumaran added the comment:

https://github.com/python/cpython/pull/984 proposes a change. I'll need some 
reviews on this changed text.

Note: I am aware that there is an issue (long pending), which suggests deal 
away with these schemes at the top.  If we get to that immediately, I will be 
happy, if not, consider this PR as the improvement over the status quo.

--

___
Python tracker 

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



[issue29974] typing.TYPE_CHECKING doc example is incorrect

2017-04-03 Thread Jelle Zijlstra

Jelle Zijlstra added the comment:

The example is actually correct; I just confirmed by running it in my shell. 
Type annotations on local variables are not evaluated at runtime; see PEP 526.

--
nosy: +Jelle Zijlstra

___
Python tracker 

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



[issue29976] urllib.parse clarify what ' ' in schemes mean

2017-04-03 Thread Senthil Kumaran

New submission from Senthil Kumaran:

urllib.parse has the following information in this module.

```
# A classification of schemes ('' means apply by default)
uses_relative = ['ftp', 'http', 'gopher', 'nntp', 'imap',
 'wais', 'file', 'https', 'shttp', 'mms',
 'prospero', 'rtsp', 'rtspu', '', 'sftp',
 'svn', 'svn+ssh', 'ws', 'wss']

```

Note the '' in the list.

1) First it needs to be first one for easy identification.
2) It needs to be clarified. '' means apply by default does not help the reader.

--
assignee: orsenthil
messages: 291100
nosy: orsenthil
priority: normal
severity: normal
stage: needs patch
status: open
title: urllib.parse clarify what ' ' in schemes mean
type: behavior
versions: 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



[issue29975] Issue in extending documentation

2017-04-03 Thread Roundup Robot

Changes by Roundup Robot :


--
pull_requests: +1156

___
Python tracker 

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



Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread eryk sun
On Tue, Apr 4, 2017 at 1:45 AM, Dennis Lee Bieber  wrote:
>
> C:\Users\Wulfraed>assoc .py
> .py=Python.File
>
> C:\Users\Wulfraed>ftype python.file
> python.file="C:\Python27\python.exe" "%1" %*

The Windows shell stores the user file-association choice in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice.
The cmd shell's assoc and ftype commands only modify a subset of
system associations in HKLM\Software\Classes. If keys with the same
names exist in HKCU\Software\Classes (e.g. Python and the launcher
were installed just for the current user), they will override the
system associations. Moreover, the user may be using a totally
different ProgId -- usually due to misconfiguration, which is
unfortunately all too common of a problem.

A couple of common misconfigurations are
HKCU\Software\Classes\py_auto_file and
HKCU\Software\Classes\Applications\python.exe. These get created
automatically by the Windows shell, and will almost always have a
broken "open" command that doesn't pass command-line arguments. By
using these ProgIds you're also missing the new drop handler that
Steve Dower wrote to support dropping files with non-ANSI names. It's
best to switch back to using Python.File, Python.NoConFile and
friends.

The UserChoice key is doubly secured via its "Hash" value plus a
security descriptor that prevents the current user from modifying
values in the key. This is to prevent direct modification. The most
you can do in code is to delete the key to have the shell reset from
defaults. By design, the only way to directly change the user choice
is via the GUI. Use the Control Panel's "Default Programs" app. Select
"Associate a filetype or protocol...". Type ".py" to advance in the
list, double-click on the entry, and select the app to use. If
Python.File is configured to use the launcher, the "Python" entry in
this application list should have an icon with a rocket on it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Appending data to a json file

2017-04-03 Thread Michael Torrie
On 04/03/2017 08:59 PM, Dave wrote:
> I created a python program that gets data from a user, stores the data 
> as a dictionary in a list of dictionaries.  When the program quits, it 
> saves the data file.  My desire is to append the new data to the 
> existing data file as is done with purely text files.  However, I can't 
> find a way to do that.  The advice I have seen on the web is to load the 
> data when the program starts, append the new user input to the list, 
> then re-write the data file.  Is that the best way, or is there a better 
> way?

If you're talking about a plain text file, can't you just open the file
for append mode and write away to it?

f = open("file","at")
with f:
   f.write("More text.\n")


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


Re: Two variable dictionary comprehension

2017-04-03 Thread Jerry Hill
On Mon, Apr 3, 2017 at 5:50 PM, Deborah Swanson
 wrote:
> Ah, but did you actually try to use the proposed solutions on the two
> stackoverflow pages? It's been several weeks now, but I did, and neither
> of those two examples fit my situation, which is why I ended up writing
> my own, and unsatisfactorily at that.

Well, that first Stack Overflow link has the following as the first
part of the highest scored answer:

  In Python 2.6 and earlier, the dict constructor can receive an
iterable of key/value pairs:
  d = dict((key, value) for (key, value) in iterable)

  From Python 2.7 and 3 onwards, you can just use the dict
comprehension syntax directly:
  d = {key: value for (key, value) in iterable}

Isn't that second form the exact thing you were looking for, back in
your first post?

> I'm sorry you think the current edition of Google does such a fine job.
> Has it really been that many years ago that the results Google returned
> from a  properly formatted boolean search were really useful? I'd
> imagine that the old Google would have returned a good 10 pages or more
> (probably a lot more) of urls containing the phrase "dict comprehension"
> or "dictionary comprehension". in which you'd find a rich variety of
> specific situations to glean through. (You wouldn't have needed to
> include "python" in the search phrase, since no other programming
> language that I know of, or other English usage for that matter, has
> dict comprehensions.)

Is this not your experience today?  I just browsed through the first 5
pages of search results for the phrase "dict comprehension" (without
the quotes), and the results seem to be pretty on point.  It's mostly
results talking about python dict comprehensions, general python pages
talking about all sorts of comprehensions (dict, list, and set), and
as you get deeper into the result pages, you start to see some entries
for the word "comprehension" in dictionaries too, which seems like a
reasonable thing to end up mixed in with the desired results.  It goes
on in that vein out to page 11 or so, at which point things seem to
devolve a bit.

I'd be totally sympathetic with your plight if you didn't know the key
phrase 'dict comprehension' to find all of that information.  I'm just
not seeing the poor results you seem to be getting from Google once
you know the term.

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-03 Thread Rick Johnson
On Sunday, April 2, 2017 at 3:49:43 PM UTC-5, Gene Heskett wrote:
> On Sunday 02 April 2017 12:26:40 Steve D'Aprano wrote:
> > On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:
> > > On 4/1/2017 12:00 PM, Steve D'Aprano wrote:
> > > > 
> > > > example of the Ugly American.
> > > 
> > > As an American I resent your promotion and perpetuation
> > > of an ugly ethno-centric stereotype.
> >
> > I'm glad you didn't try to describe it as a *unfair* or
> > *unjustified* stereotype, because (let's face it) after
> > November 8th 2016, that simply wouldn't fly.
> 
> While I too detest that label, I will have to admit that I
> am one of the conservatives, believing our Constitution and
> Bill of Rights have been used as TP by the "establishment"
> over the last 65+ years, who enabled that surprise. 

Saying what you just said, in _this_ group at least, can
bring some nasty rebukes. And not because it is wrong, no,
but because the proggie-bots will accuse you of being (1) a
racist opining for the return of slavery, (2) a homophobic
who would throw people from rooftops, (3) a bigot, (4)
something else that is equally "bad", or (5) all of the
above.

Hopefully though, like me, you're undeterred by lies and
slander because your skin is thicker than that of the
average grape. As for me, i do not want america society to
return to 1950, no, i want to american _ideals_ to return to
July 4, 1776. And this time we would: "get it right". The
first order of business would be to re-write the
constitution in a manner that will remove the subtle
semantical errors that have caused so much trouble for these
last 200+ years. Starting with the Declaration of
Independence. 

(emphasis *MINE*!)

  "When in the course of human events, it becomes
  *NECESSARY* for one people to dissolve the political bands
  which have connected them with another, and to assume
  among the powers of the earth the *SEPARATE* and *EQUAL*
  station to which the laws of nature and of [the natural
  processes that] *ENTITLE* them, a decent respect to the
  [reputation] of [humankind] requires that they should
  declare the causes which impel them to the separation."
  
  "We hold these truths to be self-evident, that all
  [people] are created equal, that they are endowed by their
  [existence] with certain unalienable rights: that among
  these are life, liberty and the pursuit of happiness. --
  that to *SECURE* these rights, governments are instituted
  among [people], deriving their just powers from the
  *CONSENT* of the governed, -- That whenever any form of
  government becomes destructive of these ends, it is the
  *RIGHT* of the people to alter or to abolish it, and to
  institute new government, laying its foundation on such
  *PRINCIPLES* and organizing its powers in such *FORM*, as
  to them shall seem most likely to effect their safety and
  happiness."
  
  "Prudence, indeed, will dictate that governments long
  established should *NOT* be changed for _light_ and
  _transient_ causes; and accordingly, all experience hath
  shewn, that [humankind] are more disposed to suffer while
  evils are "sufferable", than to right themselves by
  abolishing the forms to which they are "accustomed". But
  when a *LNG* train of abuses and usurpations pursuing
  invariably the same [*GOALS* -- to achieve an absolute
  despotism --], it is their *RIGHT*, it is their *DUTY*, to
  throw off such government and to provide new guards for
  their future security. -- Such has been the patient
  sufferance of these [people]; and such is now the
  *NECESSITY* which constrains them to alter their former
  systems of government. The history of the present [United
  States Of America] is a history of repeated injuries and
  usurpations [-- and quite frankly, a charade of vile
  hypocrisy! --], all having in direct object the
  establishment of an absolute tyranny over these [people].
  To prove this, let facts be submitted to a candid world."

  [List of modern grievances snipped for bandwidth]
  

Simply removing all the misogynist references and
patriarchal terms is a good start. But what is important to
realize, is that, removing these mistakes does not undermine
the intent of this document, no, it merely broadens and
purifies that intent. The fact is, this document has caused
a social transformation that has reverberated around the
world.

(Rhetorically i ask...)

What _is_ "life, liberty, and the pursuit of happiness"? 

Is it merely the monotone words of a random child standing
on a random grade-school stage reenacting the events of our
forefathers for the sake of mere "cute spectacle"? Or is it
something more? -- I believe it be. -- I believe it to be
one of the most *PROFOUND* realizations of social justice
that the human mind has *EVER* conceived. A culmination of
many thousand years of trial and error, and the product of
much pain and suffering. The American Declaration Of
Independence marks an epoch in our collective human social
and intellectual 

[issue29975] Issue in extending documentation

2017-04-03 Thread Martin Panter

Martin Panter added the comment:

FWIW I don’t see any error in the first quote. “Should X happen, Y happens” is 
valid English. Though I admit this kind of grammar is not used that often.

If it is too hard to understand, it should be okay to change it to “If it 
becomes a danging pointer, . . .”.

[become → becomes]

--
nosy: +martin.panter

___
Python tracker 

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



Appending data to a json file

2017-04-03 Thread Dave
I created a python program that gets data from a user, stores the data 
as a dictionary in a list of dictionaries.  When the program quits, it 
saves the data file.  My desire is to append the new data to the 
existing data file as is done with purely text files.  However, I can't 
find a way to do that.  The advice I have seen on the web is to load the 
data when the program starts, append the new user input to the list, 
then re-write the data file.  Is that the best way, or is there a better 
way?


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


[issue29975] Issue in extending documentation

2017-04-03 Thread Namjun Kim

New submission from Namjun Kim:

https://docs.python.org/3.7/extending/extending.html

"Should it become a dangling pointer, C code which raises the exception could 
cause a core dump or other unintended side effects."

The typo error in this sentence.

"If it become a dangling pointer, C code which raises the exception could cause 
a core dump or other unintended side effects."

fix the typo error.

--
assignee: docs@python
components: Documentation
messages: 291098
nosy: Namjun Kim, docs@python
priority: normal
severity: normal
status: open
title: Issue in extending documentation
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



[issue29968] Document that no characters are allowed to proceed \ in explicit line joining

2017-04-03 Thread Martin Panter

Martin Panter added the comment:

I think he means make something like the following legal, where dots (.) 
indicate space characters:

a.=.\.
b

At the moment it is a SyntaxError:

>>> a = \ 
  File "", line 1
a = \ 
 ^
SyntaxError: unexpected character after line continuation character

I don’t think it is worthwhile changing that.

--
nosy: +martin.panter

___
Python tracker 

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



Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 10:13 AM, Rick Johnson
 wrote:
> D'Aprano, are you still stewing because Donald J Trump
> spanked Hillary's jumbo sized bottom like an unruly
> stepchild? You poor widdle partisian hack. I almost feel
> sorry for you.
>
> [snip massively long political rant]

Alright, can the politics please be taken off list? I believe the
appropriate newsgroup for this drivel is comp.lang./dev/null.

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


[issue29974] typing.TYPE_CHECKING doc example is incorrect

2017-04-03 Thread Berker Peksag

Changes by Berker Peksag :


--
stage:  -> patch review
type: enhancement -> behavior
versions:  -Python 3.4

___
Python tracker 

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



Re: Two variable dictionary comprehension

2017-04-03 Thread Larry Martell
On Mon, Apr 3, 2017 at 8:24 PM Dennis Lee Bieber 
wrote:

> On Mon, 3 Apr 2017 11:48:38 -0700, "Deborah Swanson"
>  declaimed the following:
>
> >But, if Larry Page and Sergey Brin could tinker around in their dorm
> >rooms (or wherever they lived then) and they made the first Google (the
> >first search engine?) to boolean search the World Wide Web, it shouldn't
> >be so awfully hard to make a collection of Python docs that's boolean
> >searchable.



> >>Alta Vista predated Google by a few years (it was later absorbed by
> Yahoo).


Don't  forget Ask Jeeves

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


RE: Two variable dictionary comprehension

2017-04-03 Thread Steve D'Aprano
On Tue, 4 Apr 2017 03:27 am, Deborah Swanson wrote:

> I'll admit that both dictionaries and comprehensions are still a little
> bit fuzzy to me, especially when I get away from the common usages. This
> could be a good exercise to clarify some of the fuzzy areas.


As far as comprehensions go, how is your mathematics?

If you remember your set builder notation from maths, list comprehensions
are based on that.

In maths, we say something like:

{2n + 1 : 0 ≤ n ≤ 9}

which might be read aloud as "the set of 2 times n, plus 1, such that n is
between 0 and 9 inclusive".

http://www.mathwords.com/s/set_builder_notation.htm

A similar notation might be:

{2n + 1 : n ∈ {1, 2, 3}}

said as "the set of 2 times n, plus 1, such that n is an element of the set
{1, 2, 3}".


If you're a maths geek like me, this is second nature :-)


Now, Python's list comprehension syntax is based on a similar notation,
except we spell it out in words rather than symbols, using the
familiar "for n in ..." syntax from for-loops instead of : "such that".

{2*n + 1 for n in range(10)}

{2*n + 1 for n in (1, 2, 3)}


A few other differences:

- list comprehensions use [ ] for the outermost brackets;
- set and dict comprehensions use { };
- generator expressions use ( ) (unless the parentheses can be implied).

We're not restricted to mathematical expressions, and can use any Python
expression we like:

[value.method(arg)[1] for (value, arg) in zip(values, arguments)]


translates roughly into this for-loop:

result = []
for (value, arg) in zip(values, arguments):
result.append(value.method(arg)[1])



Another difference is that comprehensions allow an "if" clause:

[v.method(a)[1] for (v, a) in zip(values, arguments) if v is not None]

translates something like:


result = []
for (v, a) in zip(values, arguments):
if v is not None:
result.append(v.method(a)[1])


There's more, but that covers probably 98% of comprehension usage.

And of course, remember that dict comprehensions use the same key:value
syntax as ordinary dict "literals" (the official name is "dict display").

result = {}
for key, value in zip(keys, values):
result[key] = value


becomes

result = {key:value for (key, value) in zip(keys, values)}

although frankly that's better written as:

dict(zip(keys, values))



Hope this helps!




-- 
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: Text-mode apps (Was :Who are the "spacists"?)

2017-04-03 Thread Mark -

On Sunday, April 2, 2017 at 11:26:50 AM UTC-5, Steve D'Aprano wrote:


On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:


On 4/1/2017 12:00 PM, Steve D'Aprano wrote:


example of the Ugly American.


As an American I resent your promotion and perpetuation of an ugly
ethno-centric stereotype.


I'm glad you didn't try to describe it as a *unfair* or *unjustified*
stereotype, because (let's face it) after November 8th 2016, that
simply wouldn't fly.


D'Aprano, are you still stewing because Donald J Trump spanked




Hear hear


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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-03 Thread Rick Johnson
On Sunday, April 2, 2017 at 11:26:50 AM UTC-5, Steve D'Aprano wrote:
> On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:
> > On 4/1/2017 12:00 PM, Steve D'Aprano wrote:
> > 
> > > example of the Ugly American.
> > 
> > As an American I resent your promotion and perpetuation of
> > an ugly ethno-centric stereotype.
> 
> I'm glad you didn't try to describe it as a *unfair* or
> *unjustified* stereotype, because (let's face it) after
> November 8th 2016, that simply wouldn't fly.

D'Aprano, are you still stewing because Donald J Trump
spanked Hillary's jumbo sized bottom like an unruly
stepchild? You poor widdle partisian hack. I almost feel
sorry for you.

Heck, Trump has to be the most crass and unstatesmanlike
candidate to ever run for the american presidency -- well,
certainly in my lifetime -- so it should have been the
surest win in history for Hillary (or should i say "HER-"?),
but even with the mainstream media planted firmly in her
pocket; Bill Clinton's endless charms; a grotesque
prosession of hollywood celebs, and Obama on the campaign
trail -- she folded like lawn chair! How pathetic. Not to
mention that the democratic party cheated Burnie Sanders. (i
wonder if he's "feelin' the burn"?)

Of course, in their hubris, the Dems put all their chips on
the same old tired "game of firsts" crapola, thinking the
emotional sleight of hand was enough to clinch them the
white house, but fortunately (for america), somebody at the
DNC forgot to tell the Dem leaders that america is getting
*SICK* and *TIRED* of the emotional games.

We only want two types of candidates now: (1) those who are
highly qualified non-partisans, or (2) those who will burn
the old orders to the ground! With Trump, we got the latter.
But as bad a Trump is, he's better than the "business as
usual" we get from Repuke-I-Cans and Demon-Rats.

But Steven, you're not even an american are you? Nope!
You're just another Brit with a stick jambed firmly up his
butt waddling around lecturing Americans about how terrible
we are, but have you ever stopped to consider your own
nation's horrendous history?

  TIP OF THE DAY: "Great Britain" is the imperialist empire
  previously known as "England".

Now sod-off to your local library so you can catch up on,
say, the last umpteen centuries of English tyranny and
global colonization. Oh, and, please note that people who
live in glass houses would be wise not to start a stone
throwing war. just FYI, old buddy. *wink*

> Not all Americans, perhaps not even a majority or a
> plurality, are Ugly Americans, but there are enough of them
> to screw it up for everyone else.

There are bad apples in every bunch; every nation; every
group. Stupidity and ignorance are ubiquitous traits and are
fairly evenly distributed around the globe. So enough with
America bashing already. We Americans are no more guilty of
hate and intolerance than any other nation or peoples on
this planet. Heck, we've only existed for just over 200
years, yet many polmics and media types would have the world
believe that hate and intolerance didn't exist in this
universe until July 4, 1776.

And when has _any_ reigning power in human history ever
acted in a 100% benevolent manner? Hmm? (At least, any one
that matters, that is). If we read our history books, we
would come to the conclusion that tyranny is the natural
order of our human society, and, more evidence of universal
laws in action. Therefore, only through perpetual conflict
can we keep tyranny at bay. For instance, it's not as if we
could tell ol' Henry the Eighth: "You know what Henry... you
can be a real horse's arse!" -- to which he would
"supposedly" reply -- "Indeed. I think i am. And uh, thank
you for the healthy criticism" -- NOT! It is more likely
that anyone who dared critize the king would win a free all-
expense-paid trip to the tower of London, a most horrific
place with a most notorious reputation for cruelty. But the
English had quite a knack for cruelty, eh Steven? Hmm,
remind me again, ol' boy, how many wives did King Henry the
VIII have executed for their "supposed" infidelity? Of
course, there are rumours that one of the executions did not
go as "cleanly" as planned. My observation is that the
botched nature of that execution was a feature, not a bug.
But depravity has been the SOP for centuries in "Merry ol'
England", eh chap?

> It's an ugly stereotype, not because it is a stereotype,
> but because it embodies a set of ugly attitudes and
> behaviours.

Your feeble attempts to legitimize your American bashing are
deplorable at best. For once in your life, Steven, admit
that you're filled with hate and apologize for it. If you
don't like America, fine, don't come here. Is that so
difficult for you? *WHO* we elect and *HOW* we live our
lives is none of your damned business. Personally, i don't
give a monkey's toss who your prime minister is, or what
your pompous Queen wishes to have dipped in gold and
encrusted with diamonds. Personally i think your whole
system of 

Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 8:31 AM,   wrote:
> Hi Chris,
>
>Really! :) So I can type pip install requests at the prompt: C:\Program 
> Files\Python 2.7.12>pip install requests
>or at C:\>pip install requests
>
>And the modules would be installed either way?
>
>Sorry I am also a newbie at windows command line too.
>
> THANKS!!!

Correct! The Windows program search path means it'll find pip.exe (if
it doesn't, you'll get a wordy error that used to be called SYS1041),
and then pip itself looks in the registry and other places to figure
out where it should install things.

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-03 Thread Rick Johnson
On Saturday, April 1, 2017 at 9:32:17 PM UTC-5, MRAB wrote:
> Sometimes he mentions MUDs, sometimes he mentions Pike, but at least he 
> doesn't rant.

I have not even _begun_ to rant. Yet...

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


[issue29968] Document that no characters are allowed to proceed \ in explicit line joining

2017-04-03 Thread R. David Murray

R. David Murray added the comment:

I think you meant "the language reference" rather than "the devguide".  The 
sentence about the comment is redundant with the preceding line that says that 
the thing that results in a join is a physical line that ends with a backslash 
("that is not part of..."), which is a definitive statement that no characters 
may follow it.

So, I don't see any doc bug here, unless we want to delete that redundant 
statement about the comment because it is confusing.  But I doubt we want to do 
that, as some people will think that a comment is "the same as there being 
nothing" (despite the statement about "physical line") which it is not.

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



[issue29968] Document that no characters are allowed to proceed \ in explicit line joining

2017-04-03 Thread R. David Murray

R. David Murray added the comment:

I also have no idea what your comment about stripping white space is in 
reference to ;)

--

___
Python tracker 

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



Re: Two variable dictionary comprehension

2017-04-03 Thread Gregory Ewing

Deborah Swanson wrote:

I'd
imagine that the old Google would have returned a good 10 pages or more
(probably a lot more) of urls containing the phrase "dict comprehension"
or "dictionary comprehension".


It still does, as far as I can see. I just googled for "dict
comprehension", and the vast majority of results in the first
10 pages relate to Python.

By page 20 it's starting to wander off a bit, but you can
hardly blame it for that. There *are* non-Python web pages that
mention the words "dict" and "comprehension", and how is Google
to know that you don't want those if you don't tell it?


You used to be able to keep sifting through pages of results
after the bulk of urls fitting your criteria had passed, and still find
useful things to look at, sometimes at page 500


Seems to me Google was doing a rather *bad* job if you had
to wade through 500 pages of results to find what you wanted.
I would never have the patience to do that!

Anyhow, the reason Google got brought up was that you were
complaining about difficulty of finding things in the Python
docs. Google *does* turn up the relevant part of the docs in
the very first page of results, so being able to do a direct
text search on the docs wouldn't do any better.

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


Re: Two variable dictionary comprehension

2017-04-03 Thread Gregory Ewing

Deborah Swanson wrote:


But, if Larry Page and Sergey Brin could tinker around in their dorm
rooms (or wherever they lived then) and they made the first Google (the
first search engine?)


It wasn't the first web search engine. But it was the first
one that not only worked, but *kept* working as the web
grew bigger, and bigger, and bigger.

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


Re: Two variable dictionary comprehension

2017-04-03 Thread Gregory Ewing

Deborah Swanson wrote:

All my guesses were based on the
single variable (the most common type) examples I found. I just didn't
think of putting a colon after 'label', and found nothing to suggest
that's what I should do.


Hmmm, I'm not sure what the docs could do to make that any
clearer. The key:value syntax is part of *every* dict
comprehension (it's the only thing that distinguishes a
dict comprehension from a set comprehension).


Despite my earlier words and protestations that I did look for two
variable dict comprehensions, fairly diligently, I am taking what you
said seriously.


Don't feel too bad. Sometimes it's hard to know what to google
for, even for experienced people! Also it's hard for doc
writers to anticipate how less experienced people will
think. It wouldn't have occurred to me to use the phrase
"two variable dict comprehension" when writing documentation.

Another thing it's important to be able to do is see through
to the principles behind things, and then use those principles
to solve new problems that aren't explicitly covered in any
docs or examples.

The general principle behind all the forms of comprehension
is that they consist of a prototypical element, followed by
some clauses that generate values for that element.

The syntax for the prototypical element mirrors that of the
corresponding display. So, for a dict comprehension, the
prototypical element has the form 'key:value', where 'key'
and 'value' are arbitrary expressions. From there, it's just
a matter of figuring out what to put into those expressions.

In your case, another part of the puzzle is the fact that
you can unpack a tuple obtained from a for-loop into
variables. That's a general feature of for-loops, both
inside and outside of comprehensions, so you probably
won't find it mentioned explicitly under the heading of
dict comprehensions.


Maybe it
would be worthwhile to scrape the whole mess and have it in searchable
text form.


The HTML Python docs have a "Search" box, although I haven't
really used it so I don't know how well it works. In my experience,
Google with a site search often works a lot better than
search functions provided by sites themselves.


I hope you won't be miffed though if I still come up empty handed and
come back here to ask again.

Deborah


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


Re: Two variable dictionary comprehension

2017-04-03 Thread Gregory Ewing

Deborah Swanson wrote:


I'll admit that both dictionaries and comprehensions are still a little
bit fuzzy to me, especially when I get away from the common usages. This
could be a good exercise to clarify some of the fuzzy areas.


If you're fuzzy about dictionaries in general, it might be a
good idea to concentrate on that for now and come back to
comprehensions later. They're something of an advanced topic;
anything you can do with a comprehension can also be done
in more fundamental ways.

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


Re: Two variable dictionary comprehension

2017-04-03 Thread Nathan Ernst
No worries, Deborah.

Python is by most measurements a relatively easy/simple language to learn,
but there are always the dusty corners. If you've not already, I recommend
going through the online Python tutorial in it's entirety (
https://docs.python.org/3/tutorial/index.html).

After that, learn the language syntax that wasn't covered in the tutorial
by reading the Language Reference (
https://docs.python.org/3/reference/index.html). The tutorial should be
fairly easy for a straight beginner to follow. The language reference
assumes a little higher-level understanding of programming language
grammar.  The Python Language Reference uses a modified BNF syntax (BNF
being Backus-Naur form. You can read about BNF at
https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form). To be honest, I'm
not sure what modifications Python uses to BNF, maybe someone else can shed
some light (or skin) on it.

After you'd done those, peruse the standard library. I don't recommend deep
reading there at this point, but at least a cursory reading so you're
cognizant of libraries that are built-in that may help do things may you
want to do now, or in the future (i.e. make a web request, parse JSON or
XML, handle datetimes).

Remember: Python comes with batteries included.

-Nate

On Mon, Apr 3, 2017 at 5:09 PM, Deborah Swanson 
wrote:

> Nathan Ernst wrote, on April 03, 2017 1:59 PM
> >
> > I was a bit surprised when I looked at the language reference
> > for 3.6.x. I expected there'd be a direct link to
> > comprehensions, but there's not.
> >
> > You have to know what you're looking for:
> >
> > 6.2.5: List Displays
> > 6.2.6: Set Displays
> > 6.2.7: Dictionary Displays
> >
> > And, then, click on the appropriate element of the sub
> > grammar to find the appropriate syntax.
> >
> > So, it took me about 30 seconds to find the appropriate
> > grammars, when I expected it'd only take about 5 seconds,
> > since I'm very familiar with the python docs & how the
> > grammar documentation is laid out.  I can fully understand
> > how someone less familiar with the documentation might have a
> > harder time finding the grammar than I did.
> >
> > FWIW, If one was completely new to Python, even knowing the
> > syntax is known as a "comprehension" might be unknown. I
> > certainly didn't know what a comprehension was when I was
> > learning Python. A coworker showed me, some 13 years ago.
> >
> > Regards,
> > Nate
>
> Thanks Nate, for your comprehension of the plight of many, if not most,
> newish Python coders. And it certainly doesn't help to ask the list to
> fill in some of the holes and be met with criticism for asking, but I
> digress. It is what it is.
>
> Before I started reading the list a few months ago, I'd heard of list
> comprehensions in an article I'd read, and hardly understood the gist of
> it. But look at me now Ma, I've learned not only how to use list
> comprehensions but also a small tribe of other kinds of comprehensions!
>
> (If there's a moral to this story, heck if I know exactly what it is.
> "Keep on trying" is as good as any.)
>
> Deborah
>
> > On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill
> >  wrote:
> >
> > > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson
> > >  wrote:
> > > > Regular updates as the docs are updated would be a good idea too.
> > > > It's obvious that today's Google isn't up to it, although
> > it occurs
> > > > to me that I haven't tried Google's site search on python.org.
> > >
> > > So, when you search google for the phrase "dict comprehension" or
> > > "dictionary comprehension", nothing useful comes up for
> > you?  When I
> > > search either of those phrases, I get lots of useful
> > results, all of
> > > which spell out how to do what you were originally asking about.  I
> > > know Google search results are skewed by past usage, but
> > I'm surprised
> > > that you didn't find anything useful in the first couple of search
> > > results.
> > >
> > > When I do a search for 'dict comprehension' I get a boxed result
> > > linking to PEP 274 as the first hit, then two Stack Overflow
> > > questions, both of which demonstrate how to do dictionary
> > > comprehensions.  Following that is another link to PEP 274,
> > a link to
> > > the Python docs on data structures (which does talk about dict
> > > comprehensions, but it's way down on the page), and then links to a
> > > bunch of tutorials.  If you had to judge based on my search
> > results,
> > > Google does a fine job of answering python questions, at least when
> > > you already know the key phrase to look for.
> > >
> > > --
> > > Jerry
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread psmith36
On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote:
> Hi, 
> 
>   I am a newbie to Python.  I am using Python 2.7.12.  I want to install the 
> modules of requests and openpyxl using pip.  In the Internet, people only 
> said pip install requests, but they do not say in which directory.  I only 
> found one that said install in the script directory within Python. Well, that 
> didn't work.
> 
>   How and which directory in the command line to type pip install requests?
> 
> Thanks!
> Pauline

Hi Chris,

   Really! :) So I can type pip install requests at the prompt: C:\Program 
Files\Python 2.7.12>pip install requests
   or at C:\>pip install requests

   And the modules would be installed either way?

   Sorry I am also a newbie at windows command line too.

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


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Nathan Ernst
Hi Pauline,

I was able to infer you're on Windows, but not which version. Try
right-clicking on the start menu to start a command prompt as an
administrator (I'm not sure that was available in Windows 7, and I don't
have access to a Win7 box currently to verify). Failing that, you should be
able to find a shortcut to the command prompt somewhere under
Programs\Windows, Programs\Windows Accessories, or a like named folder.
Just keep looking, it's there. (the parent folder will be named Windows or
Programs - look through all subfolders until you find it). Once you find
it, right-click and select run as Administrator. Then, you should be able
to run the pip install command just fine.

If you cannot find Command Prompt for whatever reason, an alternate way is
to create a short cut on your desktop. Just right-click on your desktop.
Select New\Create Shortcut. When it asks you to select the location of the
file, just enter "cmd.exe".  Hit "next" until the dialog exits. Then,
right-click on the newly created shortcut and select "run as
administrator", then try your pip install command. Where you run the pip
command (i.e. current directory should not matter).

Regards

On Mon, Apr 3, 2017 at 5:14 PM,  wrote:

> On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote:
> > Hi,
> >
> >   I am a newbie to Python.  I am using Python 2.7.12.  I want to install
> the modules of requests and openpyxl using pip.  In the Internet, people
> only said pip install requests, but they do not say in which directory.  I
> only found one that said install in the script directory within Python.
> Well, that didn't work.
> >
> >   How and which directory in the command line to type pip install
> requests?
> >
> > Thanks!
> > Pauline
>
> Hi Nate,
>
>   Well, I didn't tell you I am on Windows 7.  When I went to cmd, it was
> C:\Users\myname.  Then I navigated to where my Python was installed
> C:\Program
> Files\Python 2.7.12>
>
>   Do I type pip install requests at the end of the arrow, or do I have to
> go somewhere else?
>
> Thanks a bunch!
> Pauline
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 8:14 AM,   wrote:
> Hi Nate,
>
>   Well, I didn't tell you I am on Windows 7.  When I went to cmd, it was 
> C:\Users\myname.  Then I navigated to where my Python was installed C:\Program
> Files\Python 2.7.12>
>
>   Do I type pip install requests at the end of the arrow, or do I have to go 
> somewhere else?
>
> Thanks a bunch!

Ah, this shouldn't matter. If you've installed Python and pip
correctly, you should be able to run them from any directory at all,
and they'll do their work correctly.

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


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread psmith36
On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote:
> Hi, 
> 
>   I am a newbie to Python.  I am using Python 2.7.12.  I want to install the 
> modules of requests and openpyxl using pip.  In the Internet, people only 
> said pip install requests, but they do not say in which directory.  I only 
> found one that said install in the script directory within Python. Well, that 
> didn't work.
> 
>   How and which directory in the command line to type pip install requests?
> 
> Thanks!
> Pauline

Hi Nate,

  Well, I didn't tell you I am on Windows 7.  When I went to cmd, it was 
C:\Users\myname.  Then I navigated to where my Python was installed C:\Program 
Files\Python 2.7.12>

  Do I type pip install requests at the end of the arrow, or do I have to go 
somewhere else?  

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


[issue29971] Lock.acquire() not interruptible on Windows

2017-04-03 Thread Eryk Sun

Eryk Sun added the comment:

Alternatively we could use the SleepEx and WaitFor*Ex functions with alertable 
waits (i.e. using APCs) instead of the SIGINT Event. This avoids having to 
replace all single-object waits with multiple-object waits, and would even 
allow calling SleepEx in pysleep. 

That said, issue 29871 proposes to switch to the condition variable and SRW 
lock implementation, so first it needs to be decided whether to continue to use 
kernel waits or switch to conditional variables. Or maybe refactor to use 
condition variables in performance-critical code and otherwise use kernel 
waits, if that makes sense.

An orthogonal improvement is to have the signal handler call 
CancelSynchronousIo. This would entail handling ERROR_OPERATION_ABORTED in 
_winapi Readfile, WriteFile, and WaitNamedPipe by calling PyErr_CheckSignals. 
Also in _Py_Read and _Py_Write, if errno is EINVAL and the last Windows error 
is ERROR_OPERATION_ABORTED, it could manually set errno to EINTR.

Winsock waits (e.g. select) will remain a problem in any case. Winsock uses 
alertable waits, so a queued user-mode APC will be executed while it's waiting. 
But then it just resumes its original wait instead of failing with WSAEINTR.

--

___
Python tracker 

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



RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Nathan Ernst wrote, on April 03, 2017 1:59 PM
> 
> I was a bit surprised when I looked at the language reference 
> for 3.6.x. I expected there'd be a direct link to 
> comprehensions, but there's not.
> 
> You have to know what you're looking for:
> 
> 6.2.5: List Displays
> 6.2.6: Set Displays
> 6.2.7: Dictionary Displays
> 
> And, then, click on the appropriate element of the sub 
> grammar to find the appropriate syntax.
> 
> So, it took me about 30 seconds to find the appropriate 
> grammars, when I expected it'd only take about 5 seconds, 
> since I'm very familiar with the python docs & how the 
> grammar documentation is laid out.  I can fully understand 
> how someone less familiar with the documentation might have a 
> harder time finding the grammar than I did.
> 
> FWIW, If one was completely new to Python, even knowing the 
> syntax is known as a "comprehension" might be unknown. I 
> certainly didn't know what a comprehension was when I was 
> learning Python. A coworker showed me, some 13 years ago.
> 
> Regards,
> Nate

Thanks Nate, for your comprehension of the plight of many, if not most,
newish Python coders. And it certainly doesn't help to ask the list to
fill in some of the holes and be met with criticism for asking, but I
digress. It is what it is.

Before I started reading the list a few months ago, I'd heard of list
comprehensions in an article I'd read, and hardly understood the gist of
it. But look at me now Ma, I've learned not only how to use list
comprehensions but also a small tribe of other kinds of comprehensions!

(If there's a moral to this story, heck if I know exactly what it is.
"Keep on trying" is as good as any.)

Deborah

> On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill 
>  wrote:
> 
> > On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson 
> >  wrote:
> > > Regular updates as the docs are updated would be a good idea too. 
> > > It's obvious that today's Google isn't up to it, although 
> it occurs 
> > > to me that I haven't tried Google's site search on python.org.
> >
> > So, when you search google for the phrase "dict comprehension" or 
> > "dictionary comprehension", nothing useful comes up for 
> you?  When I 
> > search either of those phrases, I get lots of useful 
> results, all of 
> > which spell out how to do what you were originally asking about.  I 
> > know Google search results are skewed by past usage, but 
> I'm surprised 
> > that you didn't find anything useful in the first couple of search 
> > results.
> >
> > When I do a search for 'dict comprehension' I get a boxed result 
> > linking to PEP 274 as the first hit, then two Stack Overflow 
> > questions, both of which demonstrate how to do dictionary 
> > comprehensions.  Following that is another link to PEP 274, 
> a link to 
> > the Python docs on data structures (which does talk about dict 
> > comprehensions, but it's way down on the page), and then links to a 
> > bunch of tutorials.  If you had to judge based on my search 
> results, 
> > Google does a fine job of answering python questions, at least when 
> > you already know the key phrase to look for.
> >
> > --
> > Jerry
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Nathan Ernst
If you've installed into Program Files, then you're on Windows, and you've
installed for all users. Start a command prompt by right-clicking on the
start icon, then selecting "Command Prompt (Admin)". This should work on
Windows 8.x and Windows 10. Windows 7, you may need to navigate through
Programs to Windows System\Command Prompt (path might be different - may be
under Windows Accessories), then right-clicking on Command Prompt (Admin).
>From that prompt, you should be able to run "py pip install " and
install it site-wide (for all local users)

On Mon, Apr 3, 2017 at 4:36 PM,  wrote:

> On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote:
> > Hi,
> >
> >   I am a newbie to Python.  I am using Python 2.7.12.  I want to install
> the modules of requests and openpyxl using pip.  In the Internet, people
> only said pip install requests, but they do not say in which directory.  I
> only found one that said install in the script directory within Python.
> Well, that didn't work.
> >
> >   How and which directory in the command line to type pip install
> requests?
> >
> > Thanks!
> > Pauline
>
> Hi Nate,
>
>   Thank you for your prompt reply.  I am just installing it on my computer
> with administrative privileges. I think I can go into the command line, but
> then I do not know which directory to go to type:  pip install requests
>
>   If I have installed python 2.7.12 in the Program Files directory, and
> then there are many directories within the Python 2.7.12 directory, then
> which directory should I go to install the modules?
>
>   I think my situation is indeed very simple.
>
> Pauline
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Jerry Hill wrote, on April 03, 2017 1:48 PM
> 
> On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson 
>  wrote:
> > Regular updates as the docs are updated would be a good 
> idea too. It's 
> > obvious that today's Google isn't up to it, although it 
> occurs to me 
> > that I haven't tried Google's site search on python.org.
> 
> So, when you search google for the phrase "dict 
> comprehension" or "dictionary comprehension", nothing useful 
> comes up for you?  When I search either of those phrases, I 
> get lots of useful results, all of which spell out how to do 
> what you were originally asking about.  I know Google search 
> results are skewed by past usage, but I'm surprised that you 
> didn't find anything useful in the first couple of search results.
> 
> When I do a search for 'dict comprehension' I get a boxed 
> result linking to PEP 274 as the first hit, then two Stack 
> Overflow questions, both of which demonstrate how to do 
> dictionary comprehensions.  Following that is another link to 
> PEP 274, a link to the Python docs on data structures (which 
> does talk about dict comprehensions, but it's way down on the 
> page), and then links to a bunch of tutorials.  If you had to 
> judge based on my search results, Google does a fine job of 
> answering python questions, at least when you already know 
> the key phrase to look for.
> 
> -- 
> Jerry

Ah, but did you actually try to use the proposed solutions on the two
stackoverflow pages? It's been several weeks now, but I did, and neither
of those two examples fit my situation, which is why I ended up writing
my own, and unsatisfactorily at that.

I'm sorry you think the current edition of Google does such a fine job.
Has it really been that many years ago that the results Google returned
from a  properly formatted boolean search were really useful? I'd
imagine that the old Google would have returned a good 10 pages or more
(probably a lot more) of urls containing the phrase "dict comprehension"
or "dictionary comprehension". in which you'd find a rich variety of
specific situations to glean through. (You wouldn't have needed to
include "python" in the search phrase, since no other programming
language that I know of, or other English usage for that matter, has
dict comprehensions.)

Nowadays Google just comes up with a mere handful of sorta appropriate
urls, and rarely do I find exactly what I'm looking for. And usually
there's nothing related to all your search terms after a page or two of
results. You used to be able to keep sifting through pages of results
after the bulk of urls fitting your criteria had passed, and still find
useful things to look at, sometimes at page 500 or even much, much
farther down the list. It really paid to comb through them all,
especially if you didn't find exactly what you wanted in the early
batch.

But giving users the choice among tens or hundreds of similar pages
(fewer if you specify 100 results per page) doesn't give Google as much
grist for the advertising mill to pump out at the users, hence the
present day useless mess.

Deborah

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


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread psmith36
On Monday, April 3, 2017 at 2:02:30 PM UTC-7, Pauline wrote:
> Hi, 
> 
>   I am a newbie to Python.  I am using Python 2.7.12.  I want to install the 
> modules of requests and openpyxl using pip.  In the Internet, people only 
> said pip install requests, but they do not say in which directory.  I only 
> found one that said install in the script directory within Python. Well, that 
> didn't work.
> 
>   How and which directory in the command line to type pip install requests?
> 
> Thanks!
> Pauline

Hi Nate, 

  Thank you for your prompt reply.  I am just installing it on my computer with 
administrative privileges. I think I can go into the command line, but then I 
do not know which directory to go to type:  pip install requests

  If I have installed python 2.7.12 in the Program Files directory, and then 
there are many directories within the Python 2.7.12 directory, then which 
directory should I go to install the modules?

  I think my situation is indeed very simple.

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


Re: Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Nathan Ernst
Hi Pauline,

It depends largely on whether you want to (and have sufficient permissions)
to install for all users or just yourself.

If, on *nix, you're installing site-wide (for all users), typically you'd
do: "sudo pip install " (for python 2) or "sudo pip3 install
" (for python 3).  If you're installing it for yourself, you may
need to add the --prefix= option. Typically,  would be somewhere
under your home directory. This can be problematic, as you may need to edit
the PYTHONPATH (and possibly LD_LIBRARY_PATH) to point to appropriate
directories. In this case, you're probably better of setting up a virtual
environment. See:
http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/. With
virtualenvs, you can setup a per user/project python configuration.

If you're on Windows, you should be able to "py pip install ", and
that will install it for you. If you run under and adminstrator cmd prompt
& python has been installed for all users, I *think* the module will be
available for everyone.

Hope this helps.

Regards,
Nate

On Mon, Apr 3, 2017 at 4:02 PM, Pauline  wrote:

> Hi,
>
>   I am a newbie to Python.  I am using Python 2.7.12.  I want to install
> the modules of requests and openpyxl using pip.  In the Internet, people
> only said pip install requests, but they do not say in which directory.  I
> only found one that said install in the script directory within Python.
> Well, that didn't work.
>
>   How and which directory in the command line to type pip install requests?
>
> Thanks!
> Pauline
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Which directory should requests and openpyxl modules be installed to?

2017-04-03 Thread Pauline
Hi, 

  I am a newbie to Python.  I am using Python 2.7.12.  I want to install the 
modules of requests and openpyxl using pip.  In the Internet, people only said 
pip install requests, but they do not say in which directory.  I only found one 
that said install in the script directory within Python. Well, that didn't work.

  How and which directory in the command line to type pip install requests?

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


Re: Two variable dictionary comprehension

2017-04-03 Thread Nathan Ernst
I was a bit surprised when I looked at the language reference for 3.6.x. I
expected there'd be a direct link to comprehensions, but there's not.

You have to know what you're looking for:

6.2.5: List Displays
6.2.6: Set Displays
6.2.7: Dictionary Displays

And, then, click on the appropriate element of the sub grammar to find the
appropriate syntax.

So, it took me about 30 seconds to find the appropriate grammars, when I
expected it'd only take about 5 seconds, since I'm very familiar with the
python docs & how the grammar documentation is laid out.  I can fully
understand how someone less familiar with the documentation might have a
harder time finding the grammar than I did.

FWIW, If one was completely new to Python, even knowing the syntax is known
as a "comprehension" might be unknown. I certainly didn't know what a
comprehension was when I was learning Python. A coworker showed me, some 13
years ago.

Regards,
Nate

On Mon, Apr 3, 2017 at 3:47 PM, Jerry Hill  wrote:

> On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson
>  wrote:
> > Regular updates as the docs are updated would be a good idea too. It's
> > obvious that today's Google isn't up to it, although it occurs to me
> > that I haven't tried Google's site search on python.org.
>
> So, when you search google for the phrase "dict comprehension" or
> "dictionary comprehension", nothing useful comes up for you?  When I
> search either of those phrases, I get lots of useful results, all of
> which spell out how to do what you were originally asking about.  I
> know Google search results are skewed by past usage, but I'm surprised
> that you didn't find anything useful in the first couple of search
> results.
>
> When I do a search for 'dict comprehension' I get a boxed result
> linking to PEP 274 as the first hit, then two Stack Overflow
> questions, both of which demonstrate how to do dictionary
> comprehensions.  Following that is another link to PEP 274, a link to
> the Python docs on data structures (which does talk about dict
> comprehensions, but it's way down on the page), and then links to a
> bunch of tutorials.  If you had to judge based on my search results,
> Google does a fine job of answering python questions, at least when
> you already know the key phrase to look for.
>
> --
> Jerry
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two variable dictionary comprehension

2017-04-03 Thread Jerry Hill
On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swanson
 wrote:
> Regular updates as the docs are updated would be a good idea too. It's
> obvious that today's Google isn't up to it, although it occurs to me
> that I haven't tried Google's site search on python.org.

So, when you search google for the phrase "dict comprehension" or
"dictionary comprehension", nothing useful comes up for you?  When I
search either of those phrases, I get lots of useful results, all of
which spell out how to do what you were originally asking about.  I
know Google search results are skewed by past usage, but I'm surprised
that you didn't find anything useful in the first couple of search
results.

When I do a search for 'dict comprehension' I get a boxed result
linking to PEP 274 as the first hit, then two Stack Overflow
questions, both of which demonstrate how to do dictionary
comprehensions.  Following that is another link to PEP 274, a link to
the Python docs on data structures (which does talk about dict
comprehensions, but it's way down on the page), and then links to a
bunch of tutorials.  If you had to judge based on my search results,
Google does a fine job of answering python questions, at least when
you already know the key phrase to look for.

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


[issue29964] %z directive has no effect on the output of time.strptime

2017-04-03 Thread Brett Cannon

Brett Cannon added the comment:

There's actually a footnote pointing out that %z is not supported by all libc 
implementations: https://docs.python.org/3/library/time.html#id2. Probably 
adding a note for %z in the strftime() table would be good.

--
nosy: +brett.cannon

___
Python tracker 

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



Request Help With pkexec

2017-04-03 Thread Wildman via Python-list
Python 3.4.2
Tkinter 8.6
GCC 4.9.1 on Linux

I am working on a gui program using Tkinter. The program will
have a feature to restart as root.  I am testing different gui
front-ends from a terminal to raise privileges and I want to
be able to use as many as possible for obvious reasons.  Gksu,
kdesudo and su-to-root all work perfectly.  However, I have a
problem with pkexec.  Here is the command I am using from a
terminal:

$ pkexec python3 /home/user/Python/linfo-tk/linfo-tk.py

I get this error:

Traceback (most recent call last):
  File "/home/user/Python/linfo-tk/linfo-tk.py", line 455, in 
root = tk.Tk()
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, 
wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

The display environment variable is set:

$ echo $DISPLAY
:0.0

And the program displays and works perfectly in every other way.
I would appreciate any insight.

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error

2017-04-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Can this be closed now?

--

___
Python tracker 

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



[issue29897] itertools.chain behaves strangly when copied with copy.copy

2017-04-03 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> Perhaps all this deserves a PEP.

If Serhiy and Kristján are on a course of action, that will suffice.  Copying 
iterators is an esoteric endeavor of interest to very few users (no one has 
even noticed until now).

--

___
Python tracker 

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



RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Rob Gaddi wrote, on April 03, 2017 10:38 AM
> 
> On 04/03/2017 10:27 AM, Deborah Swanson wrote:
> > Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM
> >>
> >> On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson" 
> >>  declaimed the following:
> >>
> >>>
> >>> Clearly there's more to be found in nooks, crannies and byways in
the
> >>> docs than you'll get to from the given pointers in the index.
Maybe it
> >>> would be worthwhile to scrape the whole mess and have it in
searchable
> >>> text form. Another thing Python would be the right tool for the
job 
> >>> for. Regular updates as the docs are updated would be a good idea
too.
> >>> It's obvious that today's Google isn't up to it, although it
occurs to
> >>> me that I haven't tried Google's site search on python.org.
> >>>
> >>On Windows, the (at least, for ActiveState releases)
documentation 
> >> is available in Windows Help format -- though I'll admit the "free 
> >> text search" leaves a lot to be desired...
> >>
> >>"dict comprehension" didn't find anything obvious; "dictionary 
> >> comprehension" brought up PEP 274 (note: I still use 2.7 as main 
> >> version).
> >>
> >> -=-=-=-=-=-
> >> Semantics
> >> The semantics of dict comprehensions can actually be
demonstrated
> >> in stock Python 2.2, by passing a list comprehension to the
> >> builtin dictionary constructor:
> >>
> >> >>> dict([(i, chr(65+i)) for i in range(4)])
> >>
> >> is semantically equivalent to
> >>
> >> >>> {i : chr(65+i) for i in range(4)}
> >>
> >> The dictionary constructor approach has two dictinct
disadvantages
> >> from the proposed syntax though.  First, it isn't as legible as
a
> >> dict comprehension.  Second, it forces the programmer to create
an
> >> in-core list object first, which could be expensive.
> >>
> >> -=-=-=-=-=-
> >> --
> >>Wulfraed Dennis Lee Bieber AF6VN
> >> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
> >
> > It would be interesting to play around with different list 
> > comprehensions than the one they've shown.
> >
> > I'll admit that both dictionaries and comprehensions are still a 
> > little bit fuzzy to me, especially when I get away from the common 
> > usages. This could be a good exercise to clarify some of the fuzzy 
> > areas.
> >
> > Deborah
> >
> 
> And don't forget
>dict_comp : { k:v for (k,v) in kv_provider }
>set_comp : { item for item in item_provider }
>set_of_tuples_comp : { (k,v) for (k,v) in kv_provider }
> 
> Just to make things more complicated.
> 
> -- 
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com 
> Email address domain is currently out of order.  See above to fix.

Added to my list of comprehension types, thank you.

I'm thinking it would also be good to include the PEPs in my searchable
Python reference. Just making the collection and browsing through it
would be highly instructive.

But, if Larry Page and Sergey Brin could tinker around in their dorm
rooms (or wherever they lived then) and they made the first Google (the
first search engine?) to boolean search the World Wide Web, it shouldn't
be so awfully hard to make a collection of Python docs that's boolean
searchable. 

I haven't seen a search method for text that comes anywhere near boolean
search's completeness in returning results (though I'm happy to take
suggestions).

Deborah


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


[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

You can use mo.group(1, 2). If you need to slice arbitrary groups, you can 
slice the result of the groups() method (which is just a tuple).

The re module is already complex, and let use existing API rather than add the 
new one.

--
resolution:  -> rejected
stage:  -> 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



[issue29971] Lock.acquire() not interruptible on Windows

2017-04-03 Thread Eryk Sun

Eryk Sun added the comment:

>From the linked issue:

> proc.send_signal(CTRL_C_EVENT) raises the KeyboardInterrupt
> in both the original and subprocess on Windows

GenerateConsoleCtrlEvent takes process group IDs, so it should have been used 
to implement os.killpg, not os.kill. If you call it on a process ID that's 
attached to the console that isn't also a group ID (i.e. the group leader), 
then it defaults to group 0, which includes every process that's attached to 
the console. 

Popen.send_signal should only send CTRL_C_EVENT or CTRL_BREAK_EVENT when the 
child process was created with CREATE_NEW_PROCESS_GROUP in its creationflags. 
Also, since kill() falls back on TerminateProcess, for added safety send_signal 
also needs to call poll() instead of using returncode because Windows reuses 
process IDs. Also, to avoid confusion, it should be noted that CTRL_C_EVENT 
will be ignored by a process in a new group unless said process manually 
enables Ctrl+C handling by calling SetConsoleCtrlHandler(NULL, FALSE). This 
setting will be inherited by child processes.

In the long run I think it would be better to clarify this by implementing 
os.killpg on Windows using GenerateConsoleCtrlEvent, with support for 
CTRL_C_EVENT, CTRL_BREAK_EVENT, SIGINT, and SIGBREAK. Deprecate using os.kill 
to send console control events. There is no Windows API to send a console 
control event to a particular process ID.

--
nosy: +eryksun

___
Python tracker 

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



[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Michael Selik

Michael Selik added the comment:

Sorry, it looks like I got the issue number wrong. My comparison should not 
have been with #24454, but instead with an issue I can't locate at the moment. 
Reproducing the example:

for g0, g1, g2 in re.finditer(r'(\d+)/(\d+)', 'Is 1/3 the same as 2/6?'):
ratio = Fraction(int(g1), int(g2))

Better:

for mo in re.finditer(r'(\d+)/(\d+)', 'Is 1/3 the same as 2/6?'):
ratio = Fraction(*map(int, mo[1:3]))

The map in the last one isn't very pretty, but I hope it illustrates the gist 
of what I'd like to do for a much larger pattern with many capture groups.

--

___
Python tracker 

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



OFF-TOPIC Bigotry on the list [was Re: Text-mode apps (Was :Who are the "spacists"?)]

2017-04-03 Thread Steve D'Aprano
On Mon, 3 Apr 2017 08:31 am, Terry Reedy wrote:

[...]
> I refrained because it would be off-topic and a diversion from my point:
> all bigotry is inappropriate here on this list, 

Indeed it is not appropriate. But calling out bigotry is not itself bigotry.

I hope you agree with that.

If not, that leaves you with some deeply Unfortunate Implications.

Suppose you are right, and merely calling out "Ranting Rick" for his bigoted
attitude makes me an anti-American bigot. Then by *you* calling *me* out
for bigotry, that makes you equally a bigot. And so the only way to avoid
being a bigot is... to do nothing in the face of bigotry.

I didn't see you calling out Rick for his prejudice against those who aren't
American, his absurd belief that "most" people are satisfied with ASCII, or
his claim that the rest of the world don't need file names in their native
languages because the "majority" (his word) of them are illiterate. Do you
think those attitudes should be left unchallenged?

(In fairness, Rick doesn't say that the *entire* rest of the world is mostly
illiterate. He only includes China, India, Russia, Japan, Indonesia,
Arab-speakers, and Israel. So a bit less than half the world.)


> including anti-Americanism.

When have I demonstrated prejudice against Americans merely for being
American?

I stand by my comment to Rick. It is *his behaviour and attitude* which
makes him an example of the stereotype, not the fact that he is an
American.

Of course all people are unique, and all stereotypes are incomplete. People
are not their stereotype, and I'm sure that Rick is a wonderful and unique
person in his own way. Perhaps he loves animals and donates his time to
working in shelters for the homeless.

But nevertheless people do behave in stereotypical ways, and we've seen Rick
do exactly that. Insensitive to cultural differences, dismissive of those
who aren't American, ignorant of everything outside of the borders of the
US, and arrogantly certain that the American way is not just the best way
but the only way. And *wilfully* so. This is not just an isolated incident
from Rick, a mere momentary lapse. He has been expressing these sorts of
attitudes for years.


> (I actually think raw bigoty is inappropriate everywhere.  While there
> are places to discuss the relative average beauty and niceness of
> various groups of people, this is not one of them.  Even comparisons of
> computer languages is not the main focus of this list.)

I'm not discussing the "relative average beauty and niceness of various
groups of people". That's absurd. I'm discussing the behaviour and
attitudes demonstrated by one specific individual.


[...]
> Yesterday, Chris Angelico, I believe it was, asked someone to stop
> including anti-Jew messages in posts here.  So I asked the same of you
> regarding your anti-American expression.

Can you really not tell the difference between criticism of an individual
American for the views he expresses, and a blanket attack on all Americans
merely for being American?



>> Not all Americans, perhaps not even a majority or a plurality, are Ugly
>> Americans, but there are enough of them to screw it up for everyone else.
> 
> Shall we discuss Ugly Australians, or whatever the appropriate epithet
> would be?

If one of them turns up and starts expressing those views, absolutely.


>> It's an ugly stereotype, not because it is a stereotype, but because it
>  > embodies a set of ugly attitudes and behaviours.
> 
> I am sure I have seen similar things written by various other people
> justifying their prejudices.

As have I. Are you judging *me* by *their* behaviour?



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


[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Michael Selik

Michael Selik added the comment:

Yesterday I wanted to do a destructuring bind on a slice of groups in a 
finditer. Similar situation to the use case of Issue #24454. It might not be 
"normal code" but I end up in that situation every month or so when parsing 
semi-structured documents. I found myself wishing for a mapping-destructuring 
bind, but that's another story.

I haven't read the full discussion of ``len`` on MatchObject yet, but I 
tentatively agree with Brandon Rhodes' comment in Issue #19536:

"My retort is that concentric groups can happen anyway:
that Group Zero, holding the entire match, is not really
as special as the newcomer might suspect, because you can
always wind up with groups inside of other groups; it is
simply part of the semantics of regular expressions that
groups might overlap or might contain one another ..."

@Serhiy, I was unaware of the feature of passing several arguments to groups. 
Unfortunately, the regex pattern I was using had a very large set of groups. A 
slice would have been particularly elegant. Passing several arguments to 
mo.groups() will be helpful, but still more awkward than a slice.

Perhaps it is a can of worms, but I was pleased to see indexing available and 
was disappointed not to find the typically supported corresponding features.

--

___
Python tracker 

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



[issue29964] %z directive has no effect on the output of time.strptime

2017-04-03 Thread R. David Murray

R. David Murray added the comment:

Yes, that's exactly right.  'time' is a low-level os-function wrapper, and 
inherits many of the deficiencies of the platform.  datetime attempts to be a 
more comprehensive, portable solution.  (But even it has its quirks...timezones 
are *hard*.)

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



Re: Two variable dictionary comprehension

2017-04-03 Thread Rob Gaddi

On 04/03/2017 10:27 AM, Deborah Swanson wrote:

Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM


On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson"
 declaimed the following:



Clearly there's more to be found in nooks, crannies and

byways in the

docs than you'll get to from the given pointers in the

index. Maybe it

would be worthwhile to scrape the whole mess and have it in

searchable

text form. Another thing Python would be the right tool for the job
for. Regular updates as the docs are updated would be a good

idea too.

It's obvious that today's Google isn't up to it, although it

occurs to

me that I haven't tried Google's site search on python.org.


On Windows, the (at least, for ActiveState releases)
documentation is available in Windows Help format -- though
I'll admit the "free text search" leaves a lot to be desired...

"dict comprehension" didn't find anything obvious;
"dictionary comprehension" brought up PEP 274 (note: I still
use 2.7 as main version).

-=-=-=-=-=-
Semantics
The semantics of dict comprehensions can actually be demonstrated
in stock Python 2.2, by passing a list comprehension to the
builtin dictionary constructor:

>>> dict([(i, chr(65+i)) for i in range(4)])

is semantically equivalent to

>>> {i : chr(65+i) for i in range(4)}

The dictionary constructor approach has two dictinct disadvantages
from the proposed syntax though.  First, it isn't as legible as a
dict comprehension.  Second, it forces the programmer to create an
in-core list object first, which could be expensive.

-=-=-=-=-=-
--
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/


It would be interesting to play around with different list
comprehensions than the one they've shown.

I'll admit that both dictionaries and comprehensions are still a little
bit fuzzy to me, especially when I get away from the common usages. This
could be a good exercise to clarify some of the fuzzy areas.

Deborah



And don't forget
  dict_comp : { k:v for (k,v) in kv_provider }
  set_comp : { item for item in item_provider }
  set_of_tuples_comp : { (k,v) for (k,v) in kv_provider }

Just to make things more complicated.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


[issue29974] typing.TYPE_CHECKING doc example is incorrect

2017-04-03 Thread Mathias Rav

Changes by Mathias Rav :


--
pull_requests: +1155

___
Python tracker 

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



[issue29974] typing.TYPE_CHECKING doc example is incorrect

2017-04-03 Thread Mathias Rav

New submission from Mathias Rav:

The documentation of typing.TYPE_CHECKING has an example (introduced in issue 
#26141) that would lead to NameError at runtime. The example shows how to limit 
the import of "expensive_mod" to type checkers, but then goes on to use 
"expensive_mod.some_type" in a type annotation that is evaluated at runtime 
("local_var: expensive_mod.some_type"). The use case of TYPE_CHECKING is 
probably meant for type annotations placed in comments, e.g. "local_var  # 
type: expensive_mod.some_type".

--
assignee: docs@python
components: Documentation
messages: 291085
nosy: docs@python, rav
priority: normal
severity: normal
status: open
title: typing.TYPE_CHECKING doc example is incorrect
type: enhancement
versions: 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



[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Eric V. Smith

Eric V. Smith added the comment:

Short of a compelling use case, I suggest we reject this enhancement request. 
len() was deliberately not added in #24454. It's not like any normal code would 
be iterating over match groups.

--
nosy: +eric.smith

___
Python tracker 

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



RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Dennis Lee Bieber wrote, on April 03, 2017 9:35 AM
> 
> On Mon, 3 Apr 2017 07:30:40 -0700, "Deborah Swanson" 
>  declaimed the following:
> 
> >
> >Clearly there's more to be found in nooks, crannies and 
> byways in the 
> >docs than you'll get to from the given pointers in the 
> index. Maybe it 
> >would be worthwhile to scrape the whole mess and have it in 
> searchable 
> >text form. Another thing Python would be the right tool for the job 
> >for. Regular updates as the docs are updated would be a good 
> idea too. 
> >It's obvious that today's Google isn't up to it, although it 
> occurs to 
> >me that I haven't tried Google's site search on python.org.
> >
>   On Windows, the (at least, for ActiveState releases) 
> documentation is available in Windows Help format -- though 
> I'll admit the "free text search" leaves a lot to be desired...
> 
>   "dict comprehension" didn't find anything obvious; 
> "dictionary comprehension" brought up PEP 274 (note: I still 
> use 2.7 as main version).
> 
> -=-=-=-=-=-
> Semantics
> The semantics of dict comprehensions can actually be demonstrated
> in stock Python 2.2, by passing a list comprehension to the
> builtin dictionary constructor:
> 
> >>> dict([(i, chr(65+i)) for i in range(4)])
> 
> is semantically equivalent to
> 
> >>> {i : chr(65+i) for i in range(4)}
> 
> The dictionary constructor approach has two dictinct disadvantages
> from the proposed syntax though.  First, it isn't as legible as a
> dict comprehension.  Second, it forces the programmer to create an
> in-core list object first, which could be expensive.
> 
> -=-=-=-=-=-
> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

It would be interesting to play around with different list
comprehensions than the one they've shown.

I'll admit that both dictionaries and comprehensions are still a little
bit fuzzy to me, especially when I get away from the common usages. This
could be a good exercise to clarify some of the fuzzy areas.

Deborah

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


[issue29941] Confusion between asserts and Py_DEBUG

2017-04-03 Thread Thomas Wouters

Thomas Wouters added the comment:

PR #980 adds a configure flag (--with-assertions), defaulting to the old 
behaviour (no assertions by default, except when --with-pydebug is passed). I 
would like to backport that to (at least) 3.6 so that we can set up a buildbot 
with it, to prevent regressions. Opinions on that?

--

___
Python tracker 

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



[issue29406] asyncio SSL contexts leak sockets after calling close with certain Apache servers

2017-04-03 Thread Michael Sghaier

Changes by Michael Sghaier :


--
pull_requests: +1154

___
Python tracker 

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



Re: Improve Python + Influxdb import performance

2017-04-03 Thread Prathamesh
On Monday, April 3, 2017 at 9:52:38 PM UTC+5:30, INADA Naoki wrote:
> You can reuse connection, instead of creating for each request. (HTTP
> keep-alive).
> 
> On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh  
> wrote:
> > Hello World
> >
> > The following script is an extract from
> >
> > https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py
> >
> > <>
> >
> > import calendar, time
> > import sys
> > import getopt
> >
> > print '---'
> >
> > # Check the arguments to this script are as expected.
> > # argv[0] is script name.
> > argLen = len(sys.argv)
> > if argLen -1 < 2:
> > print "ERROR: got ", argLen -1, " args, must be at least two."
> > print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py  
> >   [] [] 
> > [] [] [targetDB influx db>'
> > exit()
> >
> > outputFormat='CSV'
> > url='t3://localhost:7001'
> > targetHost='localhost'
> > targetDB='obi'
> > targetPort='8086'
> >
> > try:
> > wls_user = sys.argv[1]
> > wls_pw = sys.argv[2]
> > url  = sys.argv[3]
> > outputFormat=sys.argv[4]
> > targetHost=sys.argv[5]
> > targetPort=sys.argv[6]
> > targetDB=sys.argv[7]
> > except:
> > print ''
> >
> > print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB
> >
> > now_epoch = calendar.timegm(time.gmtime())*1000
> >
> > if outputFormat=='InfluxDB':
> > import httplib
> > influx_msgs=''
> >
> > connect(wls_user,wls_pw,url)
> > results = displayMetricTables('Oracle_BI*','dms_cProcessInfo')
> > for table in results:
> > tableName = table.get('Table')
> > rows = table.get('Rows')
> > rowCollection = rows.values()
> > iter = rowCollection.iterator()
> > while iter.hasNext():
> > row = iter.next()
> > rowType = row.getCompositeType()
> > keys = rowType.keySet()
> > keyIter = keys.iterator()
> > inst_name= row.get('Name').replace(' ','-')
> > try:
> > server= row.get('Servername').replace(' ','-').replace('/','_')
> > except:
> > try:
> > server= row.get('ServerName').replace(' 
> > ','-').replace('/','_')
> > except:
> > server='unknown'
> > try:
> > host= row.get('Host').replace(' ','-')
> > except:
> > host=''
> > while keyIter.hasNext():
> > columnName = keyIter.next()
> > value = row.get(columnName )
> > if columnName.find('.value')>0:
> > metric_name=columnName.replace('.value','')
> > if value is not None:
> > if value != 0:
> > if outputFormat=='InfluxDB':
> > influx_msg= 
> > ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % 
> > (metric_name,server,host,tableName,inst_name,  value,now_epoch*100)
> > influx_msgs+='\n%s' % influx_msg
> > conn = httplib.HTTPConnection('%s:%s' % 
> > (targetHost,targetPort))
> > ## TODO pretty sure should be urlencoding this 
> > ...
> > a=conn.request("POST", ("/write?db=%s" % 
> > targetDB), influx_msg)
> > r=conn.getresponse()
> >
> > <>
> >
> > It currently takes about 3 minutes to execute completely and I was thinking 
> > of a way to make it run faster
> >
> > Data alignment (Influx line protocol) & data loading - done together takes 
> > up most of the time
> >
> > Influxdb is currently loading data at around 3 points/second
> >
> > Any way to align the data separately, store it and load it as a batch?
> >
> > I feel that would help improve performance
> >
> > Please let me know if you have any pointers
> > I can send the data sheet if required
> >
> > Thanks P
> > --
> > https://mail.python.org/mailman/listinfo/python-list

How do I do that?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue29971] Lock.acquire() not interruptible on Windows

2017-04-03 Thread Josh Rosenberg

Changes by Josh Rosenberg :


--
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: Behavior of auto in Enum and Flag.

2017-04-03 Thread Oren Ben-Kiki
On Mon, Apr 3, 2017 at 7:43 PM, Chris Angelico  wrote:

> Here's a counter-example that supports the current behaviour:
>
> >>> from enum import IntFlag, auto
> >>> class Spam(IntFlag):
> ... FOO = auto()
> ... BAR = auto()
> ... FOOBAR = FOO | BAR
> ... SPAM = auto()
> ... HAM = auto()
> ... SPAMHAM = SPAM | HAM
> ...
>

Ugh, good point - I didn't consider that use case, I see how it would be
nasty to implement.

I guess just improving the documentation is called for, then...

Thanks,

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


[issue28087] macOS 12 poll syscall returns prematurely

2017-04-03 Thread STINNER Victor

STINNER Victor added the comment:

Ah! Python 2.7 tests succeeded on Sierra!

http://buildbot.python.org/all/builders/x86-64%20Sierra%202.7/builds/3

--

___
Python tracker 

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



Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 2:29 AM, Ethan Furman  wrote:
> It this point I do not.  If you can give us an example Enum and why it's
> necessary to be built like that I might be swayed -- although the odds are
> good that the change will go into aenum instead (it's already a mess with
> the 2.7 compatibility code...).

Here's a counter-example that supports the current behaviour:

>>> from enum import IntFlag, auto
>>> class Spam(IntFlag):
... FOO = auto()
... BAR = auto()
... FOOBAR = FOO | BAR
... SPAM = auto()
... HAM = auto()
... SPAMHAM = SPAM | HAM
...
>>> list(Spam)
[, , , ,
, ]

It makes perfect sense to define combined flags in terms of the
(previously-defined) individual flags. If auto() has to be deferred
until the class is fully defined, this would be a lot harder.

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


[issue29941] Confusion between asserts and Py_DEBUG

2017-04-03 Thread Thomas Wouters

Changes by Thomas Wouters :


--
pull_requests: +1153

___
Python tracker 

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



[issue29851] Have importlib.reload() raise ImportError when a spec can't be found

2017-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Wouldn't ModuleNotFoundError be more appropriate?

--
nosy: +serhiy.storchaka

___
Python tracker 

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



Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Ethan Furman

On 04/03/2017 01:53 AM, Oren Ben-Kiki wrote:

On Mon, Apr 3, 2017 at 11:03 AM, Ethan Furman wrote:


Python code is executed top-down.  First FOO, then BAR, then BAZ.  It is not 
saved up and executed later in random
order.  Or, put another way, the value was appropriate when it was chosen -- it 
is not the fault of auto() that the
user chose a conflicting value (hence why care should be taken).


This is not to say that there's no possible workaround for this - the code 
could pretty easily defer invocation of
_generate_next_macro_ until after the whole class was seen. It would still 
happen in order (since members are an ordered
dictionary these days).


Possible, yes.  Easy, no.


So it is a matter of conflicting values - what would be more "Pythonic": 
treating auto as executed immediately, or
avoiding conflicts between auto and explicit values.


Since most things execute immediately, that is the pattern I chose.


1. The documentation will be more explicit about the way `auto` behaves in the 
presence of following value


I can do that.


Barring changing the way auto works, that would be best ("explicit is better than 
implicit" and all that ;-)



As for backward compatibility, the docs are pretty clear about "use auto when you 
don't care about the value"... and
Enum is pretty new, so there's not _that_ much code that relies on "implementation 
specific" details.


Fair point.


*If* backward compatibility is an issue here, then the docs might as well specify 
"previous value plus 1, or 1 if this
is the first value" as the "standard" behavior, and be done.


Actually, (Int)Flag uses the next power of two (not already seen) -- so it isn't as easy 
as "last value + 1".


This has the advantage of being deterministic and explicit, so people would be 
justified in relying on it. It would
still have to be accompanied by saying "auto() can only consider previous values, 
not following ones".


Something to that effect sounds good.


This might work for you (untested):

def _generate_next_value_(name, start, count, previous_values):
 if not count:
 return start or 1
 previous_values.sort()
 last_value = previous_values[-1]
 if last_value < 1000:
 return 1001
 else:
 return last_value + 1


This assumes no following enum values have values > 1000 (or some predetermined 
constant), which doesn't work in my
particular case, or in the general case. But yes, this might solve the problem 
for some people.


General code isn't going to "do what I need" 100% of the time for 100% of the people.  That's why I made the 
_generate_next_value_ method user over-ridable



3. To allow for this, the implementation will include a
`_generate_auto_value_` which will take both the list of previous ("last")
values (including auto values) and also a second list of the following
("next") values (excluding auto values).


No, I'm not interested in doing that.  I currently have that kind of code in 
aenum[1] for 2.7 compatibility, and
it's a nightmare to maintain.


Understood. Another alternative would be to have something like 
_generate_next_value_ex_ with the additional argument
(similar to __reduce_ex__), which isn't ideal either.


It's a lot more work than just making another method.


Assuming you buy into my "necessity" claim, that is...


It this point I do not.  If you can give us an example Enum and why it's necessary to be built like that I might be 
swayed -- although the odds are good that the change will go into aenum instead (it's already a mess with the 2.7 
compatibility code...).



Thanks,


You're welcome.

--
~Ethan~

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


Re: SocketServer and Ctrl-C on Windows

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 12:34 AM, Paul  Moore  wrote:
> On Monday, 3 April 2017 15:10:12 UTC+1, Chris Angelico  wrote:
>> You're getting HTTP/1.1 requests. Maybe you need to send a
>> "Connection: close" header to tell the browser to leave you be?
>
> That sounds possible - I don't really know enough about HTTP to even know 
> that was a thing, so I'm not surprised if I got it wrong.
>
> My test harness is using a Bottle server, which (apparently) actively gets in 
> the way of setting this header, so I'll have to do a bit more work to confirm 
> this, but it certainly seems like a good lead.

An alternative way to diagnose this would be to see if you still have
an established socket connection. I'm not sure how you do that on
Windows, but it'd be a good thing to check.

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


Re: Improve Python + Influxdb import performance

2017-04-03 Thread INADA Naoki
You can reuse connection, instead of creating for each request. (HTTP
keep-alive).

On Tue, Apr 4, 2017 at 1:11 AM, Prathamesh  wrote:
> Hello World
>
> The following script is an extract from
>
> https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py
>
> <>
>
> import calendar, time
> import sys
> import getopt
>
> print '---'
>
> # Check the arguments to this script are as expected.
> # argv[0] is script name.
> argLen = len(sys.argv)
> if argLen -1 < 2:
> print "ERROR: got ", argLen -1, " args, must be at least two."
> print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py  
>   [] [] 
> [] [] [targetDB influx db>'
> exit()
>
> outputFormat='CSV'
> url='t3://localhost:7001'
> targetHost='localhost'
> targetDB='obi'
> targetPort='8086'
>
> try:
> wls_user = sys.argv[1]
> wls_pw = sys.argv[2]
> url  = sys.argv[3]
> outputFormat=sys.argv[4]
> targetHost=sys.argv[5]
> targetPort=sys.argv[6]
> targetDB=sys.argv[7]
> except:
> print ''
>
> print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB
>
> now_epoch = calendar.timegm(time.gmtime())*1000
>
> if outputFormat=='InfluxDB':
> import httplib
> influx_msgs=''
>
> connect(wls_user,wls_pw,url)
> results = displayMetricTables('Oracle_BI*','dms_cProcessInfo')
> for table in results:
> tableName = table.get('Table')
> rows = table.get('Rows')
> rowCollection = rows.values()
> iter = rowCollection.iterator()
> while iter.hasNext():
> row = iter.next()
> rowType = row.getCompositeType()
> keys = rowType.keySet()
> keyIter = keys.iterator()
> inst_name= row.get('Name').replace(' ','-')
> try:
> server= row.get('Servername').replace(' ','-').replace('/','_')
> except:
> try:
> server= row.get('ServerName').replace(' 
> ','-').replace('/','_')
> except:
> server='unknown'
> try:
> host= row.get('Host').replace(' ','-')
> except:
> host=''
> while keyIter.hasNext():
> columnName = keyIter.next()
> value = row.get(columnName )
> if columnName.find('.value')>0:
> metric_name=columnName.replace('.value','')
> if value is not None:
> if value != 0:
> if outputFormat=='InfluxDB':
> influx_msg= 
> ('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % 
> (metric_name,server,host,tableName,inst_name,  value,now_epoch*100)
> influx_msgs+='\n%s' % influx_msg
> conn = httplib.HTTPConnection('%s:%s' % 
> (targetHost,targetPort))
> ## TODO pretty sure should be urlencoding this ...
> a=conn.request("POST", ("/write?db=%s" % 
> targetDB), influx_msg)
> r=conn.getresponse()
>
> <>
>
> It currently takes about 3 minutes to execute completely and I was thinking 
> of a way to make it run faster
>
> Data alignment (Influx line protocol) & data loading - done together takes up 
> most of the time
>
> Influxdb is currently loading data at around 3 points/second
>
> Any way to align the data separately, store it and load it as a batch?
>
> I feel that would help improve performance
>
> Please let me know if you have any pointers
> I can send the data sheet if required
>
> Thanks P
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue29969] Typo in decimal error message

2017-04-03 Thread Stefan Krah

Stefan Krah added the comment:

Merged, thank you.

--
assignee:  -> skrah
nosy: +skrah
resolution:  -> fixed
stage:  -> 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



Obtain Ceritificate Information from Invalid or Self-Signed Certificate in Python

2017-04-03 Thread Kenneth Buckler
I'm working on a Python 2.7.13 (Win x64) script to verify SSL certificates,
and alert for problems. Specifically, I'm looking to return the date the
cert expires or did expire. However, I'm running into an issue where the
script will return information only if the certificate is valid.

If the certificate is invalid, I receive a CERTIFICATE_VERIFY_FAILED SSL
error. Normally I would simply use a try/catch when the error is raised and
just alert that the cert is invalid, but the issue here is that the I need
the actual date the certificate expired, or in some cases the cert will be
a self-signed cert, which will be acceptable UNLESS the cert is expired.
I'm dealing with an organization that has thousands of certs, so adding
every single self signed cert to the cert store locally won't be an option.

Per https://docs.python.org/2/library/ssl.html I tried to use
conn._https_verify_certificates(enable=False) to disable certificate
validation, but get an error that the attribute _https_verify_certificates
doesn't exist.

Here is my code so far. I'm sure I'm missing something obvious. Surely
Python can pull the SSL certificate without validating it, right?

import socketimport ssl
def ssl_expiry_datetime(hostname):
ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z'

context = ssl.create_default_context()
conn = context.wrap_socket(
socket.socket(socket.AF_INET),
server_hostname=hostname,
)
# 3 second timeout because Lambda has runtime limitations
conn.settimeout(3.0)
#conn._https_verify_certificates(enable=False)
conn.connect((hostname, 443))
ssl_info = conn.getpeercert()
# parse the string from the certificate into a Python datetime object
return ['notAfter']

myhost = 'www.google.com'
print ssl_expiry_datetime(myhost)

Thanks!

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


Improve Python + Influxdb import performance

2017-04-03 Thread Prathamesh
Hello World

The following script is an extract from

https://github.com/RittmanMead/obi-metrics-agent/blob/master/obi-metrics-agent.py

<>

import calendar, time
import sys
import getopt

print '---'

# Check the arguments to this script are as expected.
# argv[0] is script name.
argLen = len(sys.argv)
if argLen -1 < 2:
print "ERROR: got ", argLen -1, " args, must be at least two."
print '$FMW_HOME/oracle_common/common/bin/wlst.sh obi-metrics-agent.py  
  [] [] 
[] [] [targetDB influx db>'
exit()

outputFormat='CSV'
url='t3://localhost:7001'
targetHost='localhost'
targetDB='obi'
targetPort='8086'

try:
wls_user = sys.argv[1]
wls_pw = sys.argv[2]
url  = sys.argv[3]
outputFormat=sys.argv[4]
targetHost=sys.argv[5]
targetPort=sys.argv[6]
targetDB=sys.argv[7]
except:
print ''

print wls_user, wls_pw,url, outputFormat,targetHost,targetPort,targetDB

now_epoch = calendar.timegm(time.gmtime())*1000

if outputFormat=='InfluxDB':
import httplib
influx_msgs=''

connect(wls_user,wls_pw,url)
results = displayMetricTables('Oracle_BI*','dms_cProcessInfo')
for table in results:
tableName = table.get('Table')
rows = table.get('Rows')
rowCollection = rows.values()
iter = rowCollection.iterator()
while iter.hasNext():
row = iter.next()
rowType = row.getCompositeType()
keys = rowType.keySet()
keyIter = keys.iterator()
inst_name= row.get('Name').replace(' ','-')
try:
server= row.get('Servername').replace(' ','-').replace('/','_')
except:
try:
server= row.get('ServerName').replace(' ','-').replace('/','_')
except:
server='unknown'
try:
host= row.get('Host').replace(' ','-')
except:
host=''
while keyIter.hasNext():
columnName = keyIter.next()
value = row.get(columnName )
if columnName.find('.value')>0:
metric_name=columnName.replace('.value','')
if value is not None:
if value != 0:
if outputFormat=='InfluxDB':
influx_msg= 
('%s,server=%s,host=%s,metric_group=%s,metric_instance=%s value=%s %s') % 
(metric_name,server,host,tableName,inst_name,  value,now_epoch*100)
influx_msgs+='\n%s' % influx_msg
conn = httplib.HTTPConnection('%s:%s' % 
(targetHost,targetPort))
## TODO pretty sure should be urlencoding this ...
a=conn.request("POST", ("/write?db=%s" % targetDB), 
influx_msg)
r=conn.getresponse()

<>

It currently takes about 3 minutes to execute completely and I was thinking of 
a way to make it run faster

Data alignment (Influx line protocol) & data loading - done together takes up 
most of the time

Influxdb is currently loading data at around 3 points/second

Any way to align the data separately, store it and load it as a batch?

I feel that would help improve performance

Please let me know if you have any pointers
I can send the data sheet if required

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


[issue29973] Travis CI docs broken: UnboundLocalError: local variable 'prefix' referenced before assignment

2017-04-03 Thread STINNER Victor

STINNER Victor added the comment:

Oh, Zachary Were "restarted the docs job on most of the blocked PRs". So I 
close this issue.

That one was hopefully quickly fixed :-)

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



[issue28087] macOS 12 poll syscall returns prematurely

2017-04-03 Thread STINNER Victor

STINNER Victor added the comment:


New changeset 23d6eb656ec29140fcca1c9261b7953e2312b171 by Victor Stinner in 
branch '2.7':
bpo-28087: Skip test_asyncore and test_eintr poll failures on macOS. (#462) 
(#973)
https://github.com/python/cpython/commit/23d6eb656ec29140fcca1c9261b7953e2312b171


--

___
Python tracker 

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



[issue29973] Travis CI docs broken: UnboundLocalError: local variable 'prefix' referenced before assignment

2017-04-03 Thread STINNER Victor

STINNER Victor added the comment:

https://pypi.org/project/Sphinx/1.5.5/ has been released. How can I schedule a 
recheck on Travis CI on PRs where the docs job failed?

--

___
Python tracker 

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



[issue29973] Travis CI docs broken: UnboundLocalError: local variable 'prefix' referenced before assignment

2017-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This already is fixed in mainstream. 
https://github.com/sphinx-doc/sphinx/issues/3597

Sphinx 1.5.5 will be released soon. 
https://github.com/sphinx-doc/sphinx/issues/3598

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue29973] Travis CI docs broken: UnboundLocalError: local variable 'prefix' referenced before assignment

2017-04-03 Thread STINNER Victor

New submission from STINNER Victor:

https://travis-ci.org/python/cpython/jobs/218107336

CPython: master branch
Sphinx 1.5.4

make[1]: Entering directory `/home/travis/build/python/cpython/Doc'
./venv/bin/python -m sphinx -b suspicious -d build/doctrees -D 
latex_elements.papersize= -q -W . build/suspicious 

Exception occurred:
  File 
"/home/travis/virtualenv/python3.6.0/lib/python3.6/site-packages/sphinx/domains/python.py",
 line 317, in before_content
if prefix:
UnboundLocalError: local variable 'prefix' referenced before assignment

--
assignee: docs@python
components: Documentation, Tests
messages: 291075
nosy: docs@python, haypo
priority: normal
severity: normal
status: open
title: Travis CI docs broken: UnboundLocalError: local variable 'prefix' 
referenced before assignment
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



[issue29972] Skip tests known to fail on AIX

2017-04-03 Thread STINNER Victor

STINNER Victor added the comment:

See also https://github.com/python/cpython/pull/978 which should fix one unit 
test of test_ssl.

--

___
Python tracker 

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



[issue29972] Skip tests known to fail on AIX

2017-04-03 Thread STINNER Victor

Changes by STINNER Victor :


--
pull_requests: +1152

___
Python tracker 

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



[issue29972] Skip tests known to fail on AIX

2017-04-03 Thread Eric N. Vander Weele

Changes by Eric N. Vander Weele :


--
nosy: +ericvw

___
Python tracker 

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



[issue29972] Skip tests known to fail on AIX

2017-04-03 Thread STINNER Victor

New submission from STINNER Victor:

Extract of David Edelsohn's email:
"""
The testsuite failures on AIX are issues with the AIX kernel and C
Library, often corner cases.  I don't want to get into arguments about
the POSIX standard.  Some of the issues are actual conformance issues
and some are different interpretations of the standard.  Addressing
the problems in AIX is a slow process. If the failing testcases are
too annoying, I would recommend to skip the testcases.

Despite the testsuite failures, Python builds and runs on AIX for the
vast majority of users and applications.  I don't see the benefit in
dropping support for a platform that functions because it doesn't
fully pass the testsuite.
"""
ref: https://mail.python.org/pipermail/python-dev/2017-April/147748.html

I agree, so let's skip tests known to fail on AIX!

--
components: Tests
messages: 291073
nosy: haypo
priority: normal
severity: normal
status: open
title: Skip tests known to fail on AIX
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



[issue29971] Lock.acquire() not interruptible on Windows

2017-04-03 Thread Antoine Pitrou

New submission from Antoine Pitrou:

On Windows, Lock.acquire() (and other synchronization primitives derived from 
it, such as queue.Queue) cannot be interrupted with Ctrl-C, which makes it 
difficult to interrupt a process waiting on such a primitive.

Judging by the code in Python/_thread_nt.h, it should be relatively easy to add 
such support for the "legacy" semaphore-based implementation (by using 
WaitForMultipleObjects instead of WaitForSingleObject), but it would be much 
hairier for the new condition variable-based implementation.

Of course, many other library calls are prone to this limitation (not being 
interruptible with Ctrl-C on Windows).

See https://github.com/dask/dask/pull/2144#issuecomment-290556996 for original 
report.

--
components: Library (Lib), Windows
messages: 291072
nosy: kristjan.jonsson, paul.moore, pitrou, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Lock.acquire() not interruptible on Windows
type: enhancement
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



Re: SocketServer and Ctrl-C on Windows

2017-04-03 Thread Paul Moore
On Monday, 3 April 2017 15:10:12 UTC+1, Chris Angelico  wrote:
> You're getting HTTP/1.1 requests. Maybe you need to send a
> "Connection: close" header to tell the browser to leave you be?

That sounds possible - I don't really know enough about HTTP to even know that 
was a thing, so I'm not surprised if I got it wrong.

My test harness is using a Bottle server, which (apparently) actively gets in 
the way of setting this header, so I'll have to do a bit more work to confirm 
this, but it certainly seems like a good lead.

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


RE: Two variable dictionary comprehension

2017-04-03 Thread Deborah Swanson
Gregory Ewing wrote, on April 02, 2017 11:35 PM
> 
> Deborah Swanson wrote:
> 
> > Oh, come on. That's a fairly obscure citation in the docs, one that 
> > would take a good deal of experience and time reading 
> through them to 
> > know was there,
> 
> You seemed to know that there was something called a "dict 
> comprehension". Googling for "python 3 dict comprehension" 
> gives me a link to an example of one in the docs as the second result.
> 
> The first result is a page in Dive Into Python containing
> a section on dict comprehensions.
> 
> Part of being a good programmer is knowing how to track
> down the information you need!
> 
> Having said that, the index of the Python docs could be 
> improved a bit in this area -- currently it only mentions 
> "list" under "comprehension" (although the page it leads to 
> discusses the other types as well).
> 
> -- 
> Greg

Despite my earlier words and protestations that I did look for two
variable dict comprehensions, fairly diligently, I am taking what you
said seriously. Obviously I shouldn't expect to find handy and
recognizable entries in the index for everything I might want to find in
the docs, and I plan to spend more time browsing around. 

Clearly there's more to be found in nooks, crannies and byways in the
docs than you'll get to from the given pointers in the index. Maybe it
would be worthwhile to scrape the whole mess and have it in searchable
text form. Another thing Python would be the right tool for the job for.
Regular updates as the docs are updated would be a good idea too. It's
obvious that today's Google isn't up to it, although it occurs to me
that I haven't tried Google's site search on python.org.

I hope you won't be miffed though if I still come up empty handed and
come back here to ask again.

Deborah

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


[issue29970] Severe open file leakage running asyncio SSL server

2017-04-03 Thread kyuupichan

New submission from kyuupichan:

Original report at old repo here:  https://github.com/python/asyncio/issues/483

There this is reported fixed by https://github.com/python/cpython/pull/480

I wish to report that whilst the above patch might have a small positive 
effect, it is far from solving the actual issue.  Several users report eventual 
exhaustion of the open file resource running SSL asyncio servers.

Here are graphs provided by a friend running my ElectrumX server software, 
first accepting SSL connections and the second accepting TCP connections only.  
Both of the servers were monkey-patched with the pull-480 fix above, so this is 
evidence it isn't solving the issue.

http://imgur.com/a/cWnSu

As you can see, the TCP server (which has far less connections; most users use 
SSL) has no leaked file handles, whereas the SSL server has over 300.

This becomes an easy denial of service vector against asyncio servers.  One way 
to trigger this (though I doubt it explains the numbers above) is simply to 
connect to the SSL server from telnet, and do nothing.  asyncio doesn't time 
you out, the telnet session seems to sit there forever, and the open file 
resources are lost in the SSL handshake stage until the remote host kindly 
decides to disconnect.

I suspect these resource issues all revolve around the SSL handshake process, 
certainly at the opening of a connection, but also perhaps when closing.

As the application author I am not informed by asyncio of a potential 
connection until the initial handshake is complete, so I cannot do anything to 
close these phantom socket connections.  I have to rely on asyncio to be 
properly handling DoS issues and it is not currently doing so robustly.

--
components: asyncio
messages: 291071
nosy: kyuupichan, yselivanov
priority: normal
severity: normal
status: open
title: Severe open file leakage running asyncio SSL server
type: resource usage
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: SocketServer and Ctrl-C on Windows

2017-04-03 Thread Chris Angelico
On Mon, Apr 3, 2017 at 11:56 PM, Paul  Moore  wrote:
> On Monday, 3 April 2017 14:20:43 UTC+1, Paul  Moore  wrote:
>> On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun  wrote:
>> > It should service the request and return to the serve_forever() loop.
>> > Do you see a line logged for each request, like "[IP] - - [date] "GET
>> > ..."?
>>
>> Yes, I see that and the page is served.
>>
>> >py .\example.py
>> Serving HTTP on port 8000...
>> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470
>> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438
>>
>> But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C 
>> multiple times.
>
> Hmm, looks like sometimes it works. I wonder if the browser is holding open 
> the page request somehow. That seems unlikely as HTTP is supposed to be 
> stateless.
>

You're getting HTTP/1.1 requests. Maybe you need to send a
"Connection: close" header to tell the browser to leave you be?

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


Re: SocketServer and Ctrl-C on Windows

2017-04-03 Thread Paul Moore
On Monday, 3 April 2017 14:20:43 UTC+1, Paul  Moore  wrote:
> On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun  wrote:
> > It should service the request and return to the serve_forever() loop.
> > Do you see a line logged for each request, like "[IP] - - [date] "GET
> > ..."?
> 
> Yes, I see that and the page is served.
> 
> >py .\example.py
> Serving HTTP on port 8000...
> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470
> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438
> 
> But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C 
> multiple times.

Hmm, looks like sometimes it works. I wonder if the browser is holding open the 
page request somehow. That seems unlikely as HTTP is supposed to be stateless.

I guess this isn't worth worrying about. It seems like it's only an occasional 
problem, and I have a workaround (Ctrl-Break) anyway.

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


Re: SocketServer and Ctrl-C on Windows

2017-04-03 Thread eryk sun
On Mon, Apr 3, 2017 at 1:20 PM, Paul  Moore  wrote:
> On Monday, 3 April 2017 14:00:18 UTC+1, eryk sun  wrote:
>> It should service the request and return to the serve_forever() loop.
>> Do you see a line logged for each request, like "[IP] - - [date] "GET
>> ..."?
>
> Yes, I see that and the page is served.
>
>>py .\example.py
> Serving HTTP on port 8000...
> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET / HTTP/1.1" 200 5470
> 127.0.0.1 - - [03/Apr/2017 13:25:34] "GET /favicon.ico HTTP/1.1" 200 5438
>
> But if I press Ctrl-C at this point, nothing happens. Even if I press Ctrl-C 
> multiple times.

Try adding a low-level console control handler that shuts down the
server. For example:

import sys
import ctypes
from wsgiref.simple_server import make_server, demo_app

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
CTRL_C_EVENT = 0

with make_server('', 8000, demo_app) as httpd:
print("Serving HTTP on port 8000...")

@ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)
def ctrl_handler(dwCtrlType):
if dwCtrlType == CTRL_C_EVENT:
print("Ctrl+C shutdown", file=sys.stderr)
httpd.shutdown()
return False

if not kernel32.SetConsoleCtrlHandler(ctrl_handler, True):
raise ctypes.WinError(ctypes.get_last_error())

# Respond to requests until process is killed
httpd.serve_forever()
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   >