Karlsruhe (Germany) Python User Group, August 15th 2014, 7pm

2014-08-08 Thread Jürgen A . Erhard
The Karlsruhe Python User Group (KaPy) meets again.

Friday, 2014-08-15 (August 15th) at 19:00 (7pm) in the rooms of Entropia eV
(the local affiliate of the CCC).  See http://entropia.de/wiki/Anfahrt
on how to get there.

For your calendars: meetings are held monthly, on the 3rd Friday.

There's also a mailing list at
https://lists.bl0rg.net/cgi-bin/mailman/listinfo/kapy.
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


new devpi-2.0.1/2 releases: fixes, new anonymous upload

2014-08-08 Thread holger krekel

The new devpi releases (devpi-server-2.0.2, devpi-web-2.0.1, devpi-client-2.0.1)
contain several fixes for the private github-style pypi caching server, 
see the changelog below for details.  Find all the documentation at

http://doc.devpi.net/latest

with tutorials and quickstart documents for particular scenarios.

Note that no export/import procedure is needed if you are already running
a 2.X devpi-server.  If upgrading from a 1.2 devpi-server install, you need
to upgrade using these instructions:

http://doc.devpi.net/latest/quickstart-server.html#versioning-exporting-and-importing-server-state

many thanks to Florian Schulze who again helped a lot with this release.

have fun,

holger krekel

devpi-2.0.1 (metapackage)
-

devpi-server-2.0.2:
   
- fix issue120: link to upgrade section from main index page.

- preserve http reason string for setup.py submit through replica proxying

- proper error message when devpi push X uses an X that comes from 
  a base index or is not existent

- fix issue121: depend on py-1.4.23 to fix python3.4 compatibility
  for a venusian/py34/py interaction import oddity.

- fix issue126: handle deletion of pypi project cache entries correctly 
  (i.e. ones that are triggered by refresh on simple page).

- Add special handling of :ANONYMOUS: user in acl_upload to allow anonymous
  submit.

- fix nginx template so that when used in a replica setting the master
  always answers HEAD requests without nginx short-cirtcuiting it.

- increase internal cache size to improve performance when many indexes
  and projects are served.

devpi-web-2.0.1:

- fix issue125: javascript for embedded doc view didn't work correctly.

- fix issue118: rendering of description with unicode.

devpi-client-2.0.1:
 
- fix a test to expect a 403 instead of a 401 from devpi server from
  unauthorized access 

- fix error message on API version client/server mismatch

- fix issue124: package name url matching for the devpi test command


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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


pytest-timeout 0.4

2014-08-08 Thread Floris Bruynooghe
Hi,

I'm pleased to announce the availability of pytest-timeout 0.4:
https://pypi.python.org/pypi/pytest-timeout/0.4

pytest-timeout is a plugin for the py.test testing framework which
will interrupt hanging tests after a timeout and show stack traces for
all threads at this time.  This can greatly easy debugging certain
issues, especially when running tests on continuous integration
server.

This release provides support for using pytest-timeout in conjunction
with the --pdb option from py.test.  When a test fails and py.test
drops you into an interactive pdb session pytest-timeout will now no
longer time-out the test.

Additionally this release fixes a bug where a hang in the teardown of
a session-scoped fixture would not be caught by pytest-timeout.


Regards,
Floris

-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


pytest-2.6.1: fixes and expecting exceptions in xfail

2014-08-08 Thread holger krekel
pytest-2.6.1: fixes and new xfail marker feature
===

pytest is a mature Python testing tool with an extensive self-test test suite,
passing on many different interpreters and platforms.  The 2.6.1 release
is drop-in compatible to 2.5.2 and actually fixes some regressions
introduced with 2.6.0.  It also brings a little feature to the xfail
marker which now recognizes expected exceptions, see the CHANGELOG below.

See docs at:

http://pytest.org

As usual, you can upgrade from pypi via::

pip install -U pytest

Thanks to all who contributed, among them:

Floris Bruynooghe
Bruno Oliveira
Nicolas Delaby

have fun,
holger krekel

Changes 2.6.1
=

- No longer show line numbers in the --verbose output, the output is now
  purely the nodeid.  The line number is still shown in failure reports.
  Thanks Floris Bruynooghe.

- fix issue437 where assertion rewriting could cause pytest-xdist slaves
  to collect different tests. Thanks Bruno Oliveira.

- fix issue555: add errors attribute to capture-streams to satisfy
  some distutils and possibly other code accessing sys.stdout.errors.

- fix issue547 capsys/capfd also work when output capturing (-s) is disabled.

- address issue170: allow pytest.mark.xfail(...) to specify expected exceptions 
via
  an optional raises=EXC argument where EXC can be a single exception
  or a tuple of exception classes.  Thanks David Mohr for the complete
  PR.

- fix integration of pytest with unittest.mock.patch decorator when
  it uses the new argument.  Thanks Nicolas Delaby for test and PR.

- fix issue with detecting conftest files if the arguments contain
  :: node id specifications (copy pasted from -v output)

- fix issue544 by only removing @NUM at the end of :: separated parts
  and if the part has an .py extension

- don't use py.std import helper, rather import things directly.
  Thanks Bruno Oliveira.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Jaydeep Patil
Chris,
I mean to say, One GUI should be always on top from start to end of code 
running.
So that user cant do any other operation.
I am using wxpython

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil patil.jay2...@gmail.com wrote:
 I mean to say, One GUI should be always on top from start to end of code 
 running.
 So that user cant do any other operation.
 I am using wxpython

Ah, that would be called System Modal, and should be reserved for
absolutely critical system-wide alerts. It's also a feature that's
simply not available to most user-space programs, and not available in
most GUI toolkits.

Short answer: Don't.

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


Re: AttributeError: 'module' object has no attribute 'fork'

2014-08-08 Thread Rustom Mody
On Friday, August 8, 2014 11:18:17 AM UTC+5:30, Steven D'Aprano wrote:
 Rustom Mody wrote:

  On Thursday, August 7, 2014 10:26:56 PM UTC+5:30, Steven D'Aprano wrote:
  Roy Smith wrote:
Peter Otten  wrote:
   os.fork()
   Fork a child process.
   ...
   Availability: Unix.
   
   You are using the wrong operating system ;)
   To be honest, this could be considered a buglet in the os module.  It
   really should raise:
   NotImplementedError(fork() is only available on unix)
   or perhaps even, as Peter suggests:
   NotImplementedError(You are using the wrong operating system)
   either of those would be better than AttributeError.
  I disagree. How would you tell if fork is implemented? With the current
  behaviour, telling whether fork is implemented or not is simple:
  is_implemented = hasattr(os, fork)
 [...]
  Surely I am missing something but why not check os.fork before
  checking os.fork() ?

 Yes, you're missing something. That's what hasattr does.

 But with Roy's suggestion, testing for the existence of os.fork is not
 sufficient, because it will exist even on platforms where fork doesn't
 exist. So testing that os.fork exists is not sufficient to tell whether or
 not you can actually fork.

Windows:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type copyright, credits or license() for more information.
 import os
 os.fork

Traceback (most recent call last):
  File pyshell#1, line 1, in module
os.fork
AttributeError: 'module' object has no attribute 'fork'


Linux:

$ python
Python 2.7.8 (default, Jul  4 2014, 13:08:34) 
[GCC 4.9.0] on linux2
Type help, copyright, credits or license for more information.
 import os
 os.fork
built-in function fork
 


So yes, I continue to miss something...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: 'module' object has no attribute 'fork'

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 5:17 PM, Rustom Mody rustompm...@gmail.com wrote:
 But with Roy's suggestion, testing for the existence of os.fork is not
 sufficient, because it will exist even on platforms where fork doesn't
 exist. So testing that os.fork exists is not sufficient to tell whether or
 not you can actually fork.

 Windows:

 Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] 
 on win32
 Type copyright, credits or license() for more information.
 import os
 os.fork

 Traceback (most recent call last):
   File pyshell#1, line 1, in module
 os.fork
 AttributeError: 'module' object has no attribute 'fork'


 Linux:

 $ python
 Python 2.7.8 (default, Jul  4 2014, 13:08:34)
 [GCC 4.9.0] on linux2
 Type help, copyright, credits or license for more information.
 import os
 os.fork
 built-in function fork



 So yes, I continue to miss something...

I think the bit you're missing is the with Roy's suggestion bit, at
which os.fork() would be callable and would raise a different error.

It's of course possible for fork() to fail (no memory, ulimit hit, etc
etc etc), but I would expect that the presence of os.fork should
correspond perfectly to the API's availability (at least as detected
by Python's compilation testing).

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


Re: more simple to split the string?

2014-08-08 Thread Mark Lawrence

On 08/08/2014 01:23, elearn wrote:

str='(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'


First up it's not usually a good idea to override the builtin name str.


x=str.split(' ')
[i.replace('','') for i in x]
['(\\HasNoChildren \\Junk)', '/', '[Gmail]/V4NXPpCuTvY-']

x.strip( ) will create four parts.


I assume you meant x=str.split( ) ?  Even so I don't see how you can 
get four parts so please explain.




is there more simple to do that ?


No loop needed that I can see.

 oldstr='(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-';oldstr
'(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'
 newstr=oldstr.replace('', '');newstr
'(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'
 substrings=newstr.split();substrings
['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/V4NXPpCuTvY-']

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


Template language for random string generation

2014-08-08 Thread Paul Wolf
This is a proposal with a working implementation for a random string generation 
template syntax for Python. `strgen` is a module for generating random strings 
in Python using a regex-like template language. Example: 

 from strgen import StringGenerator as SG
 SG([\l\d]{8:15}[\d][\p]).render()
u'F0vghTjKalf4^mGLk'

The template ([\l\d]{8:15}[\d][\p]) generates a string from 8 to 15 
characters in length with letters, digits. It is guaranteed to have at least 
one digit (maybe more) and exactly one punctuation character. 

If you look at various forums, like Stackoverflow, on how to generate random 
strings with Python, especially for passwords and other hopefully secure 
tokens, you will see dozens of variations of this: 

import random
import string
mypassword = ''.join(random.choice(string.ascii_uppercase + 
string.digits) for x in range(10))

There is nothing wrong with this (it's the right answer and is very fast), but 
it leads developers to constantly:

* Use cryptographically weak methods
* Forget that the above does not guarantee a result that includes the different 
classes of characters
* Doesn't include variable length or minimum length output
* It's a lot of typing and the resulting code is vastly different each time 
making it hard to understand what features were implemented, especially for 
those new to the language
* You can extend the above to include whatever requirements you want, but it's 
a constant exercise in wheel reinvention that is extremely verbose, error prone 
and confusing for exactly the same purposes each time

This application (generation of random strings for passwords, vouchers, secure 
ids, test data, etc.) is so general, it seems to beg for a general solution. 
So, why not have a standard way of expressing these using a simple template 
language? 

strgen: 

* Is far less verbose than commonly offered solutions
* Trivial editing of the pattern lets you incorporate additional important 
features (variable length, minimum length, additional character classes, etc.)
* Uses a pattern language superficially similar to regular expressions, so it's 
easy to learn
* Uses SystemRandom class (if available, or falls back to Random)
* Supports  2.6 through 3.3
* Supports unicode
* Uses a parse tree, so you can have complex - nested - expressions to do 
tricky data generation tasks, especially for test data generation

In my opinion, it would make using Python for this application much easier and 
more consistent for very common requirements. The template language could 
easily be a cross-language standard like regex.  

You can `pip install strgen`. 

It's on Github: https://github.com/paul-wolf/strgen

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Paul Rudin
Chris Angelico ros...@gmail.com writes:

 On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil patil.jay2...@gmail.com wrote:
 I mean to say, One GUI should be always on top from start to end of code 
 running.
 So that user cant do any other operation.
 I am using wxpython

 Ah, that would be called System Modal, and should be reserved for
 absolutely critical system-wide alerts. It's also a feature that's
 simply not available to most user-space programs, and not available in
 most GUI toolkits.

 Short answer: Don't.

There are commercial software packages that do this sort of
thing. Examsoft is one - the idea being that people can take exams
without access to other software at the same time (so that, for example,
they could look at previously prepared notes).

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


Re: Template language for random string generation

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 7:01 PM, Paul Wolf paulwolf...@gmail.com wrote:
 This is a proposal with a working implementation for a random string 
 generation template syntax for Python. `strgen` is a module for generating 
 random strings in Python using a regex-like template language.

Looks good! One thing, though:

 * Supports  2.6 through 3.3

The implication of a simple reading of this statement is that your
code should run on 2.6, 2.7, 3.0, 3.1, 3.2, and 3.3, and hasn't been
tested on 3.4. But I eyeballed your code, and I'm seeing a lot of
u'string' prefixes, which aren't supported on 3.0-3.2 (they were
reinstated in 3.3 as per PEP 414), so a more likely version set would
be 2.6+, 3.3+. What's the actual version support?

Apologies for making such a minor quibble! But I'm curious as to what
you actually support.

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 6:57 PM, Paul Rudin paul.nos...@rudin.co.uk wrote:
 Chris Angelico ros...@gmail.com writes:

 On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil patil.jay2...@gmail.com 
 wrote:
 I mean to say, One GUI should be always on top from start to end of code 
 running.
 So that user cant do any other operation.
 I am using wxpython

 Ah, that would be called System Modal, and should be reserved for
 absolutely critical system-wide alerts. It's also a feature that's
 simply not available to most user-space programs, and not available in
 most GUI toolkits.

 Short answer: Don't.

 There are commercial software packages that do this sort of
 thing. Examsoft is one - the idea being that people can take exams
 without access to other software at the same time (so that, for example,
 they could look at previously prepared notes).

Yeah; like I said, Don't is the short answer. There will be
exceptions, some extremely rare situations when system modality is
correct; but fundamentally, it's impossible to use GUI software to
control what a person does with a computer (for instance, on all my
Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI
altogether). So I'm dubious about its value for anything that isn't an
absolutely critical alert. With the OS/2 Presentation Manager, I had
SystemModal available as a window flag, and I used it for two
purposes: an out-of-memory alert (or similarly critical resource
shortage), and a pseudo-login screen (it just asked for a name, no
password or anything, and it didn't change what you had access to - it
was for the purposes of logging and messaging identification, nothing
more); and the latter didn't really need to be system modal, it was
just for convenience.

If there's no way to make a wxpython window system modal, I would say
it's no great loss. The chances of the feature being misused are
extremely high; the cases where it's actually needed are extremely
rare. Hence my short answer of Don't; honestly, there are more times
when you need to optimize Python code for performance than there are
times to create system modal windows.

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


Re: Template language for random string generation

2014-08-08 Thread Paul Wolf
On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico  wrote:
 But I eyeballed your code, and I'm seeing a lot of
 u'string' prefixes, which aren't supported on 3.0-3.2 (they were
 reinstated in 3.3 as per PEP 414), so a more likely version set would
 
 be 2.6+, 3.3+. What's the actual version support?
 ChrisA

I'm going to have to assume you are right that I only tested on 3.3, skipping  
2.7 and  3.3. I'll create an issue for that. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Template language for random string generation

2014-08-08 Thread Ned Batchelder

On 8/8/14 5:42 AM, Paul Wolf wrote:

On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico  wrote:

But I eyeballed your code, and I'm seeing a lot of
u'string' prefixes, which aren't supported on 3.0-3.2 (they were
reinstated in 3.3 as per PEP 414), so a more likely version set would

be 2.6+, 3.3+. What's the actual version support?
ChrisA


I'm going to have to assume you are right that I only tested on 3.3, skipping  
2.7 and  3.3. I'll create an issue for that.



Don't bother trying to support =3.2.  It will be far more difficult 
than it is worth in terms of adoption of the library.


Also, you don't need to write a proposal for your library. You've 
written the library, and it's on PyPI.  You aren't trying to add it to 
the stdlib, so there's no agreement you need to get from anyone else. 
It can simply succeed on its merits with people using it.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Template language for random string generation

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 9:20 PM, Ned Batchelder n...@nedbatchelder.com wrote:
 On 8/8/14 5:42 AM, Paul Wolf wrote:

 On Friday, 8 August 2014 10:22:33 UTC+1, Chris Angelico  wrote:

 But I eyeballed your code, and I'm seeing a lot of
 u'string' prefixes, which aren't supported on 3.0-3.2 (they were
 reinstated in 3.3 as per PEP 414), so a more likely version set would

 be 2.6+, 3.3+. What's the actual version support?
 ChrisA


 I'm going to have to assume you are right that I only tested on 3.3,
 skipping  2.7 and  3.3. I'll create an issue for that.


 Don't bother trying to support =3.2.  It will be far more difficult than it
 is worth in terms of adoption of the library.

Agreed. I would be looking at the solution here being test on 3.4,
then (assuming no problems) declare that it works on 3.3+. Anyone on
Debian Wheezy can spin up a Python 3 from source anyway, and
presumably ditto for any other Linux distro that's distributing 3.1 or
3.2; most other platforms should have a more modern Python available
one way or another.

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


Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread cool-RR
Hi all,

If I want to acquire a `threading.Lock` using the context manager protocol, is 
it possible to specify the `blocking` and `timeout` arguments that `acquire` 
would usually take?

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


Re: Template language for random string generation

2014-08-08 Thread Paul Wolf
On Friday, 8 August 2014 12:20:36 UTC+1, Ned Batchelder  wrote:
 On 8/8/14 5:42 AM, Paul Wolf wrote:
 

 Don't bother trying to support =3.2.  It will be far more difficult 
 
 than it is worth in terms of adoption of the library.
 
 Also, you don't need to write a proposal for your library. You've 
 
 written the library, and it's on PyPI.  You aren't trying to add it to 

Thanks for that. I'll follow that advice. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Template language for random string generation

2014-08-08 Thread Paul Wolf
On Friday, 8 August 2014 12:29:09 UTC+1, Chris Angelico  wrote:
 Debian Wheezy can spin up a Python 3 from source anyway, and
 
 presumably ditto for any other Linux distro that's distributing 3.1 or
 
 3.2; most other platforms should have a more modern Python available
 
 one way or another.
 
 
 
 ChrisA

Yes, agreed. I'll update the version info. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Ethan Furman

On 08/08/2014 04:51 AM, cool-RR wrote:


If I want to acquire a `threading.Lock` using the context manager protocol,
 is it possible to specify the `blocking` and `timeout` arguments that
 `acquire` would usually take?


Not that I know of, but why would you want to?  There's no built-in 'if' with a 'with' block -- how would your code know 
whether it ran or not?


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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Rustom Mody
On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote:
 Hi all,

 I have one query. I have did some programming which copies and paste data 
 using system clipboard. I need to keep one GUI always on top till my python 
 code is running.

In linux you can do (at shell level)
$ wmctrl -r window -b add,above

Note: In place of window you will need a string that is in your window title
You can get these with
$ wmctrl -l

You can then stuff this into python with os.system

Windows: No idea
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 11:44 PM, Rustom Mody rustompm...@gmail.com wrote:
 On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote:
 Hi all,

 I have one query. I have did some programming which copies and paste data 
 using system clipboard. I need to keep one GUI always on top till my python 
 code is running.

 In linux you can do (at shell level)
 $ wmctrl -r window -b add,above

AIUI that just sets the always on top flag, which isn't what he's
asking for. Also, his toolkit should offer that directly.

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Steven D'Aprano
Chris Angelico wrote:

 On Fri, Aug 8, 2014 at 6:57 PM, Paul Rudin paul.nos...@rudin.co.uk
 wrote:
 Chris Angelico ros...@gmail.com writes:

 On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil patil.jay2...@gmail.com
 wrote:
 I mean to say, One GUI should be always on top from start to end of
 code running. So that user cant do any other operation.
 I am using wxpython

 Ah, that would be called System Modal, and should be reserved for
 absolutely critical system-wide alerts. It's also a feature that's
 simply not available to most user-space programs, and not available in
 most GUI toolkits.

 Short answer: Don't.

 There are commercial software packages that do this sort of
 thing. Examsoft is one - the idea being that people can take exams
 without access to other software at the same time (so that, for example,
 they could look at previously prepared notes).
 
 Yeah; like I said, Don't is the short answer. There will be
 exceptions, some extremely rare situations when system modality is
 correct; but fundamentally, it's impossible to use GUI software to
 control what a person does with a computer

There are exceptions, but it's impossible? Impossible except for the
exceptions, I presume :-P

 (for instance, on all my 
 Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI
 altogether). 

Does that work when xscreensaver or equivalent has locked the system? If so,
that's a security vulnerability.


 So I'm dubious about its value for anything that isn't an 
 absolutely critical alert. 

Well, there's at least two use-cases I can think of:

* screen locking, as in screen savers;

* login screens;

* exam software;

Eh, that is, at least three use-cases:

* screen locking;

* login screens;

* exam software;

* emulating full screen arcade games;

Um, among the use-cases are, screen locking, login screens, exam software,
full-screen games, critical system alerts, and, of course, the most popular
reason of all:

* my application is SO SPECIAL that it deserves to take over the
  entire GUI Just Because I Can.

I don't know any platform-independent GUI toolkits which offer this out of
the box, but I expect that there's probably a way to do it in a platform
specific way on each platform you wish to support. Either that, or the OP
can google for wxpython system modal (including the quotes) and see
what comes up. I'd do so myself, except some damn fool Javascript code
running on some rubbish web site just crashed my browser. Again.



-- 
Steven

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:

 Does that work when xscreensaver or equivalent has locked the system?
 If so, that's a security vulnerability.

Depends on the semantics of the screensaver. Its scope is the current
X11 session.

In my home, different family members have different VTs. Locking one VT
shouldn't prevent you from switching over to a different one.


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


Re: Template language for random string generation

2014-08-08 Thread Steven D'Aprano
Paul Wolf wrote:

 This is a proposal with a working implementation for a random string
 generation template syntax for Python. `strgen` is a module for generating
 random strings in Python using a regex-like template language. Example:
 
  from strgen import StringGenerator as SG
  SG([\l\d]{8:15}[\d][\p]).render()
 u'F0vghTjKalf4^mGLk'

Nice! Although very specialised :-)

I second what Ned and Chris have to say.

 If you look at various forums, like Stackoverflow, on how to generate
 random strings with Python, especially for passwords and other hopefully
 secure tokens, you will see dozens of variations of this:
[...]
 There is nothing wrong with this (it's the right answer and is very fast),
 but it leads developers to constantly:
 
 * Use cryptographically weak methods
 * Forget that the above does not guarantee a result that includes the
   different classes of characters 
 * Doesn't include variable length or minimum length output
 * It's a lot of typing and the resulting code is vastly different each
   time making it hard to understand what features were 
   implemented, especially for those new to the language 
 * You can extend the above to include whatever requirements you want,
   but it's a constant exercise in wheel reinvention that is extremely
   verbose, error prone and confusing for exactly the same purposes
   each time 

So, there's nothing wrong with it, except for the five things you list which
are wrong with it :-)

Seriously, if you're going to compete with the Stackoverflow ad hoc
solutions, you have to be more assertive that there is a problem with the
ad hoc solutions.


-- 
Steven

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 Yeah; like I said, Don't is the short answer. There will be
 exceptions, some extremely rare situations when system modality is
 correct; but fundamentally, it's impossible to use GUI software to
 control what a person does with a computer

 There are exceptions, but it's impossible? Impossible except for the
 exceptions, I presume :-P

There are exceptions to the rule you shouldn't use system modal
windows. It is, however, fundamentally impossible for GUI software to
completely control what the person does - system modality is defined
only to the extent of the GUI.

 (for instance, on all my
 Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI
 altogether).

 Does that work when xscreensaver or equivalent has locked the system? If so,
 that's a security vulnerability.

Absolutely it works! However, what you get to is a terminal with a
login prompt. If you don't know a valid userid and password, you can't
get in. (And if you *do* know them, you can probably get in through
the GUI, too, although it's possible for a screen saver to lock such
that no other account can log in.)

 So I'm dubious about its value for anything that isn't an
 absolutely critical alert.

 Well, there's at least two use-cases I can think of:

 * screen locking, as in screen savers;

 * login screens;

With these two, it's deliberately locking only the GUI, so system
modality could be correct. But really, it's more about covering the
whole screen; system modality is more about disabling the whole
screen. So they're still not a perfect match.

 * exam software;

This is what I'm dubious about. Since you can always log in via some
other method, or brute-force something (eg replace one of the system
accessibility programs with your own tool), it's impossible for the
software to stop you from running something else. And if the computer
you're doing this on is so locked down that you can't pull up your
notes in some other app, it may as well simply be so locked down that
you can't get your notes onto that computer in the first place.

 * emulating full screen arcade games;

Why should that disable access to everything else? Most full screen
games let you alt-tab away from them (preferably auto-pausing the
game). If a game goes system modal on me, I would not be happy.

 * my application is SO SPECIAL that it deserves to take over the
   entire GUI Just Because I Can.

And that one is definitely not a reason, as I'm sure you agree :)

 I don't know any platform-independent GUI toolkits which offer this out of
 the box, but I expect that there's probably a way to do it in a platform
 specific way on each platform you wish to support.

There may be; there also may not (that is to say, there may be
platform-specific ways on some, but not all, platforms - I'm not sure
Windows has the functionality). But that's par for the course... if
every platform had the exact same features, we wouldn't need multiple
platforms.

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Rustom Mody
On Friday, August 8, 2014 7:21:35 PM UTC+5:30, Chris Angelico wrote:
 On Fri, Aug 8, 2014 at 11:44 PM, Rustom Mody wrote:
  On Thursday, August 7, 2014 4:54:09 PM UTC+5:30, Jaydeep Patil wrote:
  Hi all,
 
  I have one query. I have did some programming which copies and paste data 
  using system clipboard. I need to keep one GUI always on top till my 
  python code is running.
 
  In linux you can do (at shell level)
  $ wmctrl -r window -b add,above
 
 
 
 AIUI that just sets the always on top flag, which isn't what he's
 
 asking for. Also, his toolkit should offer that directly.

A windows equivalent for linux's wmctrl seems to be nir
http://www.nirsoft.net/utils/nircmd2.html#using

Search for 'settopmost'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:23 AM, Rustom Mody rustompm...@gmail.com wrote:
 A windows equivalent for linux's wmctrl seems to be nir
 http://www.nirsoft.net/utils/nircmd2.html#using

 Search for 'settopmost'

No need; both of those are just setting the always on top flag,
which wxpython can do directly. It may be unobvious, as there seem to
be a lot of questions asked about it (lots of StackOverflow and forums
posts), but ultimately, there's a wx.STAY_ON_TOP flag that will do the
same thing.

However, the OP wasn't asking about visually keeping a window on top,
which is pretty easy. Trying to actually prevent access to any other
window is significantly harder to do, plus it's never going to be more
broad than one X session, plus it's almost always a bad UI idea.

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


Re: Template language for random string generation

2014-08-08 Thread Skip Montanaro
One suggestion, though perhaps nothing actually needs changing.

I occasionally run into sites which define their password constraints as
something like minimum 8 characters, at least one number, one uppercase
letter, and one special character. Their notion of special (which in my
mind means any printable character which isn't a letter, whitespace, or
digit) is only a subset.  You include a / or a ; and they kick your
nice random password back at you, sometimes without telling you what you
actually did wrong, only repeating, minimum 8 characters, at least one
number and one special character. You are left to discover through
trial-and-error which special characters are actually allowed. Once you
figure that out, I suppose you could use something like [.-,()@] or
whatever is actually allowed, but it would be nice if perhaps there was a
way to figure out what some of these sites actually mean by special
characters and define a \-escape which represents the lowest common
denominator set of special characters.

Definitely a small point though.

Skip

P.S. Probably a topic for a separate thread, and not actually
Python-related, but on a related note, I have never found a free password
keeper which works on all my platforms (Mac, Android, Unix). That is one
stumbling block (for me) to actually using extremely strong passwords. If
you have some thoughts, please contact me off-list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Rustom Mody
On Friday, August 8, 2014 8:04:05 PM UTC+5:30, Chris Angelico wrote:
 On Sat, Aug 9, 2014 at 12:23 AM, Rustom Mody  wrote:
  A windows equivalent for linux's wmctrl seems to be nir
  http://www.nirsoft.net/utils/nircmd2.html#using
 
  Search for 'settopmost'
 
 
 No need; both of those are just setting the always on top flag,
 which wxpython can do directly. It may be unobvious, as there seem to
 be a lot of questions asked about it (lots of StackOverflow and forums
 posts), but ultimately, there's a wx.STAY_ON_TOP flag that will do the
 same thing.
 
 
 
 However, the OP wasn't asking about visually keeping a window on top,
 which is pretty easy. Trying to actually prevent access to any other
 window is significantly harder to do, plus it's never going to be more
 broad than one X session, plus it's almost always a bad UI idea.
 

This is the OP:

 I have one query. I have did some programming which copies and
 paste data using system clipboard. I need to keep one GUI always 
 on top till my python code is running.

[I am of course assuming that 'did' means 'done' and 'GUI' means 'window' or 
'widget']

I dont see anything about preventing access.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread alister
On Fri, 08 Aug 2014 23:58:56 +1000, Steven D'Aprano wrote:
 
 (for instance, on all my Linux systems, I can hit Ctrl-Alt-F1 to switch
 away from the GUI altogether).
 
 Does that work when xscreensaver or equivalent has locked the system? If
 so,
 that's a security vulnerability.

I have not tried b=ut is should not be a security risk as you still have 
to log into the virtual terminal.

this may even be desirable if multiple people may administer the PC.
 


-- 
I never met a piece of chocolate I didn't like.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Rustom Mody
On Friday, August 8, 2014 8:22:47 PM UTC+5:30, Chris Angelico wrote:
 On Sat, Aug 9, 2014 at 12:45 AM, Rustom Mody wrote:
  I dont see anything about preventing access.
 
 
 That came from his next post, in which he said So that user cant do
 any other operation..
 That's the preventing access bit.
 
 
 Of course, if Always On Top is sufficient, then it's (a) easy, even
 across platforms, and (b) not the UI annoyance that misused system
 modality would be. There's plenty of use for always-on-top.
 

Um... Ok

Now I seem to remember this same questioner (??) asking a few months ago
about:

I have an excel program running for 20 minutes and I want to lock 
the machine or something like that

And you proscribing similarly then :-)

Yeah 'On top' can be useful. 'Modal' is a PITA.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:50 AM, alister
alister.nospam.w...@ntlworld.com wrote:
 On Fri, 08 Aug 2014 23:58:56 +1000, Steven D'Aprano wrote:

 (for instance, on all my Linux systems, I can hit Ctrl-Alt-F1 to switch
 away from the GUI altogether).

 Does that work when xscreensaver or equivalent has locked the system? If
 so,
 that's a security vulnerability.

 I have not tried b=ut is should not be a security risk as you still have
 to log into the virtual terminal.

 this may even be desirable if multiple people may administer the PC.

Right. Unix has as its underlying philosophy that users and processes
are the most important things, not interfaces. I can log in to a
computer at a virtual terminal by pressing Ctrl-Alt-F1, or with a
graphical login manager like lightdm, or via ssh, or something else,
and everything works. And if I leave something running under my user
name that allows me to connect remotely, or maybe have something
running as root that can hook in to some sort of user event (off a USB
device, or a secondary mouse, or whatever) that can then display
something on the screen, then no amount of login prevention will
change that.

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:45 AM, Rustom Mody rustompm...@gmail.com wrote:
 I dont see anything about preventing access.

That came from his next post, in which he said So that user cant do
any other operation..

That's the preventing access bit.

Of course, if Always On Top is sufficient, then it's (a) easy, even
across platforms, and (b) not the UI annoyance that misused system
modality would be. There's plenty of use for always-on-top.

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:58 AM, Rustom Mody rustompm...@gmail.com wrote:
 Now I seem to remember this same questioner (??) asking a few months ago
 about:

 I have an excel program running for 20 minutes and I want to lock
 the machine or something like that

 And you proscribing similarly then :-)

 Yeah 'On top' can be useful. 'Modal' is a PITA.

Yeah, that sounds about right.

Always on top, incidentally, is very often used for windows which
won't have input focus - maybe a small window showing a status graph,
or maybe a short-lived popup alert - rather than as a means of keeping
the user's attention on something. But whatever it's used for, it
doesn't affect input focus.

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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Neil D. Cerutti

On 8/8/2014 9:25 AM, Ethan Furman wrote:

On 08/08/2014 04:51 AM, cool-RR wrote:


If I want to acquire a `threading.Lock` using the context manager
protocol,
 is it possible to specify the `blocking` and `timeout` arguments that
 `acquire` would usually take?


Not that I know of, but why would you want to?  There's no built-in 'if'
with a 'with' block -- how would your code know whether it ran or not?


Perhaps defer release, a la a common Go pattern:

with contextlib.ExitStack() as stack:
acquired = lock.acquire(blocking=False)
if acquired:
stack.callback(lock.release)
do_stuff

--
Neil Cerutti

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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti ne...@norwich.edu wrote:
 Perhaps defer release, a la a common Go pattern:

 with contextlib.ExitStack() as stack:
 acquired = lock.acquire(blocking=False)
 if acquired:
 stack.callback(lock.release)
 do_stuff

There's a race condition in that - an unexpected exception could
happen between those two. Are you able to set the callback to be a
release if acquired atomic operation?

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


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Steven D'Aprano
Chris Angelico wrote:

 On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 Yeah; like I said, Don't is the short answer. There will be
 exceptions, some extremely rare situations when system modality is
 correct; but fundamentally, it's impossible to use GUI software to
 control what a person does with a computer

 There are exceptions, but it's impossible? Impossible except for the
 exceptions, I presume :-P
 
 There are exceptions to the rule you shouldn't use system modal
 windows. It is, however, fundamentally impossible for GUI software to
 completely control what the person does - system modality is defined
 only to the extent of the GUI.

*Fundamentally* impossible? You've never used classic Mac OS, I take it. Or
a non-jail-broken iPhone.

There is nothing *fundamental* that says that a GUI interface is necessarily
a second-class interface, or that a non-GUI interface is always available.


 (for instance, on all my
 Linux systems, I can hit Ctrl-Alt-F1 to switch away from the GUI
 altogether).

You're assuming that there are any virtual terminals running on the system,
which is not a given. Windows doesn't have them at all. Even in Linux, they
can be turned off(?) or at least access to them disabled. For that matter,
you're assuming the machine has a keyboard attached. Have you never seen a
machine running in kiosk mode with only a touchscreen or trackball?

http://wiki.tldp.org/Kiosk-HOWTO


 Does that work when xscreensaver or equivalent has locked the system? If
 so, that's a security vulnerability.
 
 Absolutely it works! However, what you get to is a terminal with a
 login prompt.

I don't think so. I think you get a terminal which may or may not be already
logged in. Hence the security vulnerability: if you leave a virtual
terminal logged in, then locking the X terminal alone via xscreensaver is
useless.

I haven't tried it with xscreensaver itself, but I've just tried it with
whatever screensaver KDE under Centos uses, and sure enough, it locks the X
session but allows access to any virtual terminals that happen to already
be logged in with no authentication needed.


[...]
 * exam software;
 
 This is what I'm dubious about. Since you can always log in via some
 other method, 

Always? You're saying it is impossible to disable telnet and ssh? Or unplug
the network cable?

But really, now we're getting silly. No, exam software isn't going to
prevent you from ssh'ing into the computer from another computer, assuming
ssh is allowed. Nor is it going to prevent you from using another computer,
getting answers from handwritten notes or books, or asking somebody to help
you. That's hardly the point.


 or brute-force something (eg replace one of the system 
 accessibility programs with your own tool), 

And how am I supposed to do that, from the exam software itself, without
access to a shell?


 it's impossible for the 
 software to stop you from running something else. And if the computer
 you're doing this on is so locked down that you can't pull up your
 notes in some other app, it may as well simply be so locked down that
 you can't get your notes onto that computer in the first place.

Um, yes? Although not necessarily. We're getting further and further from
the OP's question, which should be interpreted in the most reasonable
manner, not the least reasonable:

- he probably only cares about blocking access to the rest of the 
  GUI environment, not virtual terminals (assuming he is even using
  a system with virtual terminals);

- or he's trying to build a kiosk application.

It is unreasonable to interpret his comment user cant [sic] do any other
operation so broadly that we have to care about (e.g.):

- ssh'ing into the computer from another machine;

- rebooting into single user mode;

- walking away from the computer to do something else.

All those things can be solved (e.g. by turning off the ssh daemon, or
blocking access at the firewall, using a custom BIOS, and chaining the user
to the computer), but likely not by the GUI toolkit itself.


-- 
Steven

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


Comparisons of Python's module/import system with JavaScript?

2014-08-08 Thread Skip Montanaro
I'm struggling with some JavaScript issues related to it's lack of
good support for modules. I know RequireJS exists (and appears to be
the most widely used add-on for this stuff), but as a novice JS
programmer, I'm having trouble wrapping my head around just what it
does. In particular, I don't see how it injects names into the scope
which calls require(). I'm hoping someone here understands both the
Python and JS models (preferably as represented by RequireJS) and can
provide some advice, perhaps a pointer to a blog post? I've not found
anything yet.

Thanks

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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Neil D. Cerutti

On 8/8/2014 12:16 PM, Chris Angelico wrote:

On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti ne...@norwich.edu wrote:

Perhaps defer release, a la a common Go pattern:

with contextlib.ExitStack() as stack:
 acquired = lock.acquire(blocking=False)
 if acquired:
 stack.callback(lock.release)
 do_stuff


There's a race condition in that - an unexpected exception could
happen between those two. Are you able to set the callback to be a
release if acquired atomic operation?


Doesn't any natural looking use of blocking=False suffer from the same 
race condition? What's the correct way to use it?


Here's another attempt at context managing:

@contextlib.contextmanager
def release_if_acquired(lock, blocking=True, timeout=-1):
acquired = lock.acquire(blocking, timeout)
if acquired:
yield acquired
lock.release()
else:
yield acquired

with release_if_acquired(lock, blocking=False) as acquired:
if acquired:
do_stuff

--
Neil Cerutti

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


Re: Template language for random string generation

2014-08-08 Thread cwolf . algo
On Friday, August 8, 2014 10:35:12 AM UTC-4, Skip Montanaro wrote:
 One suggestion, though perhaps nothing actually needs changing.
 
 
 I occasionally run into sites which define their password constraints as 
 something like minimum 8 characters, at least one number, one uppercase 
 letter, and one special character. Their notion of special (which in my 
 mind means any printable character which isn't a letter, whitespace, or 
 digit) is only a subset.  You include a / or a ; and they kick your nice 
 random password back at you, sometimes without telling you what you actually 
 did wrong, only repeating, minimum 8 characters, at least one number and one 
 special character. You are left to discover through trial-and-error which 
 special characters are actually allowed. Once you figure that out, I 
 suppose you could use something like [.-,()@] or whatever is actually 
 allowed, but it would be nice if perhaps there was a way to figure out what 
 some of these sites actually mean by special characters and define a 
 \-escape which represents the lowest common denominator set of special 
 characters.
 
 
 
 Definitely a small point though.
 
 
 Skip
 
 
 
 P.S. Probably a topic for a separate thread, and not actually Python-related, 
 but on a related note, I have never found a free password keeper which works 
 on all my platforms (Mac, Android, Unix). That is one stumbling block (for 
 me) to actually using extremely strong passwords. If you have some thoughts, 
 please contact me off-list.

Skip - try lastpass.com it's cross platform, include Win, Mac, Linux, Android 
and iOS.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Neil D. Cerutti

On 8/8/2014 2:35 PM, Neil D. Cerutti wrote:

Here's another attempt at context managing:




@contextlib.contextmanager
def release_if_acquired(lock, blocking=True, timeout=-1):
 acquired = lock.acquire(blocking, timeout)
 if acquired:
 yield acquired
 lock.release()
 else:
 yield acquired


I should not have used a temporary.

@contextlib.contextmanager
def release_if_acquired(lock, blocking=True, timeout=-1):
 if lock.acquire(blocking, timeout)
 yield True
 lock.release()
 else:
 yield False

--
Neil Cerutti

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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 11:35 AM, Neil D. Cerutti ne...@norwich.edu wrote:

 On 8/8/2014 12:16 PM, Chris Angelico wrote:

 On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti ne...@norwich.edu
 wrote:

 Perhaps defer release, a la a common Go pattern:

 with contextlib.ExitStack() as stack:
  acquired = lock.acquire(blocking=False)
  if acquired:
  stack.callback(lock.release)
  do_stuff


 There's a race condition in that - an unexpected exception could
 happen between those two. Are you able to set the callback to be a
 release if acquired atomic operation?


 Doesn't any natural looking use of blocking=False suffer from the same
 race condition? What's the correct way to use it?

 Here's another attempt at context managing:

 @contextlib.contextmanager
 def release_if_acquired(lock, blocking=True, timeout=-1):
 acquired = lock.acquire(blocking, timeout)
 if acquired:
 yield acquired
 lock.release()
 else:
 yield acquired


What I'd probably do is:
@contextlib.contextmanager
def release_if_acquired(lock, blocking=True, timeout=-1):
acquired = lock.acquire(blocking, timeout)
try:
yield acquired
finally:
if acquired:
lock.release()

However, there is still the chance that a interrupt signal (ctrl+c) could
prevent the lock from being released, but I think the only 100% solution
would be to write the code in C where it cannot be interrupted within
Python. The OS could still interrupt or kill the thread, but in that case,
I don't think there is anything you can do...


 with release_if_acquired(lock, blocking=False) as acquired:
 if acquired:

 do_stuff


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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Ian Kelly
On Fri, Aug 8, 2014 at 7:25 AM, Ethan Furman et...@stoneleaf.us wrote:
 On 08/08/2014 04:51 AM, cool-RR wrote:


 If I want to acquire a `threading.Lock` using the context manager
 protocol,
  is it possible to specify the `blocking` and `timeout` arguments that
  `acquire` would usually take?


 Not that I know of, but why would you want to?  There's no built-in 'if'
 with a 'with' block -- how would your code know whether it ran or not?

@contextmanager
def locking(lock, blocking=False, timeout=-1):
  try:
yield lock.acquire(blocking, timeout)
  finally:
lock.release()

with locking(lock, timeout=5) as acquired:
  if acquired:
print('yay!')
-- 
https://mail.python.org/mailman/listinfo/python-list


Newbie needing some help

2014-08-08 Thread Matt Smith
I am trying to write a program that will loop through a text file and
delete rows in a mysql database.

It seemingly runs but I don't see anything getting deleted in the db.
Is there anything apparent that I am missing?

This is the code:
#!/usr/bin/python
import mysql.connector
#
f=open('/home/smithm/email-list.txt', 'r')
for line in f:
#do something with line
# Open database connection
db = mysql.connector.connect(user=xx, password=xx,
host=localhost, database=xx)

# prepare a cursor object using cursor() method
cursor = db.cursor()

# Prepare SQL query to DELETE required records
sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)
try:
  # Execute the SQL command
  cursor.execute(sql)
  # Commit your changes in the database
  db.commit()
except:
  # Rollback in case there is any error
  db.rollback()

# disconnect from server
db.close()

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


Re: Newbie needing some help

2014-08-08 Thread Larry Martell
On Fri, Aug 8, 2014 at 3:07 PM, Matt Smith smit...@tblc.org wrote:
 I am trying to write a program that will loop through a text file and delete
 rows in a mysql database.

 It seemingly runs but I don't see anything getting deleted in the db.
 Is there anything apparent that I am missing?

 This is the code:
 #!/usr/bin/python
 import mysql.connector
 #
 f=open('/home/smithm/email-list.txt', 'r')
 for line in f:
 #do something with line
 # Open database connection
 db = mysql.connector.connect(user=xx, password=xx,
 host=localhost, database=xx)

 # prepare a cursor object using cursor() method
 cursor = db.cursor()

 # Prepare SQL query to DELETE required records
 sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)
 try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
 except:
   # Rollback in case there is any error
   db.rollback()

 # disconnect from server
 db.close()

Run it in the debugger, set a BP after you create the sql, print it
out, and cut and paste it into an interactive sql session and you'll
see what the issues are.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie needing some help

2014-08-08 Thread Mark Lawrence

On 08/08/2014 20:07, Matt Smith wrote:

I am trying to write a program that will loop through a text file and
delete rows in a mysql database.

It seemingly runs but I don't see anything getting deleted in the db.
Is there anything apparent that I am missing?

This is the code:
#!/usr/bin/python
import mysql.connector
#
f=open('/home/smithm/email-list.txt', 'r')


The modern idiom is:-

with open(...) as f: but that doesn't matter here.


for line in f:
 #do something with line
 # Open database connection
 db = mysql.connector.connect(user=xx, password=xx,
host=localhost, database=xx)

 # prepare a cursor object using cursor() method
 cursor = db.cursor()


Are you aware that you're connecting to your db and setting up the 
cursor in every iteration of the loop?




 # Prepare SQL query to DELETE required records
 sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)
 try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
 except:


This bare except is masking every possible thing that can go wrong. 
Strip it out and I expect you'll find your mistake in seconds.  Once 
you've corrected your code add back in the bare minimum number of 
exceptions that you really should catch.



   # Rollback in case there is any error
   db.rollback()

 # disconnect from server
 db.close()

--
Matthew Smith



--
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: Template language for random string generation

2014-08-08 Thread Ian Kelly
On Fri, Aug 8, 2014 at 3:01 AM, Paul Wolf paulwolf...@gmail.com wrote:
 * Uses SystemRandom class (if available, or falls back to Random)

A simple improvement would be to also allow the user to pass in a
Random object, in case they have their own source of randomness they
want to use, or for fake Randoms used for writing unit tests that
invoke strgen.

Have you given any thought to adding a validation mode, where the user
provides a template and a string and wants to know if the string
matches the template?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Template language for random string generation

2014-08-08 Thread Nick Cash

On 08/08/2014 01:45 PM, cwolf.a...@gmail.com wrote:
 On Friday, August 8, 2014 10:35:12 AM UTC-4, Skip Montanaro wrote:
 P.S. Probably a topic for a separate thread, and not actually 
 Python-related, but on a related note, I have never found a free password 
 keeper which works on all my platforms (Mac, Android, Unix). That is one 
 stumbling block (for me) to actually using extremely strong passwords. If 
 you have some thoughts, please contact me off-list.
 Skip - try lastpass.com it's cross platform, include Win, Mac, Linux, 
 Android and iOS.

LastPass is pretty nice (and I use it on Windows, Mac, Linux and Android
myself), but the mobile versions aren't free:
https://lastpass.com/misc_download2.php
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keep one GUI always on TOP while python code is running

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 4:04 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 On Fri, Aug 8, 2014 at 11:58 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 Yeah; like I said, Don't is the short answer. There will be
 exceptions, some extremely rare situations when system modality is
 correct; but fundamentally, it's impossible to use GUI software to
 control what a person does with a computer

 There are exceptions, but it's impossible? Impossible except for the
 exceptions, I presume :-P

 There are exceptions to the rule you shouldn't use system modal
 windows. It is, however, fundamentally impossible for GUI software to
 completely control what the person does - system modality is defined
 only to the extent of the GUI.

 *Fundamentally* impossible? You've never used classic Mac OS, I take it. Or
 a non-jail-broken iPhone.

 There is nothing *fundamental* that says that a GUI interface is necessarily
 a second-class interface, or that a non-GUI interface is always available.

What I mean is that GUI software can't control the entire computer.
It's impossible for a system-modal flag to prevent access to non-GUI
parts of the computer. Now, if there happen to be none of them (that
you're aware of - certain OSes are rife with unexpected backdoors),
then for all practical purposes, it's controlling the whole computer -
but technically it still isn't.

 You're assuming that there are any virtual terminals running on the system,
 which is not a given. Windows doesn't have them at all. Even in Linux, they
 can be turned off(?) or at least access to them disabled. For that matter,
 you're assuming the machine has a keyboard attached. Have you never seen a
 machine running in kiosk mode with only a touchscreen or trackball?

 http://wiki.tldp.org/Kiosk-HOWTO

This is what I was saying about the system being so locked down
already that there's no point going system modal. If you can't invoke
other programs, what's it matter if you could switch to other running
programs? So system modality is still pointless on a kiosk.

 Does that work when xscreensaver or equivalent has locked the system? If
 so, that's a security vulnerability.

 Absolutely it works! However, what you get to is a terminal with a
 login prompt.

 I don't think so. I think you get a terminal which may or may not be already
 logged in. Hence the security vulnerability: if you leave a virtual
 terminal logged in, then locking the X terminal alone via xscreensaver is
 useless.

 I haven't tried it with xscreensaver itself, but I've just tried it with
 whatever screensaver KDE under Centos uses, and sure enough, it locks the X
 session but allows access to any virtual terminals that happen to already
 be logged in with no authentication needed.

Oh, sorry. I thought you were talking about the oops you got around
my security problem. If you leave something logged in, that's a
security vulnerability; whether that's on a VT or in a web browser
tab, someone (you or someone else) can then use it. As far as I'm
concerned, the vulnerability has nothing to do with a locked GUI. If
you're trying to ensure that someone can't get around your program,
you have to make sure there's no available logins.

 [...]
 * exam software;

 This is what I'm dubious about. Since you can always log in via some
 other method,

 Always? You're saying it is impossible to disable telnet and ssh? Or unplug
 the network cable?

I'm assuming here that the student has some control of the computer
the software's being run on. If the student has absolutely no control
over the computer, then it's the kiosk situation; there's no point
locking the GUI because you'll already have locked everything else.
What you're basically saying is Hey look, I have a perfect lock on my
front door - backed up by a moat full of angry crocodiles. The crocs
make the lock superfluous.

 or brute-force something (eg replace one of the system
 accessibility programs with your own tool),

 And how am I supposed to do that, from the exam software itself, without
 access to a shell?

Again, this would be something you'd do beforehand, making use of some
measure of control over the computer. If you can't do anything like
that, it's kiosk mode.

I'm thinking here of the time I had a Windows 7 VM that I'd forgotten
the password to. The solution? Boot a rescue disk (I could probably
have done this with a Linux live CD and an ntfs mount), copy cmd.exe
over the top of some accessibility program (backing it up first), and
reboot. The same can be done with Linux; if you can boot your own
media, you can change anything and give yourself access (put yourself
in sudoers, give yourself some groups, create a setuid root shell,
etc, etc, etc). So the *only* way to prevent access to a physical
machine is to prevent *all* access. And at that point, any lesser
control is utterly superfluous.

 We're getting further and further from
 the OP's question, 

Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 5:07 AM, Matt Smith smit...@tblc.org wrote:
 # Prepare SQL query to DELETE required records
 sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)
 try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
 except:
   # Rollback in case there is any error
   db.rollback()

By not even logging your errors, you mask everything that could go
wrong. There is an error in the block of code that I've highlighted
here, but the biggest problem is the bare except (as Mark pointed
out).

Suggestions:

1) Use a better subject line, which actually describes your problem.
2) As Mark said, don't use try/except here at all. Let exceptions
abort the whole process with a nice useful traceback.
3) Open a database connection once, right at the top, and don't commit
until the very end of your program.
4) If this isn't a toy program, consider doing the entire set of
deletions in a single statement - it'll allow the database to do a
single pass over the data. But if this is part of a learn to use SQL
course or something, ignore that, keep going the way you are.

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


Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 4:35 AM, Neil D. Cerutti ne...@norwich.edu wrote:
 Doesn't any natural looking use of blocking=False suffer from the same race
 condition? What's the correct way to use it?

Actually, I don't know. I try to avoid any form of thread locking
where possible, and I don't remember the last time I used
blocking=False at all. Generally, in those rare occasions when I want
to lock, I want to lock reliably, and it's around something so narrow
that the simple option will be the best. So you're quite probably
right.

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


Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 12:07 PM, Matt Smith smit...@tblc.org wrote:

 I am trying to write a program that will loop through a text file and
 delete rows in a mysql database.


 It seemingly runs but I don't see anything getting deleted in the db.
 Is there anything apparent that I am missing?

 This is the code:
 #!/usr/bin/python
 import mysql.connector
 #
 f=open('/home/smithm/email-list.txt', 'r')


You probably should use the with statement to make sure the file closes,
like follows:

with open('/home/smithm/email-list.txt', 'r') as f:
# Code needing the file goes here.


  for line in f:
 #do something with line
 # Open database connection
 db = mysql.connector.connect(user=xx, password=xx,
 host=localhost, database=xx)


 # prepare a cursor object using cursor() method
 cursor = db.cursor()


You probably want you connect to the database outside the line for
performance reasons.



 # Prepare SQL query to DELETE required records
 sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)


This line also seems suspect - you are not merging in the line to the SQL
statement. If you meant:

sql = DELETE FROM tblc_users WHERE user_email=%s % (line)

you would have a SQL injection attack possible. The sql library should have
support for this type of loading the code. I do not know the exact syntax
for how to do this within the mysql connector library, but typically you
pass the arguments to the execute command (in this case, line) with some
formatting in the sql command line..


 try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
 except:


As a heads up, bare exceptions are generally a bad idea, however in this
case they are acceptable.

However, I'd recommend re-raising the exception after rolling back the
transaction with a bare raise statement right after the db.rollback() -
at the absolute minimum, you should log the error. This will likely let you
see what your problem is.


   # Rollback in case there is any error
   db.rollback()


I'd probably put the close inside of a finally block (especially if you
re-raise the exception as suggested above).


 # disconnect from server
 db.close()



Overall, I'd suggest restructing your code to look like (untested):

import mysql.connector
with open('/home/smithm/email-list.txt', 'r') as f:
# Open database connection
db = mysql.connector.connect(user=xx, password=xx,
host=localhost, database=xx)
try:
# prepare a cursor object using cursor() method
cursor = db.cursor()
for line in f:
#do something with line
# NOTE: the mysql library might support the with statement like
above, removing the need for the try...finally.
try:
# Prepare SQL query to DELETE required records
sql = DELETE FROM tblc_users WHERE user_email=%s ## --I
do not know if %s is the correct syntax for this library.--
# Execute the SQL command
cursor.execute(sql, line) ## --I do not know if this is the
correct syntax for this library.--
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
raise
finally:
# disconnect from server
db.close()


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


Re: more simple to split the string?

2014-08-08 Thread luofeiyu
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 
bit (AM

D64)] on win32
Type help, copyright, credits or license for more information.
 str='(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'
 str.split( )
['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/V4NXPpCuTvY-']


it can be split into four parts,you can see.


On 8/8/2014 1:43 AM, Mark Lawrence wrote:

On 08/08/2014 01:23, elearn wrote:

str='(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'


First up it's not usually a good idea to override the builtin name str.


x=str.split(' ')
[i.replace('','') for i in x]
['(\\HasNoChildren \\Junk)', '/', '[Gmail]/V4NXPpCuTvY-']

x.strip( ) will create four parts.


I assume you meant x=str.split( ) ?  Even so I don't see how you can 
get four parts so please explain.




is there more simple to do that ?


No loop needed that I can see.

 oldstr='(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-';oldstr
'(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'
 newstr=oldstr.replace('', '');newstr
'(\\HasNoChildren \\Junk) / [Gmail]/V4NXPpCuTvY-'
 substrings=newstr.split();substrings
['(\\HasNoChildren', '\\Junk)', '/', '[Gmail]/V4NXPpCuTvY-']



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


Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor ckay...@zindagigames.com wrote:
 However, I'd recommend re-raising the exception after rolling back the
 transaction with a bare raise statement right after the db.rollback() - at
 the absolute minimum, you should log the error. This will likely let you see
 what your problem is.

AIUI, aborting the process with an uncaught exception would roll back
implicitly, so there's no need to bare except, roll back, bare
raise. But even if that's not the case, I would be looking at a
try/finally for this, rather than a try/except/raise.

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


Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor ckay...@zindagigames.com wrote:
 try:
 action
 commit
 finally:
 rollback

If commit/rollback automatically opens a new transaction, this would
just roll back an empty transaction - not a big deal. But yes, I do
see what you're looking at here.

However, structures like this are necessary only if you're hanging
onto the database connection. Python gives you a well-defined
unhandled-exception handler, and it's easy to just let exceptions
happen - if something goes wrong, you won't commit, and you'll get a
helpful traceback on the console. My recommended model for Python
databasing is:

Create database connection, get cursor
while work to do:
do work
Commit

Until such time as you have a demonstrable need for more complexity,
this model is safe, simple, and easy to work with. And less code
generally means less bugs :)

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


Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 10:32 AM, Chris Kaynor ckay...@zindagigames.com wrote:
 The main issue I can see with that idea is that the exception will keep a
 reference to the database connection (as with all locals), so unless you
 explicitly close it within a finally clause, the database connection could
 still be left hanging, and thus no rollback will occur.

To clarify: The simple example I used there was assumed to be the
entire program, meaning that the process will terminate on exception.
No worries about resource release then!

This kind of model works nicely for anything that reads from one
source and writes into the database, or processes data from the
database back into the database, or anything like that. The general
assumption is that an unexpected exception should be treated as fatal
- just write to the console and terminate. While this might seem like
the simplest 1% of cases, it's able to handle a lot of real-world
situations. And since it takes no extra code, it's the perfect way to
start :)

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


Tkinter frame reset

2014-08-08 Thread Nicholas Cannon
Ok so I am working on a little project and I cant seem to solve something with 
it. I have a label and then a clear button and I want all the numbers in the 
label to clear when I push the button. This button is on a separate frame to 
the buttons. I would like to clear the frame and then set all the widgits back 
to how they were one you first open the app(Label being blank). I have tried to 
destroy it with frame.destry() and then try re create it in a function but it 
never recreates its self. Also when I tried grid_forget() on it, it never came 
back either when I tried to frame it and then grid it back on there. I can 
clear the label by just adding a long blank string to it to overwrite the 
numbers behind because I would like to have the user add more numbers in there 
like starting fresh. This long blank string wont work because the buttons add 
on to the existing string so the label keeps getting updated with the new 
buttons pressed. I tried to remove the label but that never came back
  either. Please help me with trying to clear the label or the whole window 
back to its original blank settings
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 5:13 PM, Chris Angelico ros...@gmail.com wrote:

 On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor ckay...@zindagigames.com
 wrote:
  try:
  action
  commit
  finally:
  rollback

 If commit/rollback automatically opens a new transaction, this would
 just roll back an empty transaction - not a big deal. But yes, I do
 see what you're looking at here.

 However, structures like this are necessary only if you're hanging
 onto the database connection. Python gives you a well-defined
 unhandled-exception handler, and it's easy to just let exceptions
 happen - if something goes wrong, you won't commit, and you'll get a
 helpful traceback on the console. My recommended model for Python
 databasing is:

 Create database connection, get cursor
 while work to do:
 do work
 Commit

 Until such time as you have a demonstrable need for more complexity,
 this model is safe, simple, and easy to work with. And less code
 generally means less bugs :)


The main issue I can see with that idea is that the exception will keep a
reference to the database connection (as with all locals), so unless you
explicitly close it within a finally clause, the database connection could
still be left hanging, and thus no rollback will occur.

With just:

openConnection
while workToDo:
doWork
commit

If at any time, doWork throws an exception, the connection could be left
hanging, especially if the code is being run as an interactive script, and
not as an application.

I believe this is one case where explicit is better than implicit :) - its
better to explicitly free the external resources, at the minimum, with
something like:

openConnection
try:
while worktoDo:
doWork
commit
finally:
closeConnection

But, depending on the needs of the system (longer living connections, for
example), that may need to have explicit rollback as well.

As a rule of thumb, I have a context manger to deal with the specific needs
(either just a with transition or a with connection). Keeps the code
cleaner :).

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


how to get the ordinal number in list

2014-08-08 Thread luofeiyu

 x=[x1,x3,x7,x5]
 y=x3

 how can i get the ordinal number by some codes?

for id ,value in enumerate(x):
if y==value : print(id)

Is more simple way to do that?
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to get the ordinal number in list

2014-08-08 Thread Larry Martell
On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu elearn2...@gmail.com wrote:
 x=[x1,x3,x7,x5]
 y=x3

  how can i get the ordinal number by some codes?

 for id ,value in enumerate(x):
 if y==value : print(id)

 Is more simple way to do that?

print x.index(y)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico ros...@gmail.com wrote:

 On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor ckay...@zindagigames.com
 wrote:
  However, I'd recommend re-raising the exception after rolling back the
  transaction with a bare raise statement right after the db.rollback()
 - at
  the absolute minimum, you should log the error. This will likely let you
 see
  what your problem is.

 AIUI, aborting the process with an uncaught exception would roll back
 implicitly, so there's no need to bare except, roll back, bare
 raise. But even if that's not the case, I would be looking at a
 try/finally for this, rather than a try/except/raise.


I would imagine that on connection close, the server would rollback any
uncommitted transactions, however that presumes that the connection close
is completed in a reasonably timely manner (with a try...finally for
closing, it should be).

This is one case where I think try...except/raise is better than
try...finally. If you use try...finally to rollback, you'd have to either
track whether you committed, or you'd rollback with no actions (or possibly
a committed action, which could have odd behavior, depending on the
implementation)

try:
action
commit
except:
rollback
raise

I feel is better than:

try:
action
commit
finally:
rollback

or:

success = False
try:
action
commit
success = True
finally:
if success:
rollback

and is very different than:

try:
action
finally:
commit
-- 
https://mail.python.org/mailman/listinfo/python-list


how to print with given font and size?

2014-08-08 Thread luofeiyu

print(hallo) is so simple.

how can  print word hallo  in console with courier New font  16 pound?
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to get the ordinal number in list

2014-08-08 Thread luofeiyu

 x=[x1,x3,x7,x5,x3]
 x.index(x3)
1
if i want the result of 1 and 4 ?

On 8/8/2014 7:25 PM, Larry Martell wrote:

On Sat, Aug 9, 2014 at 1:22 PM, luofeiyu elearn2...@gmail.com wrote:

x=[x1,x3,x7,x5]
y=x3

  how can i get the ordinal number by some codes?

for id ,value in enumerate(x):
 if y==value : print(id)

Is more simple way to do that?

print x.index(y)


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


Re: how to get the ordinal number in list

2014-08-08 Thread Chris Angelico
On Sun, Aug 10, 2014 at 3:35 AM, luofeiyu elearn2...@gmail.com wrote:
 x=[x1,x3,x7,x5,x3]
 x.index(x3)
 1
 if i want the result of 1 and 4 ?

Want to know what you can do with some object? Try this:

 help(x)

In this case, though, I suspect there's no built-in to search for
*all* of the occurrences of something, so you're best doing your own
loop. You can either iterate straight over the list with enumerate, as
you were doing, or you can use index() with its start argument:

 def find_all(lst, obj):
indices = [-1]
try:
while True:
indices.append(lst.index(obj, indices[-1]+1))
except ValueError:
return indices[1:]

 x=[x1,x3,x7,x5,x3]
 find_all(x, x3)
[1, 4]

It's probably cleaner to just iterate over the list once, though, and
you already know how to do that.

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


Re: how to print with given font and size?

2014-08-08 Thread Chris Angelico
On Sun, Aug 10, 2014 at 3:33 AM, luofeiyu elearn2...@gmail.com wrote:
 print(hallo) is so simple.

 how can  print word hallo  in console with courier New font  16 pound?

You'd have to look to your console's settings; generally, you can't
change fonts. For that kind of work, what you want is an actual GUI;
there are a number of good Python GUI toolkits, including PyGTK,
Tkinter, wxPython, PyQt, and others. Pick one (Tkinter's probably a
good choice for starting out, as it comes with Python on several
platforms; personally, I quite like GTK; but really, any will do), and
work through its tutorial, which should take you through a basic
graphical Hello, World. But at a regular console, you don't have fonts
- all you have is a stream of text.

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


Re: Newbie needing some help

2014-08-08 Thread John Gordon
In mailman.12762.1407533916.18130.python-l...@python.org Matt Smith 
smit...@tblc.org writes:

 I am trying to write a program that will loop through a text file and
 delete rows in a mysql database.

 It seemingly runs but I don't see anything getting deleted in the db.
 Is there anything apparent that I am missing?

 This is the code:
 #!/usr/bin/python
 import mysql.connector
 #
 f=open('/home/smithm/email-list.txt', 'r')
 for line in f:
 #do something with line
 # Open database connection
 db = mysql.connector.connect(user=xx, password=xx,
 host=localhost, database=xx)
 # prepare a cursor object using cursor() method
 cursor = db.cursor()

As others have said, this code connects to the database and prepares
a cursor *every time* through the loop.  You probably only want to
do those things once.

 # Prepare SQL query to DELETE required records
 sql = DELETE FROM tblc_users WHERE user_email=%s, % (line)

You don't have the sql command constructed quite right.  As written, the
sql command will be, literally:

DELETE FROM tblc_users WHERE user_email=%s, % (line)

And of course that likely won't match anything.  (As a very simple debugging
step, you could have printed the sql statement each time through the loop.
That would have alerted you immediately as to what was going on.)

You probably meant something like this instead:

sql = DELETE FROM tblc_users WHERE user_email=%s % line

This will substitute the value of line for the %s.

However, most (all?) SQL databases require string values to be enclosed
in single quotes, and your databse likely defines user_email as a string
value.  So you probably actually want something like this:

sql = DELETE FROM tblc_users WHERE user_email='%s' % line

And even this solution isn't very good, because it allows SQL injection
attacks if your text file contains something nasty.  If this is anything
other than a toy program, please take the time to look up prepared
statements.

 try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
 except:
   # Rollback in case there is any error
   db.rollback()

Again, as others have said, using a bare 'except:' statement will catch
and hide any possible error, leaving you mystified as to why nothing
happened.

 # disconnect from server
 db.close()

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


how to write file into my android phone?

2014-08-08 Thread luofeiyu
When i input usb line with my android phone into the pc , there are two 
disks j: and k: (type :removable disk)  displayed in win7.


i can get my android phone bluetooth mac address .

import bluetooth
nearby_devices = bluetooth.discover_devices(lookup_names = True)
for addr, phoneName in nearby_devices:
print(addr)


it is  6C:8B:2F:CE:5B:59

Now how can i write a file into the disk  j:  of my android 
phone(bluetooth mac is 6C:8B:2F:CE:5B:59 )?


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


Re: Newbie needing some help

2014-08-08 Thread Chris Angelico
On Sat, Aug 9, 2014 at 12:51 PM, John Gordon gor...@panix.com wrote:
 You probably meant something like this instead:

 sql = DELETE FROM tblc_users WHERE user_email=%s % line

 This will substitute the value of line for the %s.

 However, most (all?) SQL databases require string values to be enclosed
 in single quotes, and your databse likely defines user_email as a string
 value.  So you probably actually want something like this:

 sql = DELETE FROM tblc_users WHERE user_email='%s' % line

 And even this solution isn't very good, because it allows SQL injection
 attacks if your text file contains something nasty.  If this is anything
 other than a toy program, please take the time to look up prepared
 statements.

All SQL databases require strings to be quoted (it's part of the SQL
spec), although some broken database engines (which I shall not name)
do allow other forms of quote than the apostrophe. But I would advise
against even suggesting the interpolation method; there's absolutely
no reason ever to do this sort of thing - it's just way too fragile.
(Even if you think you can get it perfectly right now, do you really
want to inflict the headache on the code's next maintainer?)
Parameterized queries are a part of the Python database API, so go
ahead and use them.

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


Re: how to get the ordinal number in list

2014-08-08 Thread Steven D'Aprano
luofeiyu wrote:

   x=[x1,x3,x7,x5,x3]
   x.index(x3)
 1
 if i want the result of 1 and 4 ?

def index_all(source, target):
results = []
for i, obj in enumerate(source):
if obj == target:
results.append(i)
return results

index_all(x, x3)
= returns [1, 3]




-- 
Steven

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


Re: how to get the ordinal number in list

2014-08-08 Thread Rustom Mody
On Saturday, August 9, 2014 8:36:28 AM UTC+5:30, Steven D'Aprano wrote:
 luofeiyu wrote:

x=[x1,x3,x7,x5,x3]
x.index(x3)
  1
  if i want the result of 1 and 4 ?

 def index_all(source, target):
 results = []
 for i, obj in enumerate(source):
 if obj == target:
 results.append(i)
 return results

 index_all(x, x3)
 = returns [1, 3]

Heh!
And the OP asked for a simplification!

 def index_all(lst, val): return (i for i,v in enumerate(lst) if v == val)
... 
 index_all(abcdeaga, a)
generator object genexpr at 0x7f21884797d0
 list(index_all(abcdeaga, a))
[0, 5, 7]

[To the OP]
Yeah I am in the minority at least out here in considering
comprehensions simpler than loops. Take your pick
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue22157] FAIL: test_with_pip (test.test_venv.EnsurePipTest)

2014-08-08 Thread snehal

snehal added the comment:

1oot@beta1:/home/ubuntu/python/Python-3.4.1#  cd 
/home/ubuntu/python/Python-3.4. 
esot@beta1:/home/ubuntu/python/Python-3.4.1# ./python -E -S -m test -v 
test_ctyp 
== CPython 3.4.1 (default, Aug 7 2014, 02:08:49) [GCC 4.8.2]
==   Linux-3.13.0-32-generic-ppc64le-with-debian-jessie-sid little-endian
==   hash algorithm: siphash24 64bit
==   /home/ubuntu/python/Python-3.4.1/build/test_python_1245
Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, 
dont_write_bytecode=0, no_user_site=0, no_site=1, ignore_environment=1, 
verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0)
[1/1] test_ctypes
test_ctypes skipped -- No module named '_ctypes'
1 test skipped:
test_ctypes

-

== CPython 3.4.1 (default, Aug 7 2014, 02:08:49) [GCC 4.8.2]-m test -v 
test_venv 
==   Linux-3.13.0-32-generic-ppc64le-with-debian-jessie-sid little-endian
==   hash algorithm: siphash24 64bit
==   /home/ubuntu/python/Python-3.4.1/build/test_python_1248
Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, 
dont_write_bytecode=0, no_user_site=0, no_site=1, ignore_environment=1, 
verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0)
[1/1] test_venv
test_defaults (test.test_venv.BasicTest) ... ok
test_executable (test.test_venv.BasicTest) ... ok
test_executable_symlinks (test.test_venv.BasicTest) ... ok
test_isolation (test.test_venv.BasicTest) ... ok
test_overwrite_existing (test.test_venv.BasicTest) ... ok
test_prefixes (test.test_venv.BasicTest) ... ok
test_symlinking (test.test_venv.BasicTest) ... ok
test_unoverwritable_fails (test.test_venv.BasicTest) ... ok
test_upgrade (test.test_venv.BasicTest) ... ok
test_devnull_exists_and_is_empty (test.test_venv.EnsurePipTest) ... ok
test_explicit_no_pip (test.test_venv.EnsurePipTest) ... ok
test_no_pip_by_default (test.test_venv.EnsurePipTest) ... 
ok
test_with_pip (test.test_venv.EnsurePipTest) ... FAIL

==
FAIL: test_with_pip (test.test_venv.EnsurePipTest)
--
Traceback (most recent call last):
  File /home/ubuntu/python/Python-3.4.1/Lib/test/test_venv.py, line 352, in 
test_with_pip
with_pip=True)
subprocess.CalledProcessError: Command '['/tmp/tmp1_atkzms/bin/python', '-Im', 
'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File /home/ubuntu/python/Python-3.4.1/Lib/test/test_venv.py, line 358, in 
test_with_pip
self.fail(msg.format(exc, details))
AssertionError: Command '['/tmp/tmp1_atkzms/bin/python', '-Im', 'ensurepip', 
'--upgrade', '--default-pip']' returned non-zero exit status 1

**Subprocess Output**
Traceback (most recent call last):
  File /home/ubuntu/python/Python-3.4.1/Lib/runpy.py, line 170, in 
_run_module_as_main
__main__, mod_spec)
  File /home/ubuntu/python/Python-3.4.1/Lib/runpy.py, line 85, in _run_code
exec(code, run_globals)
  File /home/ubuntu/python/Python-3.4.1/Lib/ensurepip/__main__.py, line 4, in 
module
ensurepip._main()
  File /home/ubuntu/python/Python-3.4.1/Lib/ensurepip/__init__.py, line 209, 
in _main
default_pip=args.default_pip,
  File /home/ubuntu/python/Python-3.4.1/Lib/ensurepip/__init__.py, line 116, 
in bootstrap
_run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File /home/ubuntu/python/Python-3.4.1/Lib/ensurepip/__init__.py, line 40, 
in _run_pip
import pip
  File /tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/__init__.py, line 
9, in module
  File /tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/log.py, line 9, in 
module
  File 
/tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/colorama/__init__.py,
 line 2, in module
  File 
/tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/colorama/initialise.py,
 line 5, in module
  File 
/tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/colorama/ansitowin32.py,
 line 6, in module
  File 
/tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/colorama/winterm.py,
 line 2, in module
  File 
/tmp/tmplglzwy2e/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/colorama/win32.py,
 line 7, in module
  File /home/ubuntu/python/Python-3.4.1/Lib/ctypes/__init__.py, line 7, in 
module
from _ctypes import Union, Structure, Array
ImportError: No module named '_ctypes'


--
Ran 13 tests in 0.574s

FAILED (failures=1)
test test_venv failed
1 test failed:
test_venv

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22157
___
___
Python-bugs-list mailing list
Unsubscribe: 

[issue22157] FAIL: test_with_pip (test.test_venv.EnsurePipTest)

2014-08-08 Thread Ned Deily

Ned Deily added the comment:

Thanks. So apparently the _ctypes module failed to build.  You should rerun 
make in your build directory and find out why _ctypes.so fails to build.  If 
necessary, show the results here.

--

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

When the verbose variable is imported, it is impossible to control verbosity at 
runtime. It will be better to import only the test.support module itself and 
then access its attribute.

--

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



[issue22170] Typo in iterator doc

2014-08-08 Thread Mark Lawrence

Mark Lawrence added the comment:

The comma is needed to prevent blank newlines being printed.  Please try it for 
yourself.

--
nosy: +BreamoreBoy

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

But this doesn't matter. The patch LGTM.

--

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



[issue22172] Local files shadow system modules, even from system modules

2014-08-08 Thread Daniel Thomas

New submission from Daniel Thomas:

In Python 3.4 (but not 3.2 or 2.7) when a system module does an import then 
files with the same name in the directory of the original python script which 
match that name are used.

E.g.
With a directory containing:
test.py:
#!/usr/bin/env python3
from collections import OrderedDict
print('do stuff')

operator.py:
#!/usr/bin/env python3
print('EXPLOIT!')

Running test.py will cause:
EXPLOIT!
Traceback (most recent call last):
  File ./test.py, line 4, in module
from collections import OrderedDict
  File /usr/lib/python3.4/collections/__init__.py, line 11, in module
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'


While test.py is perfectly innocent it is in the same directory as the nasty 
operator.py and test.py makes no reference at all to operator.py but when 
'collections' is imported it imports from operator which is resolved to 
operator.py in the local directory

This is a security vulnerability because it is possible to verify that a python 
script is safe to run by reading its code and then on running it find that 
other code is implicitly loaded by the system libraries which is never 
referenced in the original file or part of any of the standard libraries.

It is also rather confusing but a related issue is already filed for that in 
issue21202.
This is similar to the standard name shadowing trap 
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap
 but now applies to other files in the source directory in a way which it 
didn't in previous versions of python. I suspect this was introduced in python 
3.3 through changes to the import system and __init__.py becoming optional but 
I don't have a 3.3 install to check that with.


sys.path here is: ['/auto/homes/drt24/pythontest', '/usr/lib/python3.4', 
'/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', 
'/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
Running Python 3.4.0-0ubuntu2 on Ubuntu 14.04.1 LTS with Linux 3.13.0-32-generic

--
components: Interpreter Core
messages: 225065
nosy: drt24
priority: normal
severity: normal
status: open
title: Local files shadow system modules, even from system modules
type: security
versions: Python 3.4

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



[issue22172] Local files shadow system modules, even from system modules

2014-08-08 Thread Nick Coghlan

Nick Coghlan added the comment:

This is not new behaviour. It's just normal system shadowing:

$ python test.py 
Traceback (most recent call last):
  File test.py, line 1, in module
import collections
  File /usr/lib64/python2.7/collections.py, line 9, in module
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name itemgetter

Avoiding that behaviour is what the new isolated mode is for:

$ ~/devel/py34/python -I test.py 
$

--
nosy: +ncoghlan
resolution:  - not a bug
stage:  - resolved
status: open - closed

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



[issue21777] Separate out documentation of binary sequence methods

2014-08-08 Thread Nick Coghlan

Nick Coghlan added the comment:

v5 has all the review comments I accepted as being in scope addressed, 
including the restoration/addition of the notes about returning the object 
unchanged for center(), ljust(), rjust() and zfill() when the field width is 
less than or equal to the length of the string.

--
Added file: 
http://bugs.python.org/file36309/separate_binary_sequence_docs_v5.diff

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



[issue21777] Separate out documentation of binary sequence methods

2014-08-08 Thread Nick Coghlan

Nick Coghlan added the comment:

I think this is done now - absent any major objections, I'll push it live in a 
couple of days time.

--
stage: patch review - commit review

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



[issue22167] iglob() has misleading documentation (does indeed store names internally)

2014-08-08 Thread Roy Smith

Roy Smith added the comment:

How about something like this:

Note: The current iglob() implementation is optimized for the case of many 
files distributed in a large directory tree.  Internally, it iterates over the 
directory tree, and stores all the names from each directory at once.  This 
will lead to pathologically inefficient behavior when any individual directory 
has a large number of files in it.

--

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



[issue22167] iglob() has misleading documentation (does indeed store names internally)

2014-08-08 Thread R. David Murray

R. David Murray added the comment:

IMO the documentation isn't *wrong*, just misleading :)

What it is saying is that *your program* doesn't have to store the full list 
returned by iglob before being able to use it (ie: iglob doesn't return a 
list).  It says nothing about what resources are used internally, other than an 
implied contract that there is *some* efficiency over calling glob; which, as 
explained above, there is.  The fact that the implementation uses lots of 
memory if any single directory is large is then a performance bug, which can 
theoretically be fixed in 3.5 using scandir.

The reason iglob was introduced, if you check the revision history, is that 
glob used to call itself recursively for each sub-directory, which meant it 
held *all* of the files in *all* of the scanned tree in memory at one time.  It 
is literally true that the difference between glob and iglob is that with iglob 
your program doesn't have to store the full list of matches from all 
subdirectories, but talking about your program is not something we typically 
do in python docs, it is implied.

Perhaps in 2.7/3.4 we can mention in the module docs that at most one 
directory's worth of data will be held in memory during the globbing process, 
but it feels a little weird to document an implementation detail like that.  
Still, if someone can come up with improved wording for the docs, we can add it.

--
nosy: +r.david.murray

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



[issue22170] Typo in iterator doc

2014-08-08 Thread R. David Murray

R. David Murray added the comment:

The comma means print doesn't add a newline to what is printed.  This is 
correct because the lines read from the file already have a newline at the end. 
 I can see how this example becomes a little confusing in a tutorial section on 
iterators, but as Mark said, if you try it, you find out that it works, and if 
you play with removing the comma you learn things about how python works with 
files (I don't remember how much of that is covered earlier in the tutorial).

In python3 this is clearer, because the equivalent line uses end='', making it 
clearer that it is intentional and meaningful.

Except...that in the python3 tutorial it currently *doesn't* use end='', so 
that example is in fact wrong and needs to be fixed :)

--
nosy: +r.david.murray
stage:  - needs patch
type: enhancement - behavior
versions: +Python 3.4, Python 3.5 -Python 2.7

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



[issue22173] Update lib2to3.tests and test_lib2to3 to use test discovery

2014-08-08 Thread Zachary Ware

New submission from Zachary Ware:

The attached patch updates lib2to3.tests and the test.test_lib2to3 script to 
use test discovery.  It also re-enables lib2to3.tests.test_all_fixers with a 
cpu resource guard.  That test has been failing since at least 3.2, but was 
never run anyway.  To allow it to pass, the patch adds from __future__ import 
print_function to lib2to3.main and lib2to3.tests.pytree_idempotency.

--
components: 2to3 (2.x to 3.x conversion tool), Tests
files: test_lib2to3_discovery.diff
keywords: patch
messages: 225072
nosy: zach.ware
priority: normal
severity: normal
stage: patch review
status: open
title: Update lib2to3.tests and test_lib2to3 to use test discovery
type: behavior
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file36310/test_lib2to3_discovery.diff

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



[issue22173] Update lib2to3.tests and test_lib2to3 to use test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Added file: http://bugs.python.org/file36311/test_lib2to3_discovery.diff

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



[issue22173] Update lib2to3.tests and test_lib2to3 to use test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file36310/test_lib2to3_discovery.diff

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



[issue22170] Typo in iterator doc

2014-08-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 35db84720d8d by Ezio Melotti in branch '3.4':
#22170: avoid printing newlines twice in tutorial example.
http://hg.python.org/cpython/rev/35db84720d8d

New changeset 79e469ae13b7 by Ezio Melotti in branch 'default':
#22170: merge with 3.4.
http://hg.python.org/cpython/rev/79e469ae13b7

--
nosy: +python-dev

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



[issue22170] Typo in iterator doc

2014-08-08 Thread Ezio Melotti

Ezio Melotti added the comment:

Fixed, thanks for the report!

--
assignee: docs@python - ezio.melotti
nosy: +ezio.melotti
resolution:  - fixed
stage: needs patch - resolved
status: open - closed

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Zachary Ware added the comment:

In pre-commit testing, I realized I was getting skips that I shouldn't have 
been getting, and it turns out that I screwed up both setUpModule functions 
from the previous patch.  New patch fixes test_loading and test_find to use the 
skipTest method instead of skip decorators, so the necessary variables are 
actually set when they're looked for.  I also combined the setUpModule in 
test_find with the setUp method of the TestOpenGL_libs into a setUpClass 
classmethod, which makes things a little simpler and cleaner.

Since I was in there anyway, I went ahead and fixed your point about 
test.support.verbose.  I had not thought about that issue previously.

I'll go ahead and commit later today unless something else jumps out as being 
wrong.

--
Added file: http://bugs.python.org/file36312/issue22060.v2.diff

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


--
versions: +Python 3.4

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Added file: http://bugs.python.org/file36313/issue22060.v2.diff

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file36312/issue22060.v2.diff

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file36313/issue22060.v2.diff

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Zachary Ware

Zachary Ware added the comment:

Maybe this one is actually right...

--
Added file: http://bugs.python.org/file36314/issue22060.v2.diff

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



[issue22148] frozen.c should #include importlib.h instead of importlib.h

2014-08-08 Thread Brett Cannon

Brett Cannon added the comment:

Unfortunately switching to angle brackets breaks on other platforms, e.g. OS X 
using Clang:

Python/frozen.c:5:10: error: 'importlib.h' file not found with angled 
include; use quotes instead
#include importlib.h
 ^
 importlib.h
1 error generated.
make: *** [Python/frozen.o] Error 1

Is there a change you want to propose in our configure or Makefile instead?

--
status: open - pending

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



[issue19500] Error when connecting to FTPS servers not supporting SSL session resuming

2014-08-08 Thread Mark Ribau

Mark Ribau added the comment:

Adding Python v2.7 as also exhibiting this behavior. 

Some people over on Stack Overflow have done some things to work around the 
issue via subclassing, but I'm not sure their solutions are correct, so much 
as have useful side effects. (For example, when only the server has a key/cert 
and the client does not, how is that handled for reuse?)

http://stackoverflow.com/questions/12164470/python-ftp-tls-connection-issue

--
nosy: +Mark.Ribau
versions: +Python 2.7

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



[issue14534] Add method to mark unittest.TestCases as do not run.

2014-08-08 Thread Wei Wu

Changes by Wei Wu we...@cacheme.net:


Added file: http://bugs.python.org/file36315/01438f18ee18.diff

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



[issue10572] Move test sub-packages to Lib/test

2014-08-08 Thread Zachary Ware

Zachary Ware added the comment:

Here's an updated patch to move the sqlite3 tests.  It's a large patch because 
it simplifies things by renaming all of the test methods from Checkxxx to 
testxxx.  The test files are also renamed to fit the usual pattern.

--
Added file: http://bugs.python.org/file36316/issue10572-sqlite3.diff

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Please commit.

--

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



[issue22060] Clean up ctypes.test, use unittest test discovery

2014-08-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset fc99cf3615bb by Zachary Ware in branch '3.4':
Issue #22060: Clean up/simplify test_ctypes, use test discovery
http://hg.python.org/cpython/rev/fc99cf3615bb

New changeset 748fb6d622e8 by Zachary Ware in branch 'default':
Closes #22060: Merge with 3.4
http://hg.python.org/cpython/rev/748fb6d622e8

--
nosy: +python-dev
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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



  1   2   >