Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Mark Lawrence

On 23/02/2016 02:27, Paul Rubin wrote:

Steven D'Aprano  writes:

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


I didn't know about this!  The discussion was all on mailing lists?


https://mail.python.org/pipermail/python-ideas/2015-September/036333.html then 
http://www.gossamer-threads.com/lists/python/dev/1223780




A few things I suggest changing:

   1) the default system RNG for Linux should be getrandom(2) on kernels
   that support it (3.17 and later).

   2) Some effort should be directed at simulating getrandom's behaviour
   on kernels that don't have it, using the /dev/random entropy estimator
   and the /dev/urandom interface.  I.e. it should block if the system
   hasn't seen enough entropy to get the CSPRNG started securely, and
   never block after that.

   3) The default token length should be long enough to not have to "change
   in the future".  If the user wants a shorter token, they ask for that,
   or can truncate a longer one that they receive from the default.

There are a few other choices in the PEP whose benefit is unclear to me,
but they aren't harmful, and I guess the decisions have already been
made.



The PEP status is draft so is subject to change.

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

Mark Lawrence

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


Re: Testing whether the VPN is running?

2016-02-23 Thread Cameron Simpson

On 18Feb2016 10:03, Adam Funk  wrote:

On 2016-02-18, Ervin Hegedüs wrote:

I think that the psutil modul could be better for you for this
task:
https://pypi.python.org/pypi/psutil/

and see the "Network" section.


if 'tun0' in psutil.net_if_addrs():
  # vpn is running

Brilliant!  I've used psutil for something else, but I didn't know it
did that too.  My excuse is that the version on my system was 2.2.1,
which does not do that, so I installed the newer version with pip3.
Thanks for pointing me to that.


You might also want to check that the interface is up.

My personal hack (not for a VPN, but for "being online", which turns my ssh 
tunnels on and off) is to look in the output of "netstat -rn" for a default 
route. This may imply that an alternative test for you is to test for a route 
to your VPN's address range?  Just an idea.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Paul Rubin
Mark Lawrence  writes:
> https://mail.python.org/pipermail/python-ideas/2015-September/036333.html
> then http://www.gossamer-threads.com/lists/python/dev/1223780

Thanks.  It would be nice if those were gatewayed to usenet like this
group is.  I can't bring myself to subscribe to mailing lists.

>> There are a few other choices in the PEP whose benefit is unclear to me,
>> but they aren't harmful, and I guess the decisions have already been
>> made.
> The PEP status is draft so is subject to change.

Well they might be changeable but it sounds like there's a level of
consensus by now, that wouldn't be helped by more bikeshedding over
relatively minor stuff.  I might write up some further comments and post
them here 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Peter Otten
Paul Rubin wrote:

> Mark Lawrence  writes:
>> https://mail.python.org/pipermail/python-ideas/2015-September/036333.html
>> then http://www.gossamer-threads.com/lists/python/dev/1223780
> 
> Thanks.  It would be nice if those were gatewayed to usenet like this
> group is.  I can't bring myself to subscribe to mailing lists.

They are available via news.gmane.org as

gmane.comp.python.devel
gmane.comp.python.ideas


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


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Mark Lawrence

On 23/02/2016 08:22, Paul Rubin wrote:

Mark Lawrence  writes:

https://mail.python.org/pipermail/python-ideas/2015-September/036333.html
then http://www.gossamer-threads.com/lists/python/dev/1223780


Thanks.  It would be nice if those were gatewayed to usenet like this
group is.  I can't bring myself to subscribe to mailing lists.


Piece of cake using even a semi-decent email client (I use Thunderbird 
on Windows) via gmane.  It provides access to hundreds of Python mailing 
lists, blogs and even updates to the Activestate recipes :)





There are a few other choices in the PEP whose benefit is unclear to me,
but they aren't harmful, and I guess the decisions have already been
made.

The PEP status is draft so is subject to change.


Well they might be changeable but it sounds like there's a level of
consensus by now, that wouldn't be helped by more bikeshedding over
relatively minor stuff.  I might write up some further comments and post
them here



You might as well, can't do any harm and somebody might pick up on 
something.


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

Mark Lawrence

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


Re: Testing whether the VPN is running?

2016-02-23 Thread Gisle Vanem
Cameron Simpson:

> You might also want to check that the interface is up.
> 
> My personal hack (not for a VPN, but for "being online", which turns my ssh 
> tunnels on and off) is to look in the output
> of "netstat -rn" for a default route. This may imply that an alternative test 
> for you is to test for a route to your
> VPN's address range?  Just an idea.

And for VPN in Windows *and* using WinPcap, one can check if this device
exist:
  \Device\NPF_GenericDialupAdapter

(controllable using 'sq query rasdial'). This works if you use
PPTP or L2TP but not OpenVPN.

BTW, a VPN on Windows doesn't come back up automatically after
a sleep/hibernation. The WOSB tool at http://www.dennisbabkin.com/wosb/
could be handy. What happens with your VPN on Linux (?) after coming
back from sleep/hibernation? Automatic or you need to script that too?

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


EuroPython 2016: Early bird sales started

2016-02-23 Thread M.-A. Lemburg
We have opened up the early-bird sales today and tickets are selling
fast. The first 100 early-bird tickets, we have available, will be
gone in less than an hour. If you want to benefit from reduced ticket
prices too, please register soon.

Our early bird ticket sales are limited to 300 tickets. Regular ticket
sales will start shortly after we’ve ended the early bird sales.


  *** https://ep2016.europython.eu/en/registration/ ***

 More Information and Ticket Shop


PS: Remember to submit your proposals for the conference. There are
less than two weeks left:

  https://ep2016.europython.eu/en/call-for-proposals/


With gravitational regards,
--
EuroPython 2016 Team
http://ep2016.europython.eu/
http://www.europython-society.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


how to notify among the def and can network communication such as zeromq for python do this?

2016-02-23 Thread Ho Yeung Lee
in the following code, node 3 and node 4 running parallel

if there are 100 nodes running parallel, how can they notify each other

i find this post stackoverflow, 

http://stackoverflow.com/questions/29324346/how-do-i-connect-asyncio-coroutines-that-continually-produce-and-consume-data


if zeromq for python can not do notify among parallel nodes which means give 
handle to another def

my goal is to make each node can notify all other nodes if each node need

import asyncio
import time
from concurrent.futures import ProcessPoolExecutor

def f000():
 try:
  print "000"
  ex = ProcessPoolExecutor(2)
  yield from loop.run_in_executor(ex, time.sleep, 10)
 except:
  print "000 exception"

def f001():
 try:
  print "001"
  ex = ProcessPoolExecutor(2)
  yield from loop.run_in_executor(ex, time.sleep, 10)
 except:
  print "001 exception"

def f002():
 try:
  print "002"
  ex = ProcessPoolExecutor(2)
  yield from loop.run_in_executor(ex, time.sleep, 10)
 except:
  print "002 exception"

def f003():
 try:
  print "003"
  ex = ProcessPoolExecutor(2)
  yield from loop.run_in_executor(ex, time.sleep, 10)
 except:
  print "003 exception"

def f004():
 try:
  print "004"
  ex = ProcessPoolExecutor(2)
  yield from loop.run_in_executor(ex, time.sleep, 10)
 except:
  print "004 exception"

machine = {}
mappedfunc = {}
functionlist000 = []
functionlist001 = []
functionlist002 = []
functionlist003 = []
functionlist004 = []

functionlist000.append('002')
functionlist001.append('000')
functionlist002.append('003')
functionlist002.append('004')

functionlist003.append('001')
functionlist004.append('001')

machine000 = {'000': functionlist000}
machine001 = {'001': functionlist001}
machine002 = {'002': functionlist002}
machine003 = {'003': functionlist003}
machine004 = {'004': functionlist004}

machine.update(machine000)
machine.update(machine001)
machine.update(machine002)
machine.update(machine003)
machine.update(machine004)

functionkey000 = {'000': f000 }
functionkey001 = {'001': f001 }
functionkey002 = {'002': f002 }
functionkey002 = {'003': f003 }
functionkey002 = {'004': f004 }

mappedfunc.update(functionkey000)
mappedfunc.update(functionkey001)
mappedfunc.update(functionkey002)
mappedfunc.update(functionkey003)
mappedfunc.update(functionkey004)

def workingthreadpool(currentnumber1):
  i = 1
 #while i < 7:
  #i = i + 1
  functionlist0 = list(machine.get(currentnumber1).values())

  loop = asyncio.get_event_loop()
  tesks = []
  
  j = 1
  for functionlistelement in functionlist0
   tesks.append(asyncio.ensure_future(mappedfunc.get(functionlistelement)()))
   if j > 1:
workingthreadpool(functionlistelement)
   j = j + 1

  loop.run_until_complete(asyncio.wait_for(tesks, 1))
  loop.close()

currentnumber = "000"
workingthreadpool(currentnumber)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Grant Edwards
On 2016-02-23, Mark Lawrence  wrote:
> On 23/02/2016 08:22, Paul Rubin wrote:
>> Mark Lawrence  writes:
>>> https://mail.python.org/pipermail/python-ideas/2015-September/036333.html
>>> then http://www.gossamer-threads.com/lists/python/dev/1223780
>>
>> Thanks.  It would be nice if those were gatewayed to usenet like
>> this group is. I can't bring myself to subscribe to mailing lists.
>
> Piece of cake using even a semi-decent email client (I use Thunderbird 
> on Windows) via gmane.

And gmane is even better using a decent news (NNTP) client.  I prefer
slrn, but that may be a bit old-school for many.  Technically, gmane's
news server is not "Usenet", but the UI is the same.

Gmane's internal search facility is a bit lame, but searching gmane
with Google works fairly well.

> It provides access to hundreds of Python mailing lists, blogs and
> even updates to the Activestate recipes :)

-- 
Grant Edwards   grant.b.edwardsYow! World War Three can
  at   be averted by adherence
  gmail.comto a strictly enforced
   dress code!
-- 
https://mail.python.org/mailman/listinfo/python-list


setting the font of the root title

2016-02-23 Thread kevind0718
Hello:

Newbee here.

I need to change the font of the title of the root.
Actually I just need it to be larger, which means I may need the 
top boarder to be larger.

I wrote the bit of code below, hoping for the desired effect.
Also googled around regarding the toplevel widget
No luck.

Your kind assistance is requested.


from  Tkinter   import * 
import tkFont

root = Tk( )
root.option_add("*font, ", "Times 16")
root.title("Database Logon Info")
w = Label(root, text="Hello World")

w.pack()

root.mainloop()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: setting the font of the root title

2016-02-23 Thread Random832
On Tue, Feb 23, 2016, at 11:30, kevind0...@gmail.com wrote:
> Hello:
> 
> Newbee here.
> 
> I need to change the font of the title of the root.
> Actually I just need it to be larger, which means I may need the 
> top boarder to be larger.
> 
> I wrote the bit of code below, hoping for the desired effect.
> Also googled around regarding the toplevel widget
> No luck.

Generally the title bar and window border is provided by the window
manager or operating system and therefore its appearance is not under
the control of your program.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze

On 23.02.2016 01:48, Ian Kelly wrote:

On Mon, Feb 22, 2016 at 3:16 PM, Sven R. Kunze  wrote:

Is something like shown in 12:50 ( cout << tcp_reader(1000).get() ) possible
with asyncio? (tcp_reader would be async def)

loop = asyncio.get_event_loop()
print(loop.run_until_complete(tcp_reader(1000)))


I see. Thanks. :)

How come that Python (compared to C++) needs much more boilerplate to 
use async programming? Historically, it was the other way round.


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


DIPY 0.11.0 is now available for download

2016-02-23 Thread Eleftherios Garyfallidis
Dear all,


We are excited to announce a new public release of Diffusion Imaging in
Python (DIPY).

The 0.11 release follows closely on the heels of the 0.10 release,
resolving issues that existed in that release on the Windows 64 bit
platform. New features of the 0.11 and 0.10 release cycles include many
additional fixes and new frameworks. Here are some of the highlights:

DIPY 0.11.0 (Monday, 21 February 2016):

- New framework for contextual enhancement of ODFs.

- Compatibility with new version of numpy (1.11).

- Compatibility with VTK 7.0 which supports Python 3.x.

- Faster PIESNO for noise estimation.

- Reorient gradient directions according to motion correction parameters.

- Supporting Python 3.3+ but not 3.2.

- Reduced memory usage in DTI prediction.

- DSI now can use datasets with multiple b0s.

- Fixed different issues with Windows 64bit and Python 3.5.

DIPY 0.10.1 (Friday, 4 December 2015):

- Compatibility with new versions of scipy (0.16) and numpy (1.10).

- New cleaner visualization API, including compatibility with VTK 6, and
functions to create your own interactive visualizations.

- Diffusion Kurtosis Imaging (DKI): Google Summer of Code work by Rafael
Henriques.

- Mean Apparent Propagator (MAP) MRI for tissue microstructure estimation.

- Anisotropic Power Maps from spherical harmonic coefficients.

- A new framework for affine registration of images.

Detailed release notes can be found here:

http://dipy.org/release0.11.html

http://dipy.org/release0.10.html

To upgrade, run the following command in your terminal:


pip install --upgrade dipy

For the complete installation guide look here:

http://dipy.org/installation.html

For any questions go to http://dipy.org, or https://neurostars.org or send
an e-mail to neuroimag...@python.org

We also have a new instant messaging service and chat room available at
https://gitter.im/nipy/dipy

On behalf of the DIPY developers,

Eleftherios Garyfallidis & Ariel Rokem

http://dipy.org/developers.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: good python tutorial

2016-02-23 Thread Aaron Christensen
Thanks for sharing!

On Tue, Feb 23, 2016 at 1:48 AM, Mike S via Python-list <
python-list@python.org> wrote:

> This site was recommended by a friend, it looks really well put together,
> I thought it might be of interest to people considering online tutorials.
>
> http://www.python-course.eu/index.php
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


nosepipe error

2016-02-23 Thread Dan Stromberg
Hi folks.

I'm using (or trying to use) nosepipe to get nose test isolation; I'm
working on an almost-big test suite, and the tests appear to be
lacking test isolation.

I'm encountering a bug in nosepipe:
==
ERROR: testCreateFileMux (testFilemux.TestFilemux)
--
Traceback (most recent call last):
  File 
"/home/dstromberg/virtualenvs/dev/lib/python2.7/site-packages/nose/case.py",
line 133, in run
self.runTest(result)
  File 
"/home/dstromberg/virtualenvs/dev/lib/python2.7/site-packages/nose/case.py",
line 151, in runTest
test(result)
  File 
"/home/dstromberg/virtualenvs/dev/lib/python2.7/site-packages/nosepipe.py",
line 179, in __call__
(header + data).decode("latin1"))
Exception: short message body (want 1433299041, got 80)
Something went wrong
Message: Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr

That 1433299041 looks like ASCII:
>>> hex(1433299041)
'0x556e6861'
>>> chr(0x55) + chr(0x6e) + chr(0x68) + chr(0x61)
'Unha'

...but I'm not sure where to go with that from there.

The authors appear to be: John J. Lee, Dan McCombs, and Vadim Markovtsev.

I've e-mailed John and Dan - though that was only last night.  I don't
know how to get in touch with Vadim.

Are there any nosepipe users out there?  Does anyone know how best to
reach John, Dan and/or Vadim?

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


Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Ian Kelly
On Tue, Feb 23, 2016 at 9:50 AM, Sven R. Kunze  wrote:
> On 23.02.2016 01:48, Ian Kelly wrote:
>>
>> On Mon, Feb 22, 2016 at 3:16 PM, Sven R. Kunze  wrote:
>>>
>>> Is something like shown in 12:50 ( cout << tcp_reader(1000).get() )
>>> possible
>>> with asyncio? (tcp_reader would be async def)
>>
>> loop = asyncio.get_event_loop()
>> print(loop.run_until_complete(tcp_reader(1000)))
>
>
> I see. Thanks. :)
>
> How come that Python (compared to C++) needs much more boilerplate to use
> async programming? Historically, it was the other way round.

It's not entirely clear to me what the C++ is actually doing. With
Python we have an explicit event loop that has to be started to manage
resuming the coroutines. Since it's explicit, you could easily drop in
a different event loop, such as Tornado or curio, if desired. If your
coroutine never awaits anything that isn't already done then
technically you don't need an event loop, but at that point you might
as well be using ordinary functions.

The C++ on the other hand seems to be doing something implicit at the
compiler level to make everything happen automatically inside the
future.get() call, but I don't know what that is.

You could wrap up the boilerplate in Python if you like:

def get(coro, loop=None):
if loop is None:
loop = asyncio.get_event_loop()
return loop.run_until_complete(coro)

print(get(tcp_reader(1000)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nosepipe error

2016-02-23 Thread Chris Angelico
On Wed, Feb 24, 2016 at 4:36 AM, Dan Stromberg  wrote:
> Message: Unhandled exception in thread started by
> sys.excepthook is missing
> lost sys.stderr
>
> That 1433299041 looks like ASCII:
 hex(1433299041)
> '0x556e6861'
 chr(0x55) + chr(0x6e) + chr(0x68) + chr(0x61)
> 'Unha'
>
> ...but I'm not sure where to go with that from there.

My eye sees those characters as being the beginning of "Unhandled
exception in thread". You could be dealing with multiple levels of
cascading exceptions.

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


Re: nosepipe error

2016-02-23 Thread Dan Stromberg
On Tue, Feb 23, 2016 at 9:43 AM, Chris Angelico  wrote:
> On Wed, Feb 24, 2016 at 4:36 AM, Dan Stromberg  wrote:
>> Message: Unhandled exception in thread started by
>> sys.excepthook is missing
>> lost sys.stderr
>>
>> That 1433299041 looks like ASCII:
> hex(1433299041)
>> '0x556e6861'
> chr(0x55) + chr(0x6e) + chr(0x68) + chr(0x61)
>> 'Unha'
>>
>> ...but I'm not sure where to go with that from there.
>
> My eye sees those characters as being the beginning of "Unhandled
> exception in thread". You could be dealing with multiple levels of
> cascading exceptions.

Agreed - at least "Unhandled exception".

I'm seeing, in the nosepipe code:
# we use stdout for IPC, so block all other output
self._stream = sys.__stdout__

I'm not sure using stdout/stdin for IPC is a great thing; a lot of
tests write to stdout or stderr, whether intentionally or
unintentionally.

I'm attempting to replace the use of stdout/stdin with os.pipe(), but
so far I'm not having much luck.  I get three write()'s, and then a
hang.  So far, I'm ignoring the fact that os.read() and os.write()
might split or aggregate chunks over a socket, since this is a
socketpair communicating on the same machine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nosepipe error

2016-02-23 Thread Chris Angelico
On Wed, Feb 24, 2016 at 5:11 AM, Dan Stromberg  wrote:
> I'm seeing, in the nosepipe code:
> # we use stdout for IPC, so block all other output
> self._stream = sys.__stdout__
>
> I'm not sure using stdout/stdin for IPC is a great thing; a lot of
> tests write to stdout or stderr, whether intentionally or
> unintentionally.

Using standard streams for IPC is well recognized. If it's known in
advance, it shouldn't be a problem - writing to stdout/stderr would
simply result in a test failure.

> I'm attempting to replace the use of stdout/stdin with os.pipe(), but
> so far I'm not having much luck.  I get three write()'s, and then a
> hang.  So far, I'm ignoring the fact that os.read() and os.write()
> might split or aggregate chunks over a socket, since this is a
> socketpair communicating on the same machine.

Sounds like the buffer's full. You'll need to have another thread
reading before you start writing, to prevent that.

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


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Marko Rauhamaa
Paul Rubin :

> Marko Rauhamaa  writes:
>> It is also correct that /dev/urandom depletes the entropy pool as
>> effectively as /dev/random. 
>
> I think see what's confusing you: the above is a misconception that is
> probably held by lots of people.  Entropy is not water and from a
> cryptographic standpoint there is essentially no such thing as
> "depleting" an entropy pool.  There is either enough entropy (say 256
> bits or more) in the PRNG or else there isn't.  If there's not enough,
> urandom can misbehave by giving you bad output because it doesn't block
> until more is gathered.  If there is enough, /dev/random misbehaves by
> blocking under this bogus concept of "depletion".

You are making my point. /dev/random is correct to block until
top-quality random numbers can be supplied. That's not misbehaving.

> So once /dev/random unblocks, it should never again block, the behavior
> of getrandom.

What you are saying is that /dev/random has no reason to exist (and the
GRND_RANDOM flag to getrandom() is redundant).

I'm no cryptographer and can't judge that. However, as long as the
distinction is maintained, I have to abide by the documented
characteristics.

> No really, all you've done is repeat bad advice. The people cited in
> that article are very knowledgeable and the stuff they say makes good
> mathematical sense. The stuff you say makes no sense and you haven't
> given any convincing reason for anyone to listen to you.

Thing is, neither you nor me nor the cited articles has provided any
more info than insisting on a position, my position being relying on the
documented API.

So we have

 * /dev/urandom vs /dev/random

 * getrandom(0) vs getrandom(GRND_RANDOM)

 * GCRY_STRONG_RANDOM ("Use this level for session keys and similar
   purposes") vs GCRY_VERY_STRONG_RANDOM ("Use this level for long term
   key material") (in libgcrypt)

You don't need to convince me that that distinction is silly. You need
to convince the crypto facility providers.


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


Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze

On 23.02.2016 18:37, Ian Kelly wrote:

It's not entirely clear to me what the C++ is actually doing. With
Python we have an explicit event loop that has to be started to manage
resuming the coroutines. Since it's explicit, you could easily drop in
a different event loop, such as Tornado or curio, if desired. If your
coroutine never awaits anything that isn't already done then
technically you don't need an event loop, but at that point you might
as well be using ordinary functions.


I don't think taking the shortcut to ordinary functions will work on the 
big scale.


I certainly agree that asynchronous operations can/should? be the very 
core of everything (files, sockets, timers, etc.); just as Microsoft is 
pushing with their Windows API. Chaining async ops together just works 
now with async/await in Python as well. However, in the end of the 
chaining there'll always be synchronous code that e.g. initializes the 
event loop. Real world code works the same.


Imagine, in some near/distant future, Python might have all its core 
components (like reading a file, etc. etc.) converted to async. It would 
be great for many larger applications if there one could introduce async 
gently. So, laying out an async foundation (the building blocks) but the 
wiring synchronous operations still work as they should. Once, the team 
decides they want to leverage the async potential in their code (as the 
building blocks COULD be executed concurrently), they will then be able 
to replace the synchronous wires with an event loop.


So, I see quite some potential here.


The C++ on the other hand seems to be doing something implicit at the
compiler level to make everything happen automatically inside the
future.get() call, but I don't know what that is.

You could wrap up the boilerplate in Python if you like:

def get(coro, loop=None):
 if loop is None:
 loop = asyncio.get_event_loop()
 return loop.run_until_complete(coro)

print(get(tcp_reader(1000)))


As usual. :)

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


Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze

On 20.02.2016 07:53, Christian Gollwitzer wrote:
If you have difficulties wit hthe overall concept, and if you are open 
to discussions in another language, take a look at this video:


https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines 



MS has added coroutine support with very similar syntax to VC++ 
recently, and the developer tries to explain it to the "stackful" 
programmers.


Because of this thread, I finally finished an older post collecting 
valuable insights from last year discussions regarding concurrency 
modules available in Python: 
http://srkunze.blogspot.com/2016/02/concurrency-in-python.html It 
appears to me that it would fit here well.


@python-ideas
Back then, the old thread ("Concurrency Modules") was like basically 
meant to result in something useful. I hope the post covers the essence 
of the discussion.
Some even suggested putting the table into the Python docs. I am unaware 
of the formal procedure here but I would be glad if somebody could point 
be at the right direction if that the survey table is wanted in the docs.


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


exit from Tkinter mainloop Python 2.7

2016-02-23 Thread kevind0718
Hello:



Newbie here.

Spent the a good part of the day tinkering and reading tutorials,
I was able to create a sample that is very close to my requirement.

When I execute the code below the Dialog displayed as expected and
I can enter data into the textboxes.  All good.

When I click on butGo I get the error below.
So is this some sort of scope error?
why does entryName not exist for me to grab it's value?

Your kind assistance is requested.


Traceback (most recent call last):
  File "C:\Users\kduffy12\workspace\testPythonA\testA\simpleDialog.py", line 
25, in 
print entryName.get("1.0", "end-1c" )
AttributeError: 'NoneType' object has no attribute 'get'




from Tkinter import *


def butContinue():
root1.destroy()

root1 = Tk()
root1.geometry("500x250")


lblTop = Label(root1, text= '  Enter Values Below', font="Helvetica 
14").grid(row=0, column=0, columnspan=2 , pady=5)
##lblTop.pack(side = TOP)

lblDB = Label(root1,text= 'Weight').grid(row=1, column=0 )
lblPWord = Label(root1, text= 'Height').grid(row=2,column=0)
entryName = Entry(root1).grid(row=1, column=1, pady=5)

entryPWord = Entry(root1).grid(row=2, column=1, pady = 5)

butGo  =  Button(root1, text="   Continue "  , command=butContinue 
).grid(row=3, column=1, sticky=W, pady=10)


root1.mainloop()

print entryName.get("1.0", "end-1c" )
print entryPWord.get("1.0", "end-1c" )
-- 
https://mail.python.org/mailman/listinfo/python-list


[Newbie] Tkinter Question

2016-02-23 Thread Wildman via Python-list
I am familiar with OO programming but I am new to Python
and Tkinter.  I am working on a gui program that creates
a couple of temporary files.  As part of the Exit button
command they are deleted.  If the program is shut down
using the window close button [X], the exit button code
is not executed and the temporary files are left behind.
That is a serious no-no.

Is there a way to capture close button click to prevent
the program from closing and instead execute a command?
I'm talking about something like the Form_QueryUnload
event in Visual Basic.

Alternately is there a way to just disable the button
or prevent it from being displayed in the first place?

Any help appreciated.

-- 
 GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
  -Benjamin Franklin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exit from Tkinter mainloop Python 2.7

2016-02-23 Thread Christian Gollwitzer

Am 23.02.16 um 22:39 schrieb kevind0...@gmail.com:

from Tkinter import *

def butContinue():
 root1.destroy()
[...]
entryName = Entry(root1).grid(row=1, column=1, pady=5)
[...]
butGo  =  Button(root1, text="   Continue "  , command=butContinue 
).grid(row=3, column=1, sticky=W, pady=10)

root1.mainloop()

print entryName.get("1.0", "end-1c" )



When I click on butGo I get the error below.
So is this some sort of scope error?
why does entryName not exist for me to grab it's value?


You call destroy() on the root window of Tk. If you destroy a window, 
that will destroy all of it's children. Therefore by deleting the root 
window, also the entryName widget was deleted. You need to export the 
values before you close the window, i.e. in the butContinue() function.


There is another pitfall with Tk: if you delete the main window, you can 
get problems if you try to recreate it. If you want to show several 
pages in sequence or the like, you should withdraw the main window


root1.withdraw()

and popup a fresh toplevel by

t=Toplevel()
and do everything in t. Once you are finished, destroying t will keep 
your application alive (because the real root window is just hidden)


Another comment:

> root1.geometry("500x250")

Do not do this. The grid and pack geometry managers compute the needed 
space automatically. A fixed size in pixels can easily break, when you 
go to another computer with a different font size, screen resolution, or 
a different OS. If you are not satisfied with the whitespace, use the 
padding options of grid or pack.


Christian

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


Re: exit from Tkinter mainloop Python 2.7

2016-02-23 Thread Christian Gollwitzer

Am 23.02.16 um 22:39 schrieb kevind0...@gmail.com:

lblTop = Label(root1, text= '  Enter Values Below', font="Helvetica 
14").grid(row=0, column=0, columnspan=2 , pady=5)
##lblTop.pack(side = TOP)

lblDB = Label(root1,text= 'Weight').grid(row=1, column=0 )
lblPWord = Label(root1, text= 'Height').grid(row=2,column=0)


Also here, the labels look odd. Have you tried to do some alignment of 
the text with spaces? Remove the sapces and look at the "justify" option 
of the label widget and the "sticky" option for grid.


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


Re: [Newbie] Tkinter Question

2016-02-23 Thread Christian Gollwitzer

Am 23.02.16 um 23:19 schrieb Wildman:

I am familiar with OO programming but I am new to Python
and Tkinter.  I am working on a gui program that creates
a couple of temporary files.  As part of the Exit button
command they are deleted.  If the program is shut down
using the window close button [X], the exit button code
is not executed and the temporary files are left behind.
That is a serious no-no.

Is there a way to capture close button click to prevent
the program from closing and instead execute a command?


It's done using the WM_DELETE_WINDOW protocol:

http://stackoverflow.com/questions/55/how-do-i-handle-the-window-close-event-in-tkinter

Your program could still be killed by another way, e.g. from the task 
manager, which would leave the files behind.


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


Re: [Newbie] Tkinter Question

2016-02-23 Thread Chris Kaynor
On Tue, Feb 23, 2016 at 2:19 PM, Wildman via Python-list <
python-list@python.org> wrote:

> I am familiar with OO programming but I am new to Python
> and Tkinter.  I am working on a gui program that creates
> a couple of temporary files.  As part of the Exit button
> command they are deleted.  If the program is shut down
> using the window close button [X], the exit button code
> is not executed and the temporary files are left behind.
> That is a serious no-no.
>
> Is there a way to capture close button click to prevent
> the program from closing and instead execute a command?
> I'm talking about something like the Form_QueryUnload
> event in Visual Basic.
>
> Alternately is there a way to just disable the button
> or prevent it from being displayed in the first place?
>
> Any help appreciated.
>

There are a few options involved, however one other case to consider is if
the user force kills the app (or the whole system is shut down improperly,
such as a power loss). In those cases, should the temp files be removed? If
yes, you'll need to use OS features to ensure the files are properly
deleted by letting the OS know they are temporary.

If the temp files need to be removed no matter what, the primary option is
something like
https://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile
using the delete=True arguments. Alternatively, you can probably use
os.open with O_TEMPORARY (I belive this is the same
as FILE_FLAG_DELETE_ON_CLOSE in the Win32 API, and there is probably
something similar for Linux).

If you only care if the user closes the app properly (no ending the process
on Windows), you can perform the clean-up when the mainloop returns, aka
Tkinter.Tk().mainloop(). Based off other GUI systems, this will only occur
once all windows have been closed. Another option would be to use Python's
atexit library: https://docs.python.org/3/library/atexit.html. atexit has
the advantage that you could register/unregister the handlers when needed,
rather than maintaining your own list to clean-up. Tkinter may also have
some hook you can use to get when it is exiting, but I do not know what
that is. The same limitations regarding OS exits will apply, however.

If you need somewhere in the middle, you can try signal handlers, which,
for some types of external exits, will fire, but it is not certain.

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


Re: exit from Tkinter mainloop Python 2.7

2016-02-23 Thread Peter Otten
Christian Gollwitzer wrote:

> Am 23.02.16 um 22:39 schrieb kevind0...@gmail.com:
>> from Tkinter import *
>>
>> def butContinue():
>>  root1.destroy()
>> [...]
>> entryName = Entry(root1).grid(row=1, column=1, pady=5)
>> [...]
>> butGo  =  Button(root1, text="   Continue "  , command=butContinue
>> ).grid(row=3, column=1, sticky=W, pady=10)
>>
>> root1.mainloop()
>>
>> print entryName.get("1.0", "end-1c" )
> 
>> When I click on butGo I get the error below.
>> So is this some sort of scope error?
>> why does entryName not exist for me to grab it's value?
> 
> You call destroy() on the root window of Tk. If you destroy a window,
> that will destroy all of it's children. Therefore by deleting the root
> window, also the entryName widget was deleted. You need to export the
> values before you close the window, i.e. in the butContinue() function.

Even when you follow this advice, entryName was set to None by the line

>> entryName = Entry(root1).grid(row=1, column=1, pady=5)

as grid() always returns None. You need two steps

entryName = Entry(root1)
entryName.grid(row=1, column=1, pady=5)

Also,

>> print entryName.get("1.0", "end-1c" )

I believe that the Entry widget's get() method doesn't take any arguments.

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


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Steven D'Aprano
On Tue, 23 Feb 2016 05:54 pm, Marko Rauhamaa wrote:

> Steven D'Aprano :
> 
>> On Tue, 23 Feb 2016 06:32 am, Marko Rauhamaa wrote:
>>> Under Linux, /dev/random is the way to go when strong security is
>>> needed. Note that /dev/random is a scarce resource on ordinary
>>> systems.
>>
>> That's actually incorrect, but you're not the only one to have been
>> mislead by the man pages.
>>
>> http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
> 
> Still, mostly hypnotic repetitions.

Repetition for the sake of emphasis, because there are so many misled and
confused people on the internet who misunderstand the difference between
urandom and random and consequently give bad advice. I believe that the
Linux man page for urandom is to blame, although I don't know why it hasn't
been fixed.

Possibly because it is *technically* correct, in the sense of "if you are
concerned by the risk of being hit by a meteorite, wearing a stainless
steel cooking pot on your head will give you some protection from meteorite
strikes to the head". Everything in it is technically correct, but
misleading.


> However, it admits:
> 
>But /dev/random also tries to keep track of how much entropy remains
>in its kernel pool, and will occasionally go on strike if it decides
>not enough remains.
> 
> That's the whole point. 

Exactly, but you've missed the point. That is precisely why the blocking
random is HARMFUL and should not be used. There is one, and only one,
scenario when your CSPRNG should block: before the system has enough
entropy to securely seed the CSPRNG and it is at risk of returning
predictable numbers.

But after that point has passed, there is no test you can perform to
distinguish the outputs of /dev/random and /dev/urandom (apart from the
blocking behaviour itself). If I give you a million numbers, there is no
way you can tell whether I used random or urandom.

The important thing here is that there is no difference in "quality"
(whatever that means!) between the random numbers generated by urandom and
those generated by random. They are equally unpredictable. They pass the
same randomness tests. Neither is "better" or "worse" than the other,
because they are both generated by the same CSPRNG or HRNG.

Here is a summary of the random/urandom distinction on various Unixes:


Linux: 
random blocks, urandom never blocks, both use the same CSPRNG 
based on SHA-1 hashes, both will use a HRNG if available

FreeBSD:
urandom is a link to random, which never blocks; uses 256-bit 
Yarrow CSPRNG, will use a HRNG if available

OpenBSD:
both never block; both use a variant of the RC4 CSPRNG 
(misleadingly renamed ARC4 due to licencing issues), in
newer versions use the ChaCha20 CSPRNG

OS X:
both never block and use 160-bit Yarrow

NetBSD:
random blocks, urandom never blocks, both use the same AES-128
CSPRNG


The NetBSD man pages are quite scathing:


"The entropy accounting described here is not grounded in any
cryptography theory.  It is done because it was always done, 
and because it gives people a warm fuzzy feeling about 
information theory.

...

History is littered with examples of broken entropy sources and
failed system engineering for random number generators.  Nobody 
has ever reported distinguishing AES ciphertext from uniform 
random without side channels, nor reported computing SHA-1 
preimages faster than brute force.  The folklore information-
theoretic defence against computationally unbounded attackers 
replaces system engineering that successfully defends against 
realistic threat models by imaginary theory that defends only 
against fantasy threat models."


To be clear, the "folklore information-theoretic defence" they are referring
to is /dev/random's blocking behaviour.

http://netbsd.gw.com/cgi-bin/man-cgi?rnd+4+NetBSD-current


The blocking behaviour of /dev/random (on Linux) doesn't solve any real
problems, but it *creates* new problems. /dev/random can block for minutes
or even hours, especially straight after booting a freshly installed OS.
This can be considered a Denial Of Service attack, and even if it isn't, it
encourages developers to "fix" the problem by using their own home-brewed
random numbers, weakening the security of the system.

There's even a minority viewpoint that constantly adding new entropy to the
CSPRNG is useless. Apart from collecting sufficient entropy for the initial
seed, you should never add new entropy to the CSPRNG. Your CSPRNG is either
cryptographically strong, or it isn't. If it is, then it is already
unpredictable and adding more entropy is a waste of time. If it isn't, then
adding more entropy isn't going to help you.

Adding entropy is just one more component that can contain bugs (see the
NetSBD comment about "broken entropy sources") or even allow an attack on
the CSPRNG:

http://blog.cr.yp.to/20140205-entropy.html

There's one good argument for 

Network Simulator

2016-02-23 Thread nikhil amraotkar
Hi...I need help to design a network simulator consisting for 5 routers in 
python...Any help would be appretiated...
Thanks..
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Network Simulator

2016-02-23 Thread Joel Goldstick
On Tue, Feb 23, 2016 at 9:54 PM, nikhil amraotkar <
nikhil.amraotk...@gmail.com> wrote:

> Hi...I need help to design a network simulator consisting for 5 routers in
> python...Any help would be appretiated...
> Thanks..
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/ 
http://cc-baseballstats.info/
-- 
https://mail.python.org/mailman/listinfo/python-list


How may I change values in tuples of list of lists?

2016-02-23 Thread subhabangalore
Hi 

I am trying to use the following set of tuples in list of lists. 
I am using a Python based library named, NLTK. 

>>> import nltk
>>> from nltk.corpus import brown as bn
>>> bt=bn.tagged_sents()
>>> bt_5=bt[:5]
>>> print bt
[[(u'The', u'AT'), (u'Fulton', u'NP-TL'), (u'County', u'NN-TL'), (u'Grand', 
u'JJ-TL'), (u'Jury', u'NN-TL'), (u'said', u'VBD'), (u'Friday', u'NR'), (u'an', 
u'AT'), (u'investigation', u'NN'), (u'of', u'IN'), (u"Atlanta's", u'NP$'), 
(u'recent', u'JJ'), (u'primary', u'NN'), (u'election', u'NN'), (u'produced', 
u'VBD'), (u'``', u'``'), (u'no', u'AT'), (u'evidence', u'NN'), (u"''", u"''"), 
(u'that', u'CS'), (u'any', u'DTI'), (u'irregularities', u'NNS'), (u'took', 
u'VBD'), (u'place', u'NN'), (u'.', u'.')], [(u'The', u'AT'), (u'jury', u'NN'), 
(u'further', u'RBR'), (u'said', u'VBD'), (u'in', u'IN'), (u'term-end', u'NN'), 
(u'presentments', u'NNS'), (u'that', u'CS'), (u'the', u'AT'), (u'City', 
u'NN-TL'), (u'Executive', u'JJ-TL'), (u'Committee', u'NN-TL'), (u',', u','), 
(u'which', u'WDT'), (u'had', u'HVD'), (u'over-all', u'JJ'), (u'charge', u'NN'), 
(u'of', u'IN'), (u'the', u'AT'), (u'election', u'NN'), (u',', u','), (u'``', 
u'``'), (u'deserves', u'VBZ'), (u'the', u'AT'), (u'praise', u'NN'), (u'an
 d', u'CC'), (u'thanks', u'NNS'), (u'of', u'IN'), (u'the', u'AT'), (u'City', 
u'NN-TL'), (u'of', u'IN-TL'), (u'Atlanta', u'NP-TL'), (u"''", u"''"), (u'for', 
u'IN'), (u'the', u'AT'), (u'manner', u'NN'), (u'in', u'IN'), (u'which', 
u'WDT'), (u'the', u'AT'), (u'election', u'NN'), (u'was', u'BEDZ'), 
(u'conducted', u'VBN'), (u'.', u'.')], ...]
>>> 

Now if I want to change the values of tags like 'AT', 'NP-TL', 'NN-TL', etc. to 
some arbitrary ones like XX,YY,ZZ and yet preserve total structure of tuples in 
list of lists, please suggest how may I do it. 

I donot think it is an NLTK issue, rather a Python issue. 
I am trying to access and change but using 
for i,j in enumerate(bt_5), etc. bit long stuff.

If any one may kindly suggest a smart line of code. 

I am using Python2.7.11 on MS-Windows-10. My NLTK version is 3.1

Thanks in advance.

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


Re: How may I change values in tuples of list of lists?

2016-02-23 Thread Ben Finney
subhabangal...@gmail.com writes:

> Now if I want to change the values of tags like 'AT', 'NP-TL',
> 'NN-TL', etc. to some arbitrary ones like XX,YY,ZZ and yet preserve
> total structure of tuples in list of lists, please suggest how may I
> do it. 

Changing items in lists is done by assigning to an index in that list,
using index syntax::

big_list[17] = new_value

This works because a list is a homogeneous mutable sequence: no position
in the sequence has any special meaning, and you can change any of the
items in the sequence to refer to a different value.

Choosing the list type to represent a structure is a choice to express
“this sequence doesn't mean anything except the particular ordering of
these items, and changing any of the values doesn't change the meaning
of this sequence”.


I think your question boils down to “how do I change one item in a
tuple?”. If that's the essence of the question, the other stuff about
where the tuple is found are irrelevant to solving this.

The answer to that question is: you don't. Instead, you create a new
tuple.


A tuple is immutable; the programmer, by choosing the tuple type, has
chosen to express “this sequence is a single complex value, where the
total set of items in this order has its own meaning, and if any of its
items were different this would have a different meaning”.

So, to create a new tuple based on an existing tuple, you need to
specify each item in the new tuple. If you want some of the items in the
new tuple to be from the existing tuple, you need to access those.

foo = ('Fulton', 'NP-TL')
bar = tuple(foo[0], 'XX')

Is this awkward? Yes, so you should be thinking hard about whether
you're fighting against the intent of the existing data structure.

The programmer either made a bad design choice; or the choice of tuple
type was for a good purpose. You should lean toward the latter until you
know more about the program.

-- 
 \  “It seems intuitively obvious to me, which means that it might |
  `\   be wrong.” —Chris Torek |
_o__)  |
Ben Finney

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


Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Marko Rauhamaa
Steven D'Aprano :

> On Tue, 23 Feb 2016 05:54 pm, Marko Rauhamaa wrote:
>> However, when you are generating signing or encryption keys, you
>> should use /dev/random.
>
> And that is where you repeat something which is rank superstition.

Can you find info to back that up. All I've seen so far is forceful
claims that's superstition ("These are not the droids you're looking
for"). Even the ssh-keygen man page has:

The reseeding of the OpenSSL random generator is usually done from
/dev/urandom. If the SSH_USE_STRONG_RNG environment vari‐ able is
set to value other than 0 the OpenSSL random generator is reseeded
from /dev/random.


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