pyPEG 2.10 released

2013-02-11 Thread Volker Birk
Hello,

pyPEG 2.10 is a maintenance release. Now optional attributes are
supported by the XML backend. There are several bugfixes.

pyPEG 2 for Python 2.7 and 3.x

Python is a nice scripting language. It even gives you access to its own
parser and compiler. It also gives you access to different other parsers
for special purposes like XML and string templates.

But sometimes you may want to have your own parser. This is what's pyPEG
for. And pyPEG supports Unicode.

The source code for all you can find on bitbucket:

https://bitbucket.org/fdik/pypeg/

To build the documentation, you'll need YML 2. You can download YML
here:

Homepage: http://fdik.org/yml/ Toolchain: http://fdik.org/yml2.tar.bz2

pyPEG 2 depends on lxml, see http://lxml.de/

Yours,
VB.
-- 
“Wer also seinen Anwendern Übles will, sollte unbedingt die Einführung von
Windows 8 in Produktivumgebungen forcieren.”

Susanne Nolte in der iX
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Jython 2.5.4rc1 and Jython 2.7b1 released!

2013-02-11 Thread Frank Wierzbicki
On behalf of the Jython development team, I'm pleased to announce that
the first release candidate of Jython 2.5.4 and the first beta of
Jython 2.7 are available.

The 2.5.4rc1 details are here:
http://fwierzbicki.blogspot.com/2013/02/jython-254-rc1-released.html

The 2.7b1 details are here:
http://fwierzbicki.blogspot.com/2013/02/jython-27-beta1-released.html

Thanks to Adconion Media Group for sponsoring my work on Jython, and
thanks to the many contributors to Jython!

-Frank
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
Hello

I have a couple of newbie questions about using Python in a FastCGI
+ Flup context on a shared CentOS server:

1. The following script runs fine...
=
#!/usr/bin/env python2.6

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Done!\n']

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
=

... while this triggers an error:
=
#!/usr/bin/env python2.6
# -*- coding: UTF-8 -*-

from cgi import escape
import sys, os

def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])

yield 'h1FastCGI Environment/h1'
yield 'table'
for k, v in sorted(environ.items()):
 yield 'trth%s/thtd%s/td/tr' % (escape(k),
escape(v))
yield '/table'

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()
=

Internal Server Error: The server encountered an internal error or
misconfiguration and was unable to complete your request. [...]
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.

2. Generally speaking, what is the right way to investigate an error
in a Python web script? FWIW I have access to the shared server
through SSH.

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 10:30:01 +0100, Gilles nos...@nospam.com wrote:
   I have a couple of newbie questions about using Python in a FastCGI
+ Flup context on a shared CentOS server:

Please ignore the thread. I found the error, and a way to catch
compile-time errors (log on through SSH, and run python
./myscript.py).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 8:39 PM, Gilles nos...@nospam.com wrote:
 On Mon, 11 Feb 2013 10:30:01 +0100, Gilles nos...@nospam.com wrote:
   I have a couple of newbie questions about using Python in a FastCGI
+ Flup context on a shared CentOS server:

 Please ignore the thread. I found the error, and a way to catch
 compile-time errors (log on through SSH, and run python
 ./myscript.py).

That'll catch some forms of error, but not everything. You may also
want to consider looking for your server's error log - that may be
getting the actual traceback. I don't know what your server setup is,
but there's likely to be one somewhere.

A question though. You say 2.4.3 in your subject line, but your
shebang says python2.6 - which version are you actually running? At
very least, I'd recommend using python2.6 to run your script from the
shell; if there's any incompatibility between the system Python (which
quite plausibly would be the 2.4.3 you named) and the one your CGI
script uses (named python2.6 and my guess would be that it's 2.6.6),
you'll confuse yourself when you do your shell test.

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


Error in reading and writing CSV format file in python

2013-02-11 Thread inshu chauhan
In the programme below I am trying to read two csv format files and process
them and write a new file with some of theirs data.

import csv
f1_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00.arff))
f2_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00_noxy+class.arff))
nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)

while True:
l1 = f1_reader.next()
while len(l1) != 12:
l1 = f1_reader.next()
l2 = f2_reader.next()
while len(l2) != 11:
l2 = f2_reader.next()

ix = l1[0].strip()
iy = l1[1].strip()
classification = l2[8].strip()

print  nf, ix, iy, classification

nf.close()

This programme is giving me this error now :

Traceback (most recent call last):
  File Z:\Weka work\final_image_classificationwithoutxy.py, line 16, in
module
l2 = f2_reader.next()
StopIteration


what could be a possible reason to StopIteration ???


I checked the syntax and usage of this module looks alright to me , but
then why this error ?


Thankyou in Advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico ros...@gmail.com
wrote:
That'll catch some forms of error, but not everything. You may also
want to consider looking for your server's error log - that may be
getting the actual traceback. I don't know what your server setup is,
but there's likely to be one somewhere.

Good to know.

A question though. You say 2.4.3 in your subject line, but your
shebang says python2.6 - which version are you actually running?

I didn't pay attention to this. Support says that I should use 2.6,
but running python -V through SSH says 2.4.3. I'll ask support which
to use.

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 10:22 PM, Gilles nos...@nospam.com wrote:
 On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico ros...@gmail.com
 wrote:
That'll catch some forms of error, but not everything. You may also
want to consider looking for your server's error log - that may be
getting the actual traceback. I don't know what your server setup is,
but there's likely to be one somewhere.

 Good to know.

A question though. You say 2.4.3 in your subject line, but your
shebang says python2.6 - which version are you actually running?

 I didn't pay attention to this. Support says that I should use 2.6,
 but running python -V through SSH says 2.4.3. I'll ask support which
 to use.

Try running python2.6 -V

Your shebang line says that it's looking for a program named
python2.6, which is quite probably not the same as the one named
just python.

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


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico ros...@gmail.com
wrote:
Try running python2.6 -V

Your shebang line says that it's looking for a program named
python2.6, which is quite probably not the same as the one named
just python.

Indeed, they have two versions of Python installed:

# python2.6 -V
Python 2.6.4

# python -V
Python 2.4.3

I'll make sure to use 2.6.

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 10:36 PM, Gilles nos...@nospam.com wrote:
 On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico ros...@gmail.com
 wrote:
Try running python2.6 -V

Your shebang line says that it's looking for a program named
python2.6, which is quite probably not the same as the one named
just python.

 Indeed, they have two versions of Python installed:

 # python2.6 -V
 Python 2.6.4

 # python -V
 Python 2.4.3

 I'll make sure to use 2.6.

It's entirely possible you have a third Python, a 3.x, as well.
Different Pythons coexist quite happily on a system.

Anyway, seems your issue's sorted out. Yay!

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Tim Chase
On Mon, 11 Feb 2013 18:24:05 +1100 Chris Angelico ros...@gmail.com
wrote:
 Is that Unicode string theory or ASCII string theory?

+1 QOTW :-)

-tkc


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


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 22:42:50 +1100, Chris Angelico ros...@gmail.com
wrote:
It's entirely possible you have a third Python, a 3.x, as well.
Different Pythons coexist quite happily on a system.

Thank for the help. I'm on my way to figure out how mod_fcgid, Flup,
and Python scripts work together.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Sunday, February 10, 2013 5:37:46 AM UTC-6, Steven D'Aprano wrote:
 Rick Johnson wrote:
  IMO Set Types should only exists as a concequence of freezing an
  array,
 
 Sets are not frozen lists.

Indeed. That wording was a bit clumsy on my part.

  and should have NO literal syntax available. 

I may have spoken too soon on this issue. My reasoning for /not/ having a 
literal set syntax was due to symbol congestion, however as i described in 
another post, the problem can be solved by literally type declaring the 
literal.

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


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread MRAB

On 2013-02-11 11:00, inshu chauhan wrote:

In the programme below I am trying to read two csv format files and
process them and write a new file with some of theirs data.

import csv
f1_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00.arff))
f2_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00_noxy+class.arff))
nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)

while True:
 l1 = f1_reader.next()
 while len(l1) != 12:
 l1 = f1_reader.next()
 l2 = f2_reader.next()
 while len(l2) != 11:
 l2 = f2_reader.next()

 ix = l1[0].strip()
 iy = l1[1].strip()
 classification = l2[8].strip()

 print  nf, ix, iy, classification

nf.close()

This programme is giving me this error now :

Traceback (most recent call last):
   File Z:\Weka work\final_image_classificationwithoutxy.py, line 16,
in module
 l2 = f2_reader.next()
StopIteration


what could be a possible reason to StopIteration ???


I checked the syntax and usage of this module looks alright to me , but
then why this error ?


It has reached the end of the file, there's no next line.

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


Re: Import redirects

2013-02-11 Thread Oscar Benjamin
On 11 February 2013 06:50, Isaac To isaac...@gmail.com wrote:
 I have a package (say foo) that I want to rename (say, to bar), and for
 compatibility reasons I want to be able to use the old package name to refer
 to the new package.  Copying files or using filesystem symlinks is probably
 not the way to go, since that means any object in the modules of the package
 would be duplicated, changing one will not cause the other to be updated.

A symlink would not have these problems, although it's not a
completely portable solution.

 Instead, I tried the following as the content of `foo/__init__.py`:

 import sys
 import bar
 sys.modules['foo'] = bar

 To my surprise, it seems to work.  If I `import foo` now, the above will
 cause bar to be loaded and be used, which is expected.  But even if I
 `import foo.baz` now (without first `import foo`), it will now correctly
 import bar.baz in its place.

 Except one thing: it doesn't really work.  If I `import foo.baz.mymod` now,
 and if in bar.baz.mymod there is a statement `import bar.baz.depmod`, then
 it fails.  It correctly load the file bar/baz/depmod.py, and it assigns
 the resulting module to the package object bar.baz as the depmod variable.
 But it fails to assign the module object of mymod into the bar.baz
 module.  So after `import foo.baz.mymod`, `foo.baz.mymod` results in an
 AttributeError saying 'module' object has no attribute 'mymod'.  The natural
 `import bar.baz.mymod` is not affected.

My guess is that you have two copies of the module object bar.baz with
one under the name foo.baz and the other under the name bar.baz. mymod
is inserted at bar.baz but not at foo.baz. I think a solution in this
case would be to have your foo/__init__.py also import the subpackage
'bar.baz' and give it both names in sys.modules:

import bar.baz
sys.modules['foo.baz'] = bar.baz


Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Saturday, February 9, 2013 11:04:42 PM UTC-6, Chris Angelico wrote:
 On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson wrote:
  Well Chris i have wonderful news for you! Python /does/
  have homogenous arrays, and they're called, wait for
  it. arrays!

 That's not a built-in. But you were the one who complained about the
 way sum() could be applied to a list that contains a non-integer;
 maybe your solution is simply to ignore sum() and work with
 array.array?

Yes i could, however by doing so i would be ignoring the inconsistent elephant 
in the room. My crusade is to bring consistency and logic to languages, and if 
i have any free time afterwards, to remove multiplicity. There are two types of 
people in the world Chris, those that lead and those that follow. 

 Nice how you can complain about Python for not having something, then
 heap scorn on me for not being aware that it's there in the stdlib.
 (Which, by the way, I freely admit to being less than fully familiar
 with. Even less familiar with what's on PyPI.)

Well i would expect anyone who considers himself a python programmer (not to 
mention pythonista!) to at minimum be familiar with the stdlib. That does not 
mean he must have attained black belt level kung-fu in /every/ stdlib module, 
but he must at least /know/ all the modules names and all types that Python 
offers. Is that really too much to ask Chris?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread Steven D'Aprano
inshu chauhan wrote:

 In the programme below I am trying to read two csv format files and
 process them and write a new file with some of theirs data.
 
 import csv
 f1_reader = csv.reader(open(rZ:\Weka
 work\Feature_Vectors_Fullset_00.arff))
 f2_reader = csv.reader(open(rZ:\Weka
 work\Feature_Vectors_Fullset_00_noxy+class.arff))
 nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)
 
 while True:
 l1 = f1_reader.next()
 while len(l1) != 12:
 l1 = f1_reader.next()
 l2 = f2_reader.next()
 while len(l2) != 11:
 l2 = f2_reader.next()
 
 ix = l1[0].strip()
 iy = l1[1].strip()
 classification = l2[8].strip()
 
 print  nf, ix, iy, classification
 
 nf.close()
 
 This programme is giving me this error now :
 
 Traceback (most recent call last):
   File Z:\Weka work\final_image_classificationwithoutxy.py, line 16, in
 module
 l2 = f2_reader.next()
 StopIteration
 
 
 what could be a possible reason to StopIteration ???

next() raises StopIteration when there is nothing else to return.


py it = iter([1, 2, 3])
py it.next()
1
py it.next()
2
py it.next()
3
py it.next()
Traceback (most recent call last):
  File stdin, line 1, in module
StopIteration


You have reached the end of the file and there is nothing else for the CSV
reader to return, so it raises StopIteration.



-- 
Steven

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


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 11:18 PM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 On Sunday, February 10, 2013 5:37:46 AM UTC-6, Steven D'Aprano wrote:
 Rick Johnson wrote:
  IMO Set Types should only exists as a concequence of freezing an
  array,

 Sets are not frozen lists.

 Indeed. That wording was a bit clumsy on my part.

  and should have NO literal syntax available.

 I may have spoken too soon on this issue. My reasoning for /not/ having a 
 literal set syntax was due to symbol congestion, however as i described in 
 another post, the problem can be solved by literally type declaring the 
 literal.

Or doing what you were pointing and laughing at Pike for, and using
two-symbol delimiters. You could even make it majorly logical:

list_ = [[ 1, 2, 3 ]]
tuple_ = ([ 1, 2, 3 ])
dict_ = [{ 1, 2, 3 }]
frozendict_ = ({ 1, 2, 3 })
set_ = [ 1, 2, 3 ]
frozenset_ = ( 1, 2, 3 )

I'm not actually sure where I stand on that argument. Some of those
types are distinctly unusual (when would you use frozendict?), and may
well not need literal notation. But it is nice to have them all.

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


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread inshu chauhan
On Mon, Feb 11, 2013 at 1:26 PM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 inshu chauhan wrote:

  In the programme below I am trying to read two csv format files and
  process them and write a new file with some of theirs data.
 
  import csv
  f1_reader = csv.reader(open(rZ:\Weka
  work\Feature_Vectors_Fullset_00.arff))
  f2_reader = csv.reader(open(rZ:\Weka
  work\Feature_Vectors_Fullset_00_noxy+class.arff))
  nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)
 
  while True:
  l1 = f1_reader.next()
  while len(l1) != 12:
  l1 = f1_reader.next()
  l2 = f2_reader.next()
  while len(l2) != 11:
  l2 = f2_reader.next()
 
  ix = l1[0].strip()
  iy = l1[1].strip()
  classification = l2[8].strip()
 
  print  nf, ix, iy, classification
 
  nf.close()
 
  This programme is giving me this error now :
 
  Traceback (most recent call last):
File Z:\Weka work\final_image_classificationwithoutxy.py, line 16, in
  module
  l2 = f2_reader.next()
  StopIteration
 
 
  what could be a possible reason to StopIteration ???

 next() raises StopIteration when there is nothing else to return.


 py it = iter([1, 2, 3])
 py it.next()
 1
 py it.next()
 2
 py it.next()
 3
 py it.next()
 Traceback (most recent call last):
   File stdin, line 1, in module
 StopIteration


 You have reached the end of the file and there is nothing else for the CSV
 reader to return, so it raises StopIteration.



But why does it has nothing to return so early before traversing the whole
file ? Is there any way it can be corrected ?  And also the programme isn't
writing anything to the file ?




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


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 11:28 PM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 On Saturday, February 9, 2013 11:04:42 PM UTC-6, Chris Angelico wrote:
 On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson wrote:
  Well Chris i have wonderful news for you! Python /does/
  have homogenous arrays, and they're called, wait for
  it. arrays!

 That's not a built-in. But you were the one who complained about the
 way sum() could be applied to a list that contains a non-integer;
 maybe your solution is simply to ignore sum() and work with
 array.array?

 Yes i could, however by doing so i would be ignoring the inconsistent 
 elephant in the room. My crusade is to bring consistency and logic to 
 languages, and if i have any free time afterwards, to remove multiplicity. 
 There are two types of people in the world Chris, those that lead and those 
 that follow.

In other words, you prefer to argue than to code.

 Nice how you can complain about Python for not having something, then
 heap scorn on me for not being aware that it's there in the stdlib.
 (Which, by the way, I freely admit to being less than fully familiar
 with. Even less familiar with what's on PyPI.)

 Well i would expect anyone who considers himself a python programmer (not to 
 mention pythonista!) to at minimum be familiar with the stdlib. That does 
 not mean he must have attained black belt level kung-fu in /every/ stdlib 
 module, but he must at least /know/ all the modules names and all types that 
 Python offers. Is that really too much to ask Chris?

Actually, it is. How many modules and types does Python offer? Can you
tell me, without looking it up? Okay. Now how many does Ruby offer?
Presumably you extend the same courtesy to other languages. Now
imagine someone who knows twenty languages. Will s/he know their
entire stdlibs?

If there is anyone here who can honestly boast knowing the ENTIRE
stdlib of a language the size of Python, I would be impressed. Very
impressed.

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Rick Johnson
On Sunday, February 10, 2013 6:36:20 PM UTC-6, Steven D'Aprano wrote:
 Rick Johnson wrote:
  On Sunday, February 10, 2013 5:29:54 AM UTC-6, Steven D'Aprano wrote:
  Rick wrote:
  [...]
  Steven, the definition of flatten (as relates to sequences) is very, VERY
  simple:
  
  Return a new sequence that is the result of reducing
  a nested sequence of sequences into a single depth
  sequence.
 
 Very, VERY simple until you actually implement this function, and discover
 that it does too much e.g.

I would implement it as a method of sequence types, but i digress!

 flatten([None, 23, [1, 2, 3], Point(x=2, y=3), [spam, ham]])
 = [None, 23, 1, 2, 3, 2, 3, 's', 'p', 'a', 'm', 'h', 'a', 'm']
 
 So people who have *actually programmed*, instead of just talking about
 programming, have discovered that in practice you need to treat some
 sequences as primitives that don't get expanded.

Which primitive(s) should NOT have been expanded in your opinion? The Point 
object? I agree, that's why MY implementation would call seq.flatten() on all 
sub-sequences THEREBY allowing each subtype to define it's own flatten 
behavior. Of course the default behavior of the SequenceBase#flatten would be 
to flatten everything. 

However, ImmutableSequence Types would not flatten. In your example [spam, 
ham] would not be expanded to ['s', 'p', 'a', 'm', 'h', 'a', 'm']. psst: 
strings and tuples are immutable!


I'm not convinced that flattening immutable types is a good idea anyway, 
because heck, they're designed to be immutable! I suppose if we are not 
flattening in-place it really would not matter though. Creating a new 
immutable object that is the result of reordering an existing immutable 
object's values is not mutation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread MRAB

On 2013-02-11 12:44, inshu chauhan wrote:


On Mon, Feb 11, 2013 at 1:26 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info
mailto:steve+comp.lang.pyt...@pearwood.info wrote:

inshu chauhan wrote:

  In the programme below I am trying to read two csv format files and
  process them and write a new file with some of theirs data.
 
  import csv
  f1_reader = csv.reader(open(rZ:\Weka
  work\Feature_Vectors_Fullset_00.arff))
  f2_reader = csv.reader(open(rZ:\Weka
  work\Feature_Vectors_Fullset_00_noxy+class.arff))
  nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)
 
  while True:
  l1 = f1_reader.next()
  while len(l1) != 12:
  l1 = f1_reader.next()
  l2 = f2_reader.next()
  while len(l2) != 11:
  l2 = f2_reader.next()
 
  ix = l1[0].strip()
  iy = l1[1].strip()
  classification = l2[8].strip()
 
  print  nf, ix, iy, classification
 
  nf.close()
 
  This programme is giving me this error now :
 
  Traceback (most recent call last):
File Z:\Weka work\final_image_classificationwithoutxy.py,
line 16, in
  module
  l2 = f2_reader.next()
  StopIteration
 
 
  what could be a possible reason to StopIteration ???

next() raises StopIteration when there is nothing else to return.


py it = iter([1, 2, 3])
py it.next()
1
py it.next()
2
py it.next()
3
py it.next()
Traceback (most recent call last):
   File stdin, line 1, in module
StopIteration


You have reached the end of the file and there is nothing else for
the CSV
reader to return, so it raises StopIteration.



But why does it has nothing to return so early before traversing the
whole file ? Is there any way it can be corrected ?  And also the
programme isn't writing anything to the file ?


Try adding some logging so that you can see what it's doing. A simple way
would be something like:

log_file = open(rZ:\Weka work\log.txt, w)

...

l1 = f1_reader.next()
print  log_file, Read from f1:, l1
print  log_file, Length is, len(l1)
while len(l1) != 12:
l1 = f1_reader.next()
print  log_file, Read from f1:, l1
print  log_file, Length is, len(l1)

and so on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread inshu chauhan
On Mon, Feb 11, 2013 at 2:02 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 On 2013-02-11 12:44, inshu chauhan wrote:


 On Mon, Feb 11, 2013 at 1:26 PM, Steven D'Aprano
 steve+comp.lang.python@**pearwood.infosteve%2bcomp.lang.pyt...@pearwood.info
 mailto:steve+comp.lang.**pyt...@pearwood.infosteve%2bcomp.lang.pyt...@pearwood.info
 wrote:

 inshu chauhan wrote:

   In the programme below I am trying to read two csv format files and
   process them and write a new file with some of theirs data.
  
   import csv
   f1_reader = csv.reader(open(rZ:\Weka
   work\Feature_Vectors_Fullset_**00.arff))
   f2_reader = csv.reader(open(rZ:\Weka
   work\Feature_Vectors_Fullset_**00_noxy+class.arff))
   nf = open(rZ:\Weka work\classified_image00_**withoutxy.arff,
 w)
  
   while True:
   l1 = f1_reader.next()
   while len(l1) != 12:
   l1 = f1_reader.next()
   l2 = f2_reader.next()
   while len(l2) != 11:
   l2 = f2_reader.next()
  
   ix = l1[0].strip()
   iy = l1[1].strip()
   classification = l2[8].strip()
  
   print  nf, ix, iy, classification
  
   nf.close()
  
   This programme is giving me this error now :
  
   Traceback (most recent call last):
 File Z:\Weka work\final_image_**classificationwithoutxy.py,
 line 16, in
   module
   l2 = f2_reader.next()
   StopIteration
  
  
   what could be a possible reason to StopIteration ???

 next() raises StopIteration when there is nothing else to return.


 py it = iter([1, 2, 3])
 py it.next()
 1
 py it.next()
 2
 py it.next()
 3
 py it.next()
 Traceback (most recent call last):
File stdin, line 1, in module
 StopIteration


 You have reached the end of the file and there is nothing else for
 the CSV
 reader to return, so it raises StopIteration.



 But why does it has nothing to return so early before traversing the
 whole file ? Is there any way it can be corrected ?  And also the
 programme isn't writing anything to the file ?

  Try adding some logging so that you can see what it's doing. A simple way
 would be something like:

 log_file = open(rZ:\Weka work\log.txt, w)

 ...

 l1 = f1_reader.next()
 print  log_file, Read from f1:, l1
 print  log_file, Length is, len(l1)

 while len(l1) != 12:
 l1 = f1_reader.next()
 print  log_file, Read from f1:, l1
 print  log_file, Length is, len(l1)

 and so on.
 --
 http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list



Thanks :) This worked !!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 6:40:23 AM UTC-6, Chris Angelico wrote:
 [...]
 Or doing what you were pointing and laughing at Pike for, and using
 two-symbol delimiters. You could even make it majorly logical:
 
 list_ = [[ 1, 2, 3 ]]
 tuple_ = ([ 1, 2, 3 ])
 dict_ = [{ 1, 2, 3 }]
 frozendict_ = ({ 1, 2, 3 })
 set_ = [ 1, 2, 3 ]
 frozenset_ = ( 1, 2, 3 )

I am vehemently against using more than one opening seq char and one closing 
seq char. It works fine for single depth sequences, however, once you start 
nesting the mental focus required to parse the doubled openers/closers is 
headache inducing. I would accept wrapping the literal in some sort of 
declaration though, something like i proposed earlier in the thread. The 
easiest is to use:

  set({1,2,3})

but that looks like a function call! So we'd need a unique syntax. Either a 
single tag like:

  set{1,2,3}

Or we could use start and end tags like:

  set{1,2,3}set

where set{ and }set are delimiters. For lists, tuples, and dict we would 
use the short form because these literals are far too ubiquitous:

  [1,2,3] # list
  {k:v} # dict
  (1,2,3) # tuple

However, the grouping chars for tuples has always been confusing because they 
can clash with grouping of expressions. What is this?

  (1)

It's NOT a tuple! But it looks like a tuple! What is this:

  1,2

it IS a tuple, but it does not look like a tuple! 

That's an unfortunate side effect of a poorly thought-out tuple syntax. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 11:53 PM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 Which primitive(s) should NOT have been expanded in your opinion? The Point 
 object? I agree, that's why MY implementation would call seq.flatten() on all 
 sub-sequences THEREBY allowing each subtype to define it's own flatten 
 behavior. Of course the default behavior of the SequenceBase#flatten would be 
 to flatten everything.

 However, ImmutableSequence Types would not flatten. In your example [spam, 
 ham] would not be expanded to ['s', 'p', 'a', 'm', 'h', 'a', 'm']. psst: 
 strings and tuples are immutable!

So...

flatten([None, 23, [1, 2, 3], (2, 3), [spam, ham]])

would return

[None, 23, 1, 2, 3, (2, 3), spam, ham]

? I think that's even more unexpected.

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


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 6:50:03 AM UTC-6, Chris Angelico wrote:
 On Mon, Feb 11, 2013 at 11:28 PM, Rick Johnson
  Well i would expect anyone who considers himself a
  python programmer (not to mention pythonista!) to at
  minimum be familiar with the stdlib. [...]
 
 [...]
 
 If there is anyone here who can honestly boast knowing the ENTIRE
 stdlib of a language the size of Python, I would be impressed. Very
 impressed.

I am sure there are quite a few Chris. But if you expect to around making 
statements like: Python does not have typed arrays, then don't get all upset 
when someone corrects you. 

Maybe, before you go and pop your mouth off next time, if it isn't too much 
trouble, i mean, i don't want you to get a cramp in your wrist or a blister on 
your finger, much less a headache reading a few lines of documentation, but if 
is not too much to ask, Mr. Angelico, i would suggest you stuff this tiny 
little code snippet into your favorite Python interpreter and run it!

py help('modules')

See, some python functions are useful. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:13 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 I am vehemently against using more than one opening seq char and one 
 closing seq char. ... we could use start and end tags like:

   set{1,2,3}set

 where set{ and }set are delimiters.

Interesting. So what you're actually against is the symbols. Okay. I
have a bit of a Scheme (rubs hands together with glee) for you. We can
thtandardithe on jutht one thymbol pair and uthe wordth for the retht.
And to make it clear that thith ith no function call, we'll put the
word *inthide* the parenthetheth.

(set 1 2 3)
(dict 1 2 3 4)   ; implicitly pairs up the arguments
(tuple 1 2)
(list 1 2 3 4); This seems like a real good idea.

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


Re: Logging within a class

2013-02-11 Thread Jean-Michel Pichavant
- Original Message -
 Within __init__ I setup a log with self.log =
 logging.getLogger('foo') then add a
 console and filehandler which requires the formatting to be
 specified. There a few
 methods I setup a local log object by calling getChild against the
 global log object.
 
 
 This works fine until I need to adjust the formatter for a few. With
 this style, I need
 to redefine the handlers, so basically setup logging again.
 
 
 I tried to get around this by using basicConfig and simply
  re-specifying format inside
 the few methods, but it didn't work.
 
 
 How does one accomplish this most elegantly so I can define one log
 instance with
 the appropriate general console and file handlers in my class, then
 simply override
 the formatter for both handlers they use in a couple methods?
 
 
 Thanks!
 jlc

Hi,

Depend on what type of customization you need, if you need additional fields, 
that's pretty easy : 
http://docs.python.org/2/howto/logging-cookbook.html#context-info

If you need to completely change the format pattern, I'm not sure there an easy 
way, thread safe to do such thing. The closest thing that comes to my mind 
would be to write your own Formatter than can handle multiple formats, 
depending on the record attributes:

Class MultiFormatter(logging.Formatter):
  def format(record): 
if record.funcName == 'bar':
  # substitute self._fmt with something else
  
  # then call super(format)
  logging.Formatter(self, record) # not sure this one would be thread safe

Records have a funcName and module attribute, but I'm not sure collision could 
be handled properly with those.

Maybe the safest thing to do would be to add a contextual info to your log 
holding a specific format.

class Foo():
  def bar(self):
self.logger.info(hello, extra = {'format' : %(message)s}) # would be 
handled in MultiFormatter

cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:28 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 I am sure there are quite a few Chris. But if you expect to around making 
 statements like: Python does not have typed arrays, then don't get all 
 upset when someone corrects you.

Oh, I don't mind being corrected on those sorts of points. And if ever
I say Python doesn't have a module for creating a DNS server, I will
be quite happy to be corrected, because DNS servers are fun.

But my statement wasn't based on my own knowledge of the stdlib, but
rather on this:

On Sat, Feb 9, 2013 at 6:58 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 I'm a bit unnerved by the sum function. Summing a sequence only makes sense 
 if the sequence in question contains /only/ numeric types. For that reason i 
 decided to create a special type for holding Numerics.

Why create a special type if it already exists?

 Maybe, before you go and pop your mouth off next time, if it isn't too much 
 trouble, i mean, i don't want you to get a cramp in your wrist or a blister 
 on your finger, much less a headache reading a few lines of documentation, 
 but if is not too much to ask, Mr. Angelico, i would suggest you stuff this 
 tiny little code snippet into your favorite Python interpreter and run it!

 py help('modules')

 See, some python functions are useful.

Yep. By the way, how does the help function fit into your wonderfully
OOP model? What's it a method on?

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


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread Dave Angel

On 02/11/2013 06:00 AM, inshu chauhan wrote:

In the programme below I am trying to read two csv format files and process
them and write a new file with some of theirs data.

import csv
f1_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00.arff))
f2_reader = csv.reader(open(rZ:\Weka
work\Feature_Vectors_Fullset_00_noxy+class.arff))
nf = open(rZ:\Weka work\classified_image00_withoutxy.arff, w)

while True:
 l1 = f1_reader.next()
 while len(l1) != 12:
 l1 = f1_reader.next()
 l2 = f2_reader.next()
 while len(l2) != 11:
 l2 = f2_reader.next()

 ix = l1[0].strip()
 iy = l1[1].strip()
 classification = l2[8].strip()

 print  nf, ix, iy, classification

nf.close()

This programme is giving me this error now :

Traceback (most recent call last):
   File Z:\Weka work\final_image_classificationwithoutxy.py, line 16, in
module
 l2 = f2_reader.next()
StopIteration


what could be a possible reason to StopIteration ???


I checked the syntax and usage of this module looks alright to me , but
then why this error ?




That's not an error, it's just a normal way to end a for-loop.  If you 
were using a syntax like:

  for item in f2_reader:

the StopIteration would simply end the loop.  Since you're doing it 
manually, you have to handle the exception yourself.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Alternative to Apache+mod_fcgid+Flup?

2013-02-11 Thread Chris Rebert
On Feb 11, 2013 6:16 AM, Gilles nos...@nospam.com wrote:

 Hello

 I read this article...

 Why is WSGI deployment under FASTCGI so painful?

http://blog.dscpl.com.au/2011/09/why-is-wsgi-deployment-under-fastcgi-so.html

 ... and was wondering what better alternative is available to run
 Python web scripts?

If you want to stick with Apache, mod_wsgi is the obvious alternative.

 Someone recommends nginx + uWSGI.What do you think?

We use that combination at my workplace, and it works well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in reading and writing CSV format file in python

2013-02-11 Thread inshu chauhan
On Mon, Feb 11, 2013 at 3:22 PM, Dave Angel da...@davea.name wrote:

 On 02/11/2013 06:00 AM, inshu chauhan wrote:

 In the programme below I am trying to read two csv format files and
 process
 them and write a new file with some of theirs data.

 import csv
 f1_reader = csv.reader(open(rZ:\Weka
 work\Feature_Vectors_Fullset_**00.arff))
 f2_reader = csv.reader(open(rZ:\Weka
 work\Feature_Vectors_Fullset_**00_noxy+class.arff))
 nf = open(rZ:\Weka work\classified_image00_**withoutxy.arff, w)

 while True:
  l1 = f1_reader.next()
  while len(l1) != 12:
  l1 = f1_reader.next()
  l2 = f2_reader.next()
  while len(l2) != 11:
  l2 = f2_reader.next()

  ix = l1[0].strip()
  iy = l1[1].strip()
  classification = l2[8].strip()

  print  nf, ix, iy, classification

 nf.close()

 This programme is giving me this error now :

 Traceback (most recent call last):
File Z:\Weka work\final_image_**classificationwithoutxy.py, line
 16, in
 module
  l2 = f2_reader.next()
 StopIteration


 what could be a possible reason to StopIteration ???


 I checked the syntax and usage of this module looks alright to me , but
 then why this error ?



 That's not an error, it's just a normal way to end a for-loop.  If you
 were using a syntax like:
   for item in f2_reader:

 the StopIteration would simply end the loop.  Since you're doing it
 manually, you have to handle the exception yourself.


 --
 DaveA
 --
 http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list


Yes , therefore I used try and except.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Roy,

On Feb 11, 2013, at 10:24 AM, Roy Smith r...@panix.com wrote:
 
 Is this server that you're talking to something that you have control 
 over, i.e. are you stuck with this protocol?  Given a choice, I'd go 
 with something like JSON, for which pre-existing libraries for every 
 language under the sun.
 
I'm running JSON for my application messaging protocol but with JSON and python 
default unordered dict,
there's no guarantee if I put in the length key in the JSON message, it will be 
placed on the first bytes hence
why it was designed for a fixed 4-byte at the start of the message to indicate 
the message length.

Beyond the 4-bytes it is all JSON.

but if you have a better idea, i would certainly welcome it.

 Do you actually *know* what the value of nbuf is?  Is it possible that 
 (somehow) it's 0?  You should print (log, whatever), the value of nbuf, 
 just to make sure.

nbuf is printing the right bytes amount, I removed the print statement before I 
made the first post.

So to clarify, I added a print statement between the first recv and the second.

{msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 
1.0, data: {1: igb0, 2: igb1, ifcnt: 2}}
connected to misty:8080
sending data
138 bytes sent: 0x86{msgver: 1.0, msgid: 200, subcode: 100, 
appver: 1.0, appid: 1.0, data: {1: igb0, 2: igb1, ifcnt: 
2}}
receiving data
message length is 188
0 bytes received:

So the subsequent recv() call will be readjusted with 188 bytes buffer size so 
theoretically, recv shouldn't return 0.

The same logic that I used to send to the server from the python client that 
the server will readjust the second recv() call based on the length 
information. On this 2nd recv() call the server is able to obtain the rest of 
the messages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Dave,

On Feb 11, 2013, at 9:22 AM, Dave Angel da...@davea.name wrote:

 Exactly how are you sending hexadecimal ?  If that 0xad (which is only one 
 byte, what about the other 3 ?) is intended to be a C description, then it's 
 certainly not hex, it's binary.  And probably little-endian, to boot.  That's 
 a mistake, as network protocols almost always use big-endian.
 
 So what is the range of values for the length, and how are they actually 
 encoded?  Are they uint32 in native binary format?   And are you permitted to 
 change the encoding, to fix it?  (If it were my choice, I'd make it a 
 printable decimal value, first choice, or printable hex, second choice.)

They are ASCII stream, actually JSON with the exception of the first 4 bytes. I 
avoided using struct class for this as it's overkill for my application.

So the idea is that i code the length to a max of 0xff (max length of 256 
bytes), I would only have to assign 4 bytes to it. If i need 1k length, i just 
need to increase it to 6 bytes or 4 if i decide to strip the 0x.

the code for the function is as follows:

def request_get_session(sock, jmsg):
# append message length
plen = hex(len(jmsg))
msg = '{0}{1}'.format(plen, jmsg)

print 'sending data'
n = sock.send(msg)
str = '{0} bytes sent: {1}'.format(n, msg)
print str

# receive message length
print 'receiving data'
mlen = sock.recv(4)
try:
nbuf = int(mlen, 16)
except ValueError as e:
print 'invalid length type'
return -1

print 'message length is {0}'.format(nbuf)

while True:
buf = sock.recv(nbuf)

if not buf:
break

slen = len(buf)
str = {0} bytes received: {1}.format(slen, buf)
print str
return 0
 
 
 I've managed to receive and translate the message length until I reach my 
 second recv which I readjusted the buffer size to include the new message 
 length.
 
 However that failed and recv received 0 bytes. I implemented the same 
 algorithm on the server side using C and it work so appreciate if you can 
 help me on this.
 
 # receive message length
 print 'receiving data'
 mlen = sock.recv(4)
 try:
 nbuf = int(mlen, 16)
 
 That supposes the count is being sent as a printable string of hex digits.  
 That's not what I concluded above.

That is what I meant. it just an ascii string.

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


matplotlib - removing text from a figure - a bug?

2013-02-11 Thread Raphael Mameghani
Does anyone know if the following error message is a matplotlib bug?
Is there an correct/alternative way to remove (or replace) text? Thank
you, Raphael

from matplotlib.figure import Figure
fig = Figure()
caption = fig.suptitle(test)
caption.remove()

Traceback (most recent call last):
  File pyshell#6, line 1, in module
caption.remove()
  File C:\Programme\Python27\lib\site-packages\matplotlib\artist.py,
line 134, in remove
raise NotImplementedError('cannot remove artist')
NotImplementedError: cannot remove artist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi MRAB,

My code now works thanks to your advice.

{msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 
1.0, data: {1: igb0, 2: igb1, ifcnt: 2}}
connected to misty:8080
sending data
138 bytes sent: 0x86{msgver: 1.0, msgid: 200, subcode: 100, 
appver: 1.0, appid: 1.0, data: {1: igb0, 2: igb1, ifcnt: 
2}}
receiving data
message length is 188
188 bytes received: { msgver: 1.00, appver: 1.00, appid: 1000, 
msgid: 10, subcode: 20, data: [ 110.159.183.16, 124.108.16.94, 
2400:3700:50::2, 2400:3700:50::1, 2400:3700:51:: ] }

Many thanks.

On Feb 11, 2013, at 9:55 AM, MRAB pyt...@mrabarnett.plus.com wrote:

 You should keep reading until you get all need or the connection is
 closed:
 
buf = b''
while len(buf)  nbuf:
chunk = sock.recv(nbuf - len(buf))
 
if not chunk:
break
 
buf += chunk
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Python recv loop

2013-02-11 Thread MRAB

On 2013-02-11 14:56, Ihsan Junaidi Ibrahim wrote:

Hi Roy,

On Feb 11, 2013, at 10:24 AM, Roy Smith r...@panix.com wrote:


Is this server that you're talking to something that you have control
over, i.e. are you stuck with this protocol?  Given a choice, I'd go
with something like JSON, for which pre-existing libraries for every
language under the sun.


I'm running JSON for my application messaging protocol but with JSON and python 
default unordered dict,
there's no guarantee if I put in the length key in the JSON message, it will be 
placed on the first bytes hence
why it was designed for a fixed 4-byte at the start of the message to indicate 
the message length.

Beyond the 4-bytes it is all JSON.

but if you have a better idea, i would certainly welcome it.


I probably wouldn't make it fixed length. I'd have the length in
decimal followed by, say, \n.


Do you actually *know* what the value of nbuf is?  Is it possible that
(somehow) it's 0?  You should print (log, whatever), the value of nbuf,
just to make sure.


nbuf is printing the right bytes amount, I removed the print statement before I 
made the first post.

So to clarify, I added a print statement between the first recv and the second.

{msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 1.0, data: {1: igb0, 
2: igb1, ifcnt: 2}}
connected to misty:8080
sending data
138 bytes sent: 0x86{msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 1.0, data: {1: 
igb0, 2: igb1, ifcnt: 2}}
receiving data
message length is 188
0 bytes received:

So the subsequent recv() call will be readjusted with 188 bytes buffer size so 
theoretically, recv shouldn't return 0.

The same logic that I used to send to the server from the python client that 
the server will readjust the second recv() call based on the length 
information. On this 2nd recv() call the server is able to obtain the rest of 
the messages.



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


Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote:
 I probably wouldn't make it fixed length. I'd have the length in
 decimal followed by, say, \n.

Or even followed by any non-digit. Chances are your JSON data begins
with a non-digit, so you'd just have to insert a space in the event
that you're JSON-encoding a flat integer. (Which might not ever
happen, if you know that your data will always be an object.)

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


Re: Python recv loop

2013-02-11 Thread Dave Angel

On 02/11/2013 10:02 AM, Ihsan Junaidi Ibrahim wrote:


  snip

 print 'message length is {0}'.format(nbuf)

 while True:
 buf = sock.recv(nbuf)

 if not buf:
 break


This loop doesn't terminate till buf is zero length, which it will be 
eventually.  At that point, you've overwritten the real data you may 
have gotten.  So the loop is just plain wrong.


Uwe MRAB's code, since there's no promise that all the data will be 
returned in a single call.  Keep accumulating it as you loop.





 slen = len(buf)
 str = {0} bytes received: {1}.format(slen, buf)
 print str
 return 0





--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


imp.load_module error in Python 3.3

2013-02-11 Thread Iuri
I want to load a file with an invalid module name (with a dash).

filename = '...' # something like /my/path/to/ejtp-crypto
with open(filename, 'rb') as fp:
my_module = imp.load_module('crypto', fp, 'ejtp-crypto', ('.py',
'rb', imp.PY_SOURCE))

It works to all Python = 2.5, except 3.3. Some behaviour changed to break
it or is it a regression bug?

I know imp.load_module is deprecated in 3.3, but I didn't found anything
related with behaviour changes.

Also, I didn't understanded how exactly change my code to use importlib,
can you help me with this change?

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


Compiling Python with static runtime library (VS2010)

2013-02-11 Thread Jonatan Magnusson


Hi

I'm trying to build Python 3.3.0 on Windows using Visual Studio 2010 Express.

I opened the solution (pcbuild.sln) and built the python project (including 
its dependencies of course) and that worked fine with just a few warnings.

But I need to build Python using the the static C runtime so I followed the 
instructions:

 * Changed Runtime Library to non-DLL variant (/MT or /MTd) for each of the 
projects (make_buildinfo, make_versioninfo, kill_python, python core, w9xpopen 
and python)
 * Changed preprocessor macro Py_ENABLED_SHARED to Py_NO_ENABLE_SHARED in the 
pythoncore project
 * Changed configuration type from Dynamic Library to Static library for the 
pythoncore project

Then I recompiled and once again it built with just a few warnings, until the 
link stage where __imp__Py_Main was unresolved!

Is it no longer supported to build against the static runtime libraries or am I 
doing something wrong?


Regards,
Jonatan Magnusson

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


PyDev, pep8.py conflict on spaces around negative numbers

2013-02-11 Thread Wanderer
If I check the 'Use space before and after operators? (+, -, /, *, //, **, 
etc.)' in the EclipsePyDevEditorCode Style Code Formatter, PyDev will 
insert a space before a negative number in a keyword parameter declaration. 
Pep8.py will then post a warning 'E251 no spaces around keyword / parameter 
equals'.

For example:
foo(bar= -25)

So which is right? Should there be a space before a negative number?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Serhiy Storchaka

On 11.02.13 09:24, Chris Angelico wrote:

Can I get a ringside seat at the debate between Rick and jmf on which
kind of string theory was the wronger decision?


I want to see it.

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


Re: PyDev, pep8.py conflict on spaces around negative numbers

2013-02-11 Thread MRAB

On 2013-02-11 16:39, Wanderer wrote:

If I check the 'Use space before and after operators? (+, -, /, *,
//, **, etc.)' in the EclipsePyDevEditorCode Style Code
Formatter, PyDev will insert a space before a negative number in a
keyword parameter declaration. Pep8.py will then post a warning 'E251
no spaces around keyword / parameter equals'.

For example:
foo(bar= -25)

So which is right? Should there be a space before a negative number?


Pep8.py is right.

This is preferred:

foo(bar=-25)

as is this:

bar = -25
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Namespace asinitiy and the folly of the global statement

2013-02-11 Thread Jason Swails
On Mon, Feb 11, 2013 at 1:27 AM, Chris Angelico ros...@gmail.com wrote:

 On Mon, Feb 11, 2013 at 1:42 PM, alex23 wuwe...@gmail.com wrote:
  On Feb 9, 2:25 pm, Michael Torrie torr...@gmail.com wrote:
  Rick seems to know his stuff
  about Tk programming, but his knowledge of programming language theory
  and formal computing seems quite informal.
 
  Not informal, intuited. If he doesn't already know something, it's
  apparently not important.

 I wonder how he learned about Tk. To be quite frank, I've not found
 tkinter to be particularly intuitive, and I've been doing GUI
 programming since the early 90s (with a wide variety of toolkits).


Perhaps that's your problem ;).  Tkinter was the first--and only--GUI
toolkit I learned [1] (I do almost exclusively CLI, and GUI only for fun --
and I program as a result of the work I do).  Having no previous knowledge
of any other GUI toolkit (and really only writing 2 or 3 _real_ GUIs
total), it wasn't hard to pick up enough from effbot/stackoverflow/tkinter
documentation to get a working GUI with (what I think is) decent code
organization.

Just my personal experience.

--Jason

[1] Tkinter is part of the stdlib, and I try to minimize external
dependencies
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyDev, pep8.py conflict on spaces around negative numbers

2013-02-11 Thread Wanderer
On Monday, February 11, 2013 1:09:38 PM UTC-5, MRAB wrote:
 On 2013-02-11 16:39, Wanderer wrote:
 
  If I check the 'Use space before and after operators? (+, -, /, *,
 
  //, **, etc.)' in the EclipsePyDevEditorCode Style Code
 
  Formatter, PyDev will insert a space before a negative number in a
 
  keyword parameter declaration. Pep8.py will then post a warning 'E251
 
  no spaces around keyword / parameter equals'.
 
 
 
  For example:
 
  foo(bar= -25)
 
 
 
  So which is right? Should there be a space before a negative number?
 
 
 
 Pep8.py is right.
 
 
 
 This is preferred:
 
 
 
  foo(bar=-25)
 
 
 
 as is this:
 
 
 
  bar = -25

Then, I guess I'll uncheck the 'Use space before and after operators' in PyDev.

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


Re: PyWart: Namespace asinitiy and the folly of the global statement

2013-02-11 Thread Michael Torrie
On 02/11/2013 11:32 AM, Jason Swails wrote:
 
 Perhaps that's your problem ;).  Tkinter was the first--and only--GUI
 toolkit I learned [1] (I do almost exclusively CLI, and GUI only for fun --
 and I program as a result of the work I do).  Having no previous knowledge
 of any other GUI toolkit (and really only writing 2 or 3 _real_ GUIs
 total), it wasn't hard to pick up enough from effbot/stackoverflow/tkinter
 documentation to get a working GUI with (what I think is) decent code
 organization.
 
 Just my personal experience.

My first experience with GUI programming was with MFC on windows.  Yuck!
 Anything is better.  Although wxWidgets seems to follow the MFC model
in some ways, and that has always left a sour taste in my mouth.

Since then I've done both GTK and Qt programming and both are a
pleasure, especially in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Namespace asinitiy and the folly of the global statement

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 6:15 AM, Michael Torrie torr...@gmail.com wrote:
 On 02/11/2013 11:32 AM, Jason Swails wrote:

 Perhaps that's your problem ;).  Tkinter was the first--and only--GUI
 toolkit I learned [1] (I do almost exclusively CLI, and GUI only for fun --
 and I program as a result of the work I do).  Having no previous knowledge
 of any other GUI toolkit (and really only writing 2 or 3 _real_ GUIs
 total), it wasn't hard to pick up enough from effbot/stackoverflow/tkinter
 documentation to get a working GUI with (what I think is) decent code
 organization.

 Just my personal experience.

 My first experience with GUI programming was with MFC on windows.  Yuck!
  Anything is better.  Although wxWidgets seems to follow the MFC model
 in some ways, and that has always left a sour taste in my mouth.

 Since then I've done both GTK and Qt programming and both are a
 pleasure, especially in Python.

Lately I've done all my GUI work with GTK, and it's worked out nicely
for me. But I still assume that it'll take as long to learn as the
language I'm using - which, for good languages like Python, isn't all
that long, but it's not like mastering urllib.

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


Re: How to Send a Tweet from Python? I can read, but not post.

2013-02-11 Thread Steven D'Aprano
saqib.ali...@gmail.com wrote:

 I posted this on StackOverflow.com but haven't got a good response yet:
 http://stackoverflow.com/questions/14808245/python-why-cant-i-send-a-tweet
 
 
 
 I have tried two different packages python-twitter and tweepy but have not
 been successful using either package. Those solutions are discussed here:
 
 Twitter API: simple status update (Python) How to tweet from Django?

These are not URLs. 

Your question is very specialised. If you don't get a response in a day or
so, you may have better luck asking on a dedicated python-twitter or tweepy
forum, or if those projects are too small to have a dedicated forum, by
asking the creator of the packages for assistance.

If you do get an answer somewhere else, please reply here with the solution
to help future developers who are searching for an answer to the same
question.

Thank you.


-- 
Steven

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


Re: Monitoring updating directory for image for GUI

2013-02-11 Thread ciscorucinski
WOW...I am thinking that all of this was actually unnecessary, I don't think I 
need a Queue, or List / Stack, or any traversal of the file system to 
accomplish this!!

I only need one image displayed at a time and don't care about them after a 
newer image is generated. So my prototype of just replacing the image over and 
over again SHOULD suffice. All I need the for the monitor now is to grab the 
image file (that might have or might not have been updated by Lilypond) at set 
amount of times and refresh the GtkImage object.

The only reason why I originally suggested using multiple files was because I 
wanted to make sure that I had to most recent image and I was not sure if the 
threads would guarantee that. So my only remaining question (for now) is...

I'm I guaranteed that if I have threads 1...n, that were all started in 
**quick** succession to call an OS command on Lilypond, that if I replaced the 
image file being generated with the completion of each thread that I would end 
up with the final image being from thread n...and that if I were able to update 
the GUI in a fast enough fashion, that I would see the images being displayed 
on the screen from 1 to n without anything being out of place?

All of my tests have shown that seems to be a reasonable assumption, but I need 
to know for sure. If that was the case were I am not guaranteed that, then when 
a user decides to stop the stream I could resend the note stream that I have 
saved on my end to Lilypond one last time to guarantee that all of the notes 
are displayed.


So I would only create one image location at images\sheetMusic.png and that 
file would be continuously updated as new notes are streamed in. My monitor 
class (might be a legacy component now) would basically look for that one image 
- images\sheetMusic.png, grab it, and update the GUI at an interval that is 
easy on the eyes (maybe a half second for example).

Could there be a problem where the image is being updated, so the OS deletes 
the image, and my program tries to update the image but cannot find it, and the 
OS reassigns that file location to that previous file location and name?

Let me know what you thing or if anything is confusing you.
Thanks for the comments so far!

 - Christopher - 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python programming language?

2013-02-11 Thread Dan Stromberg
Sent from my android phone.
On Feb 9, 2013 6:41 PM, Terry Reedy tjre...@udel.edu wrote:

 On 2/9/2013 6:53 PM, Michael Torrie wrote:

 On 02/09/2013 04:26 PM, Tim Roberts wrote:

 Most people would call bash a scripting language, but it is also
clearly
 a programming language.  It has syntax, variables and expressions.  I
 suspect it is Turing-complete, although I haven't seen a proof of that.

 I would assert that scripting languages are a proper subset of
programming
 languages, not a separate category.


 I'm pretty sure Bash is turing complete.  I know it's been shown that
 sed is turing complete, and awk probably is too!  If I recall, the way
 to show a language is turing complete is to implement a turing machine


 If the language has arrays, conditional execution, and explicit (while)
loops or recursion, you can be pretty sure it is Turing complete. I presume
this covers awk and bash. Something like the game of Life, where the
looping in implicit in the operation, is much harder to show Turing
complete. I suspect sed is non-trivial also.

http://en.m.wikipedia.org/wiki/Turing_completeness

For proving something Turing-complete, you only need to prove equivalence
to some other Turing-complete language.

The simplest test involves three things:
1. Sequential flow
2. An if, while or recursive function/method call
3. An arbitrary number of variables - arrays are optional

Strictly speaking, no language on a real computer is fully Turing-complete,
because real computers don't have an infinitely large memory, while TM's do.

But it's common to handwaive past that part of the definition.

 Terry Jan Reedy

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


Re: Monitoring updating directory for image for GUI

2013-02-11 Thread MRAB

On 2013-02-11 22:50, ciscorucin...@gmail.com wrote:
[snip]


So I would only create one image location at images\sheetMusic.png
and that file would be continuously updated as new notes are streamed
in. My monitor class (might be a legacy component now) would
basically look for that one image - images\sheetMusic.png, grab it,
and update the GUI at an interval that is easy on the eyes (maybe a
half second for example).

Could there be a problem where the image is being updated, so the OS
deletes the image, and my program tries to update the image but
cannot find it, and the OS reassigns that file location to that
previous file location and name?


[snip]
You could create the image under one name and then copy or move/rename
it for display.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 curses behavior

2013-02-11 Thread Dan Stromberg
Sent from my android phone.
On Feb 10, 2013 2:09 PM, Vlasov Vitaly vnig...@gmail.com wrote:

 суббота, 9 февраля 2013 г., 23:22:47 UTC+4 пользователь Terry Reedy
написал:
  On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:

  --
 
  Terry Jan Reedy

 Thank you.

 I tried everything in my test script.
 win.leaveok() - no effect
 curses.cur_vis() - no effect
 win.scrollok() - start newline and place cursor on it

 It's only one last option:
 on last line last char try/except with pass.

I doubt this is a Python 2 or Python 3 problem; historically some terminal
types curses supports could not fill the lower right-most character cell
without causing an undesired scroll of the screen by one line.  So portable
curses programs avoid filling that spot with anything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread 88888 Dihedral
Rick Johnson於 2013年2月11日星期一UTC+8下午9時13分58秒寫道:
 On Monday, February 11, 2013 6:40:23 AM UTC-6, Chris Angelico wrote:
 
  [...]
 
  Or doing what you were pointing and laughing at Pike for, and using
 
  two-symbol delimiters. You could even make it majorly logical:
 
  
 
  list_ = [[ 1, 2, 3 ]]
 
  tuple_ = ([ 1, 2, 3 ])
 
  dict_ = [{ 1, 2, 3 }]
 
  frozendict_ = ({ 1, 2, 3 })
 
  set_ = [ 1, 2, 3 ]
 
  frozenset_ = ( 1, 2, 3 )
 
 
 
 I am vehemently against using more than one opening seq char and one 
 closing seq char. It works fine for single depth sequences, however, once 
 you start nesting the mental focus required to parse the doubled 
 openers/closers is headache inducing. I would accept wrapping the literal in 
 some sort of declaration though, something like i proposed earlier in the 
 thread. The easiest is to use:
 
 
 
   set({1,2,3})
 
 
 
 but that looks like a function call! So we'd need a unique syntax. Either a 
 single tag like:
 
 
 
   set{1,2,3}
 
 
 
 Or we could use start and end tags like:
 
 
 
   set{1,2,3}set
 
 
 
 where set{ and }set are delimiters. For lists, tuples, and dict we would 
 use the short form because these literals are far too ubiquitous:
 
 
 
   [1,2,3] # list
 
   {k:v} # dict
 
   (1,2,3) # tuple
 
 
 
 However, the grouping chars for tuples has always been confusing because they 
 can clash with grouping of expressions. What is this?
 
 
 
   (1)
 
 
 
 It's NOT a tuple! But it looks like a tuple! What is this:
 
 
 
   1,2
 
 
 
 it IS a tuple, but it does not look like a tuple! 
 
 
 
 That's an unfortunate side effect of a poorly thought-out tuple syntax.

I am thinking a mutated list temporarily is useful when a list is to be used 
to be iterated through all of its elements efficiently.

A permanently mutated list is a tuple of constant objects.

As for the set type, I prefer to use the operations of the list,
dictionaries in Python to act for the designed purposes. 

 





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


Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim

On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote:

 On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote:
 I probably wouldn't make it fixed length. I'd have the length in
 decimal followed by, say, \n.
 
 Or even followed by any non-digit. Chances are your JSON data begins
 with a non-digit, so you'd just have to insert a space in the event
 that you're JSON-encoding a flat integer. (Which might not ever
 happen, if you know that your data will always be an object.)
 
 ChrisA

So on the first recv() call, I set the buffer at 1 character and I iterate over 
single character until a non-digit character
is encountered?



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


Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim ih...@grep.my wrote:

 On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote:

 On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote:
 I probably wouldn't make it fixed length. I'd have the length in
 decimal followed by, say, \n.

 Or even followed by any non-digit. Chances are your JSON data begins
 with a non-digit, so you'd just have to insert a space in the event
 that you're JSON-encoding a flat integer. (Which might not ever
 happen, if you know that your data will always be an object.)

 ChrisA

 So on the first recv() call, I set the buffer at 1 character and I iterate 
 over single character until a non-digit character
 is encountered?

More efficient would be to guess that it'll be, say, 10 bytes, and
then retain any excess for your JSON read loop. But you'd need to sort
that out between the halves of your code.

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


Re: Python recv loop

2013-02-11 Thread Roy Smith
In article mailman.1655.1360594595.2939.python-l...@python.org,
 Ihsan Junaidi Ibrahim ih...@grep.my wrote:

 I'm running JSON for my application messaging protocol but with JSON and 
 python default unordered dict,
 there's no guarantee if I put in the length key in the JSON message, it will 
 be placed on the first bytes hence
 why it was designed for a fixed 4-byte at the start of the message to 
 indicate the message length.
 
 Beyond the 4-bytes it is all JSON.

I'm confused.  It sounds like you're making things way more complicated 
than they have to be.  Can you give us an example of an actual data 
message?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import redirects

2013-02-11 Thread Isaac To
On Mon, Feb 11, 2013 at 8:27 PM, Oscar Benjamin
oscar.j.benja...@gmail.comwrote:

 On 11 February 2013 06:50, Isaac To isaac...@gmail.com wrote:
  Except one thing: it doesn't really work.  If I `import foo.baz.mymod`
 now,
  and if in bar.baz.mymod there is a statement `import bar.baz.depmod`,
 then
  it fails.  It correctly load the file bar/baz/depmod.py, and it assigns
  the resulting module to the package object bar.baz as the depmod
 variable.
  But it fails to assign the module object of mymod into the bar.baz
  module.  So after `import foo.baz.mymod`, `foo.baz.mymod` results in an
  AttributeError saying 'module' object has no attribute 'mymod'.  The
 natural
  `import bar.baz.mymod` is not affected.

 My guess is that you have two copies of the module object bar.baz with
 one under the name foo.baz and the other under the name bar.baz. mymod
 is inserted at bar.baz but not at foo.baz. I think a solution in this
 case would be to have your foo/__init__.py also import the subpackage
 'bar.baz' and give it both names in sys.modules:

 import bar.baz
 sys.modules['foo.baz'] = bar.baz


Thanks for the suggestion.  It is indeed attractive if I need only to
pre-import all the subpackage and not to redirect individual modules.  On
the other hand, when I actually try this I found that it doesn't really
work as intended.  What I actually wrote is, as foo/__init__.py:

import sys
import bar
import bar.baz
sys.modules['foo.baz'] = bar.baz
sys.modules['foo'] = bar

One funny effect I get is this:

 import bar.baz.mymod
 bar.baz.mymod
module 'bar.baz.mymod' from 'bar/baz/mymod.pyc'
 import foo.baz.mymod
 bar.baz.mymod
module 'foo.baz.mymod' from 'bar/baz/mymod.pyc'

By importing foo.baz.mymod, I change the name of the module from
bar.baz.mymod to foo.baz.mymod.  If that is not bad enough, I also see
this:

 import bar.baz.mymod as bbm
 import foo.baz.mymod as fbm
 bbm is fbm
False

Both effects are there even if bar/baz/mymod.py no longer `import
bar.baz.depmod`.

It looks to me that package imports are so magical that I shouldn't do
anything funny to it, as anything that seems to work might bite me a few
minutes later.

Regards,
Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python recv loop

2013-02-11 Thread MRAB

On 2013-02-12 02:20, Chris Angelico wrote:

On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim ih...@grep.my wrote:


On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote:


On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote:

I probably wouldn't make it fixed length. I'd have the length in
decimal followed by, say, \n.


Or even followed by any non-digit. Chances are your JSON data begins
with a non-digit, so you'd just have to insert a space in the event
that you're JSON-encoding a flat integer. (Which might not ever
happen, if you know that your data will always be an object.)

ChrisA


So on the first recv() call, I set the buffer at 1 character and I iterate

 over single character until a non-digit character is encountered?


More efficient would be to guess that it'll be, say, 10 bytes, and
then retain any excess for your JSON read loop. But you'd need to sort
that out between the halves of your code.


If the length is always followed by a space then it's easier to split
it off the input:

buf = sock.recv(10)
space_pos = buf.find(b )
nbuf = int(buf[ : space_pos])
buf = buf[space_pos+ 1 : ]

while len(buf)  nbuf:
chunk = sock.recv(nbuf - len(buf))
if not chunk:
break

buf += chunk

I'm assuming that:

1. The initial recv returns the length followed by a space. It could,
of course, return fewer bytes (space_pos == -1), so you may need to
recv some more bytes, like what's done later on.

2. At least 10 bytes were sent. Imagine what would happen if the sender
sent b2 [] immediately followed by b2 []. The initial recv could
return all of it. In that case you could save the excess until next
time. Alternatively, the sender could guarantee that it would never
send fewer than the 10 bytes, padding with several b  if necessary.

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


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 7:35:23 AM UTC-6, Chris Angelico wrote:
 On Tue, Feb 12, 2013 at 12:13 AM, Rick Johnson wrote:
  I am vehemently against using more than one opening seq char and one 
  closing seq char. ... we could use start and end tags like:
 
set{1,2,3}set
 
  where set{ and }set are delimiters.
 
 Interesting. So what you're actually against is the symbols. 

Nothing really. Chars are innocent creatures. They themselves know not of evil. 
However groups of chars have the capacity to collectively emit evil in the form 
of density, of which who's demon spawn is incomprehensibility!

 Okay. I
 have a bit of a Scheme (rubs hands together with glee) for you. 
 [snip lisping]
 
 (set 1 2 3)
 (dict 1 2 3 4)   ; implicitly pairs up the arguments
 (tuple 1 2)
 (list 1 2 3 4); This seems like a real good idea.

Well i must admit that this syntax would be beautifully consistent--except for 
the dict which is far too implicit! I would gravitate to something more like:

(dict 'a':1 'b':2 'name':'fred')

But what happens when we start nesting?

(dict: 
'employees':
(list 
'sarah:(dict 
'age':22,
'position:'CSR'),
'john':(dict 
'age':46,
'position':'grounds'),
'albert':(dict 
'age':85,
'position':'CEO'),
), # end list
'key1':(tuple 1,2,10.1),
'key2':(set 10,20,30),
) # end dict

As opposed to:

{
'employees':[
'sarah:{
'age':22,
'position:'CSR'},
'john':{
'age':46,
'position':'grounds'},
'albert':{
'age':85,
'position':'CEO'},
],
'key1':(1,2,10.1),
'key2':set([10,20,30]),
}

But then again, literals are code smell anyway!

  http://en.wikipedia.org/wiki/Code_smell
  
I use literals like anyone else, but i sometimes wonder if i could live without 
them (probably not string literals though!!!). Many of us can even remember a 
day (before we learned about recursion) when we would write out gobs and gobs 
of unnecessary literals that could easily be built with a for loop. I think 
_most_ literals could just as easily be replicated in code. Consider this 
alternative approach to building the the dict above:

database = d = {}
d['sarah'] = k = {}
k['age'] = 22
k['position'] = 'CSR'
d['john'] = k = {}
k['age'] = 46
k['position'] = 'grounds'
d['albert'] = k = {}
k['age'] = 85
k['position'] = 'CEO'
d['key1'] = (1,2,10.1)
d['key2'] = [10,20,30]

Not as structured as the literal, but by utilizing indention the message will 
become clearer. Oh, yeah, better make sure we built that structure correctly!

py import pprint
py pprint.pprint(d)
{'albert': {'age': 85, 'position': 'CEO'},
 'john': {'age': 46, 'position': 'grounds'},
 'key1': (1, 2, 10.1),
 'key2': [10, 20, 30],
 'sarah': {'age': 22, 'position': 'CSR'}}

But then the old for x in LITERAL_SEQ and the if this in LITERAL_SEQ will 
bite you. Damn literals! Can't live with them, can't live without them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 7:52:24 AM UTC-6, Chris Angelico wrote:
 [...]
 But my statement wasn't based on my own knowledge of the stdlib, but
 rather on this:
 
 On Sat, Feb 9, 2013 at 6:58 AM, Rick Johnson wrote:
  I'm a bit unnerved by the sum function. Summing a
  sequence only makes sense if the sequence in question
  contains /only/ numeric types. For that reason i decided
  to create a special type for holding Numerics.
 
 Why create a special type if it already exists?

Because at the time i made this statement we were discussing 100% true OOP (you 
know, the kind of paradigm where object definition identifiers start with a 
capital letter? *estoeric-wink*), but more importantly because i don't find the 
current implementation of array and list to be consistent.

 Yep. By the way, how does the help function fit into your wonderfully
 OOP model? What's it a method on?

Well since /all/ objects will have help available it should be defined 
Object#help and then propagate downwards. But even true OOP languages need a 
few global functions... *gasp*... oh yes! A few that come to mind include:

 globals, locals, vars, compile, eval, exec, input, print, dir
 
And don't forget, we still have module namespace to deal with!
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 7:27:30 AM UTC-6, Chris Angelico wrote:

 So...
 flatten([None, 23, [1, 2, 3], (2, 3), [spam, ham]])
 
 would return
 
 [None, 23, 1, 2, 3, (2, 3), spam, ham]
 
 I think that's even more unexpected.

Why? Are you over-analyzing? Show me a result that /does/ make you happy. 

Do you remember when i was talking about how i attempt to intuit interfaces 
before reading any docs? Well i have news for you Chris, what you are doing is 
NOT intuiting how flatten will work, what you are doing is projecting how 
flatten will work; these are two completely different concepts Chris.

The word flatten is too ambiguous to intuit the /exact/ result. The only 
intuit-able attribute of flatten is that calling list.flatten() will result in 
a list that probably looks different than the current list. Intuition is your 
friend; not your own personal clairvoyant side-kick!

To learn the interface you need to initially intuit, but then you need to 
test. Run a few example sequences and see what results you get, compare those 
results to what you /expected/ to get. If it works the way you expect, move on 
to the next topic, if not, dig deeper. 

You can't procrastinate over this method forever because NEWSFLASH you will 
/never/ find a perfect flatten algorithm that will please /everyone/, so just 
pick the most logical and consistent, and MOVE ON! 

Infinite recursion anyone?

while obj.repeat is True:
   obj.lather()
   obj.rinse()
   obj.repeat = True
   
   
-- 
http://mail.python.org/mailman/listinfo/python-list


how to call shell?

2013-02-11 Thread contro opinion
 import os
 os.system(i=3)
0
 os.system(echo $i)

0

why i can't get the value of i ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Mark Janssen
On Fri, Feb 8, 2013 at 9:48 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 On Friday, February 8, 2013 9:16:42 AM UTC-6, Steven D'Aprano wrote:
 Rick Johnson wrote:
 Just because /everything/ in Python is an object does not mean that Python is 
 100% OOP.

The whole idea of make everything an object is possibly a misguided
sense of puritanism anyway.   I wouldn't harp on that point to much.
But I really like your other developments.  Like the following

 If so, Python would have a supertype called Collection that wold define all 
 methods that operate on collections. Some of these include:

  len, any, all, length, isempty, __getitem__, __setitem__, etc...

I think this is a great idea and fixes a language wart which put
irrelevant methods into the builtin namespace.

 Then any collection subtype would inherit from this supertype and get the 
 methods for free.

Yes.  OOP encapsulation.  But I question whether strings should be
considered collections.  This is a spurious usage issue, not something
in an integrated object model (see below on what I mean).

 And a *really* smart language designer will have realised this ahead of
 time, and designed the language to encourage the use of protocols like
 this, instead of insisting on the slavish application of obj.method syntax.
 Using built-in functions to operate on objects is foolish because you are 
 placing extra burden on the programmer to know which /functions/ work with 
 which /types/. The *only* functions that should be global are the kind that 
 will work on *ANY* object. But then again, the Object type could hold these 
 methods!

Exactly.  This gets us closer to the real Python3000 that I've been
waiting for

 len, all, and any (just to name a few) only work for collections types and as 
 such should be methods of these types. The global functions:

   sum, len, any, all, enumerate, map, max, min, reversed, sorted, zip

 can only be applied to sequence types, or subtypes of a sequence type. So 
 using a /real/ OOP paridigm we would do the following:

 ## START TRUE OOP PARIDIGM ##
 [[snip]]

This is a great start, I think, but I think it's time to really
re-evaluate the whole data model again.  Before Python was trying to
have everything, and have the flexibility to adapt for everyone, but
sometimes I think there's too much flexibility  and options and it
leads to sloppiness.  I would argue it's time for a refactor and
re-think the object model.

 class Object(SuperType):
 def dir
 def help
 def id
 def isinstance?(Type)
 def issubclass?(Type)
 def super
 def type

I like the general line-of-thought, but some of these are
questionable.  I think it's essential to have help() outside any class
-- the built-in, global methods serve an important purpose of setting
the culture for a language, and help, (and my proposed test()) builtin
are part of (or would be) the community.

 class SequenceBase(Object):
 def sum
 def filter(proc)
 def map
 def max
 def min
 def reverse
 def reduce(proc)

Here again, you see how the early python community put these in the
global namespace because of the bias that they had such (admittedly()
cool builtin collection types in the language.  But now, it's
interesting to reconsider these ideas.

 ## END TRUE OOP PARIDIGM ##

 You see, 100% OOP uses encapsulation, inheritance, sub-typing, etc, etc... 
 But most fundamental to OOP is interface (methods belonging to objects), not 
 global functions applied to objects in some haphazard fashion that some 
 self-appointed dictator pull from his backside due to his fear of true OOP 
 style!

That's not quite fair to the BDFL; you're criticizing the community
that made Python great.  That, of course, doesn't mean that it's still
logical to keep them out there in the global scope, exposed for all to
see.

 Python is not 100% OOP. Heck you cannot fairly apply a specific percentage 
 level because Python's level of OOP is defined by each user of the language. 
 The best way to describe Python is as promiscuous language who secretly longs 
 to be 100% OOP, and to fulfill this fantasy it cross-dresses in OOP lingerie 
 on the weekends.

That's a funny quote, besides its questionable accuracy, but your
initial sentences point out that having a unified data model might
actually be of use.  A unified data model does for data what lexical
definitions and parsers do for code:  organize it in a well-defined
way that is a *complete* specification for all possible data
organizations.  (But see my other posts about that ;^)

Mark
Tacoma, Wa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LangWart: Method congestion from mutate multiplicty

2013-02-11 Thread Mark Janssen
On Mon, Feb 11, 2013 at 8:55 PM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 On Monday, February 11, 2013 7:27:30 AM UTC-6, Chris Angelico wrote:

 So...
 flatten([None, 23, [1, 2, 3], (2, 3), [spam, ham]])

 would return

 [None, 23, 1, 2, 3, (2, 3), spam, ham]

 I think that's even more unexpected.

 Why? Are you over-analyzing? Show me a result that /does/ make you happy.

 Do you remember when i was talking about how i attempt to intuit interfaces 
 before reading any docs? Well i have news for you Chris, what you are doing 
 is NOT intuiting how flatten will work, what you are doing is projecting 
 how flatten will work; these are two completely different concepts Chris.

 You can't procrastinate over this method forever because NEWSFLASH you will 
 /never/ find a perfect flatten algorithm that will please /everyone/, so just 
 pick the most logical and consistent, and MOVE ON!

Yeah, this is where one has to consider the idea of a unified data
model (a sort of OOPv2).  Right now, it's all confused because people
are using their own internal, subconscious ideas of data.  There are
natural ways of working with data that ***actually map onto the world
we all share*** and there are other ways which are purely abstract and
not-pragmatic however pure.   (Apart from this, there is the
ultra-concrete data model, like C, which only maps onto the machine
architecture).  This is where pretty much every computer language is
today.

What I'm suggesting I think is somewhat novel.  The first version of
OOP was too concrete in the sense that it was actually trying to make
real-world objects in the machine (class Chevy(Car):).  This is
ridiculous.  There needs to be a refactor of the OOP paradigm.  In
practice OOP never was used to represent real-world objects.  It came
to model virtual world objects, a very different world with different
relationships.  It became the evolution of the data type itself.  The
unified object model needs to do for OOP what arithmetic did for
number:  defined a very basic and general set of operations on the
concept of quantificiation.  But here were trying to do that not for
quantification but for structures.

My suggestion is to create the fractal graph data type to end (and
represent) all data types.  (Keep all the special, high-speed matrix
ideas in SciPi/VPython.)  But generally, re-arrange the data model
around the fractal graph for efficiency and start watching the magic
happen.

markj
pangaia.sf.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: call shell from python

2013-02-11 Thread Chris Rebert
On Mon, Feb 11, 2013 at 9:13 PM, contro opinion contropin...@gmail.com wrote:
 import os
 os.system(i=3)
 0
 os.system(echo $i)

 0
 how can i get the value of  i?

Your example is too heavily contrived for me to give a much more
specific/useful answer than use the `subprocess` module:
http://docs.python.org/2/library/subprocess.html#using-the-subprocess-module

Of course, if all you want to do is manipulate environment variables,
then there's `os.environ`:
http://docs.python.org/2/library/os.html#os.environ

Good luck, my pseudonymous contrarian compadre.
– Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to call shell?

2013-02-11 Thread Tim Roberts
contro opinion contropin...@gmail.com wrote:

 import os
 os.system(i=3)
0
 os.system(echo $i)

0

why i can't get the value of i ?

Each invocation of os.system creates a brand new shell that starts, runs,
and terminates.  Your first command adds a variable i to the environment
for that shell, but the variable is deleted when the shell procsess
terminates.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral
dihedral88...@googlemail.com wrote:
 A permanently mutated list is a tuple of constant objects.

I nominate this line as bemusing head-scratcher of the week.

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


Awsome Python - chained exceptions

2013-02-11 Thread Steven D'Aprano
As an antidote to the ill-informed negativity of Ranting Rick's 
illusionary PyWarts, I thought I'd present a few of Python's more 
awesome features, starting with exception contexts.

If you've ever written an exception handler, you've probably written a 
*buggy* exception handler:


def getitem(items, index):
# One-based indexing.
try:
return items[index-1]
except IndexError:
print (Item at index %d is missing % index - 1)  # Oops!


Unfortunately, when an exception occurs inside an except or finally 
block, the second exception masks the first, and the reason for the 
original exception is lost:

py getitem(['one', 'two', 'three'], 5)  # Python 2.6
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 6, in getitem
TypeError: unsupported operand type(s) for -: 'str' and 'int'


But never fear! In Python 3.1 and better, Python now shows you the full 
chain of multiple exceptions, and exceptions grow two new special 
attributes: __cause__ and __context__.

If an exception occurs while handling another exception, Python sets the 
exception's __context__ and displays an extended error message:


py getitem(['one', 'two', 'three'], 5)  # Python 3.1
Traceback (most recent call last):
  File stdin, line 4, in getitem
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 6, in getitem
TypeError: unsupported operand type(s) for -: 'str' and 'int'



Python 3 also allows you to explicitly set the exception's __cause__ 
using raise...from syntax:

py try:
... len(None)
... except TypeError as e:
... raise ValueError('bad value') from e
... 
Traceback (most recent call last):
  File stdin, line 2, in module
TypeError: object of type 'NoneType' has no len()

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File stdin, line 4, in module
ValueError: bad value



Note the slight difference in error message. If both __cause__ and 
__context__ are set, the __cause__ takes priority.


Sometimes you actually want to deliberately catch one exception and raise 
another, without showing the first exception. A very common idiom in 
Python 2:


try:
do_work()
except SomeInternalError:
raise PublicError(error_message)


Starting with Python 3.3, there is now support from intentionally 
suppressing the __context__:


py try:
... len(None)
... except TypeError:
... raise ValueError('bad value') from None  # Python 3.3
... 
Traceback (most recent call last):
  File stdin, line 4, in module
ValueError: bad value



You can read more about exception chaining here:

http://www.python.org/dev/peps/pep-3134/
http://www.python.org/dev/peps/pep-0409/



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue16997] subtests

2013-02-11 Thread holger krekel

holger krekel added the comment:

On Sun, Feb 10, 2013 at 12:41 PM, Antoine Pitrou rep...@bugs.python.orgwrote:


 Antoine Pitrou added the comment:

  Please don't commit I think we still need a discussion as to whether
  subtests or paramaterized tests are a better approach. I certainly
  don't think we need both and there are a lot of people asking for
  parameterized tests.

 I think they don't cater to the same crowd. I see parameterized tests as
 primarily used by people who like adding formal complexity to their
 tests in the name of architectural elegance (decorators, non-intuitive
 constructs and other additional boilerplate). Subtests are meant to not
 get in the way. IMHO, this makes them more suitable for stdlib
 inclusion, while the testing-in-python people can still rely on their
 additional frameworks.


Parametrized testing wasn't introduced because I or others like formal
complexity.  I invented the yield syntax that both pytest and nose still
support and it was enhanced for several years until it was deemed not fit
for a general purpose testing approach.  More specifically, if you have
functional parametrized tests, they each run relatively slow.   People
often want to re-run a single failing test or otherwise select tests which
use a certain fixture, or send tests to different CPUs to speed up
execution.   That's all not possible with subtests or am i missing
something?

That being said, I have plans to support some form of subtests for pytest
as well, as there are indeed cases where a more lightweight approach fits
well, especially for unit- or integration tests where one doesn't care if a
group of tests need to be re-run when working on fixing a failure to a
single subtest.  And where it's usually more about reporting, getting nice
debuggable output on failures.  I suspect the cases which Antoine refers
satisfy this pattern.

best,
holger

--

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



[issue16997] subtests

2013-02-11 Thread holger krekel

holger krekel added the comment:

On Sun, Feb 10, 2013 at 12:43 PM, Nick Coghlan rep...@bugs.python.orgwrote:


 Nick Coghlan added the comment:

 You can use subtests to build parameterized tests, you can't use
 parameterized tests to build subtests.

I doubt you can implement parametrized tests via subtests especially for
functional testing and its fixture needs.

The standard library can also
 be converted to using subtests *far* more readily than it could be
 converted to parameterized tests.

I can see that and for this reason and the stdlib's use cases it might make
sense to support it.  The unittest module is also used in many other
contexts so it shouldn't be the only verification criterium.

best,
holger

--

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



[issue4591] 32-bits unsigned user/group identifier

2013-02-11 Thread Mark Dickinson

Mark Dickinson added the comment:

Hmm;  good point.  Well, +1 to the functionality, anyway;  I'll leave the 
discussion about the name.

--

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



[issue17179] TypeError: type() takes 1 or 3 arguments

2013-02-11 Thread Chris Withers

New submission from Chris Withers:

 from types import new_class
 from datetime import datetime
 new_class('tdatetime', (datetime, ), kwds={'foo':'bar'})
Traceback (most recent call last):
  File console, line 1, in module
  File /src/Python-3.3.0/Lib/types.py, line 52, in new_class
return meta(name, bases, ns, **kwds)
TypeError: type() takes 1 or 3 arguments

I'm guessing ns and kwds should be combined before being passed through to 
meta? (meta is 'type' in this case)

--
components: Library (Lib)
messages: 181884
nosy: cjw296
priority: normal
severity: normal
status: open
title: TypeError: type() takes 1 or 3 arguments
versions: Python 3.3

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



[issue17180] shutil copy* unsafe on POSIX - they preserve setuid/setgit bits

2013-02-11 Thread Milko Krachounov

New submission from Milko Krachounov:

When copying the mode of a file with copy, copy2, copymode, copystat or 
copytree, all permission bits are copied (including setuid and setgit), but the 
owner of the file is not. This can be used for privilege escalation.

An example:

-rwSr--r--  1 milko milko0 фев 11 10:53 test1

shutil.copy(test1, test2)

-rwSr--r--  1 root  root 0 фев 11 10:53 test2

If test1 contained anything malicious, now the user milko can execute his 
malicious payload as root.

Potential fixes:
- Strip setuid/setgid bits.
- Copy the owner on POSIX.
- Perform a safety check on the owner.
- Document the security risk.


The behaviour of copymode/copystat in this case is the same as `chmod 
--reference', and there can be some expectation of unsafety, but 
copy/copy2/copytree's behaviour differs from that of `cp -p', and this is a 
non-obvious difference.

--
components: Library (Lib)
messages: 181885
nosy: milko.krachounov
priority: normal
severity: normal
status: open
title: shutil copy* unsafe on POSIX - they preserve setuid/setgit bits
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2

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



[issue4591] 32-bits unsigned user/group identifier

2013-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There is a problem with test_pwd on 64-bit platform. It expects KeyError on 
pwd.getpwuid(sys.maxsize). Actually the test is not looks robust. On 32-bit 
platform sys.maxsize = 2**31-1  2**32 and this value only by chance was not in 
the user database. On 64-bit platform sys.maxsize  2**32 and in old code it 
was wrapped to 2**31-1 C unsigned int value and this value only by chance was 
not in the user database. New code doesn't wrap the value to C unsigned int and 
raises an overflow exception.

What should I change, a test or a raised exception?

--

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



[issue17159] Remove explicit type check from inspect.Signature.from_function()

2013-02-11 Thread Nick Coghlan

Nick Coghlan added the comment:

On Mon, Feb 11, 2013 at 11:46 AM, Terry J. Reedy rep...@bugs.python.org wrote:
 I am also puzzled by the 'from None' part in
 + raise TypeError('{!r}' is not a Python function.format(func)) from None

 While I remember that being in the pydev discussion and while raise XyzError 
 from None executes, it does not seems to be documented for 3.3 in 7.8. The 
 raise statement. (Should this be another issue?) In fact, that section says  
 if given, the second expression must be another exception class or instance, 
 which excludes None.

That's a separate docs bug - it seems we missed the necessary language
reference updates when implementing PEP 309. The relevant docs are
here: http://docs.python.org/3/library/exceptions.html#built-in-exceptions

--

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



[issue16997] subtests

2013-02-11 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 what if there are 500 subtests in a loop and you don't want 500 failures to be
 registered for that test case?

Parametered tests have the same issue. In this case you simply don't use 
subtests
or test cases. On the other hand, the issue doesn't exist in most cases where 
you
iterate over three or four different cases.

 addMessage was just one suggestion.

It is quite orthogonal, actually, and could be added independently. Also, it is 
not clear how you would limit the addMessage to a subtest, rather than the 
whole test case.
We could re-use testtools' addDetail idea, although their content-type thing
is a bit heavyweight: I'd rather duck-type the API.

http://testtools.readthedocs.org/en/latest/for-test-authors.html#details

--

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



[issue17181] SSLContext.set_servername_callback should be able to set argument

2013-02-11 Thread Daniel Black

New submission from Daniel Black:

I think my original implementation of the SNI callback to see a original 
sslcontext was wrong. It would be much more useful for the 
SSLContext.set_servername_callback to take a callable and an object as an 
argument.

This would allow constructs like the following where self can be used within 
the callback. Example:

def cb_sni(ssl_sock, server_name, self):
self.sniname = server_name

self.context.set_servername_callback(cb_sni, self)

The original functionality can still occur with:

self.context.set_servername_callback(cb_sni, self.context)

Agree?

--
components: Library (Lib)
messages: 181889
nosy: grooverdan, pitrou
priority: normal
severity: normal
status: open
title: SSLContext.set_servername_callback should be able to set argument
type: enhancement
versions: Python 3.5

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



[issue10852] SSL/TLS sni use in smtp, pop, imap, nntp, ftp client libs by default

2013-02-11 Thread Daniel Black

Daniel Black added the comment:

Ack. Have fix. Simple if self.certfile or self.keyfile: test added before 
load_cert_chain.

part way through developing test. Thinking #17181 would help.

--

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



[issue17052] unittest discovery should use self.testLoader

2013-02-11 Thread Michael Foord

Michael Foord added the comment:

I think you're right! Thanks.

--
assignee:  - michael.foord
resolution: fixed - 
status: closed - open

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



[issue17152] Array module should support boolean natively

2013-02-11 Thread Jesús Cea Avión

Jesús Cea Avión added the comment:

we have a -1, so I close this as rejected.

I still think it is a valuable idea to pursuit.

--
resolution:  - rejected
status: open - closed

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



[issue17152] Array module should support boolean natively

2013-02-11 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
stage:  - committed/rejected

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



[issue17044] Implement PEP 422: Simple class initialisation hook

2013-02-11 Thread Florent Xicluna

Changes by Florent Xicluna florent.xicl...@gmail.com:


--
nosy: +flox

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



[issue17052] unittest discovery should use self.testLoader

2013-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ece0a2e6b08e by Michael Foord in branch '2.7':
Correction to issue 17052 fix
http://hg.python.org/cpython/rev/ece0a2e6b08e

New changeset 867763eb6985 by Michael Foord in branch '3.2':
Correction to issue 17052 fix
http://hg.python.org/cpython/rev/867763eb6985

New changeset a79650aacb43 by Michael Foord in branch 'default':
Merge. Closes issue 17052.
http://hg.python.org/cpython/rev/a79650aacb43

--
resolution:  - fixed
stage: commit review - committed/rejected
status: open - closed

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



[issue17182] signal.default_int_handler should set signal number on the raised exception

2013-02-11 Thread Antoine Pitrou

New submission from Antoine Pitrou:

Having a dedicated optional attribute on KeyboardInterrupt receiving the signal 
number would be useful in certain circumstances, for example if you want to 
propagate the signal to a child process.

--
components: Extension Modules
messages: 181894
nosy: pitrou
priority: normal
severity: normal
status: open
title: signal.default_int_handler should set signal number on the raised 
exception
type: enhancement
versions: Python 3.4

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



[issue17063] assert_called_with could be more powerful if it allowed placeholders

2013-02-11 Thread Michael Foord

Michael Foord added the comment:

I still don't particularly like the idea of the assert_* methods returning 
something.

If the call args tuples had args and kwargs attributes, for which there are 
outstanding feature requests, then you could simply do:

my_mock(1, someobj(), bar=someotherobj())

foo = my_mock.call_args.args[1]
bar = my_mock.call_args.kwargs['bar']

By avoiding the extra step of tuple unpacking this is still nice and readable 
(IMO).

--

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



[issue17064] Fix sporadic buildbot failures for test_mailbox

2013-02-11 Thread R. David Murray

R. David Murray added the comment:

Thanks, Jeremy.

--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed
type:  - behavior
versions: +Python 2.7, Python 3.2 -Python 3.5

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



[issue17181] SSLContext.set_servername_callback should be able to set argument

2013-02-11 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 This would allow constructs like the following where self can be used
 within the callback. Example:
 
 def cb_sni(ssl_sock, server_name, self):
 self.sniname = server_name
 
 self.context.set_servername_callback(cb_sni, self)
 
 The original functionality can still occur with:
 
 self.context.set_servername_callback(cb_sni, self.context)

But you could simply use a closure:

def cb_sni(ssl_sock, server_name):
self.sniname = server_name

self.context.set_servername_callback(cb_sni)

--
title: SSLContext.set_servername_callback should be able to set argument - 
SSLContext.set_servername_callback should be able to setargument

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



[issue4591] 32-bits unsigned user/group identifier

2013-02-11 Thread Eric V. Smith

Eric V. Smith added the comment:

+1 for PyIndex_AsLong()

--
nosy: +eric.smith

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



[issue17064] Fix sporadic buildbot failures for test_mailbox

2013-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset bbeff2958cc5 by R David Murray in branch '3.2':
#17064: fix sporadic permission errors in test_mailbox on windows.
http://hg.python.org/cpython/rev/bbeff2958cc5

New changeset 3e3915cbfde3 by R David Murray in branch '3.3':
Merge: #17064: fix sporadic permission errors in test_mailbox on windows.
http://hg.python.org/cpython/rev/3e3915cbfde3

New changeset aa15df77e58f by R David Murray in branch 'default':
Merge: #17064: fix sporadic permission errors in test_mailbox on windows.
http://hg.python.org/cpython/rev/aa15df77e58f

New changeset 1c2dbed859ca by R David Murray in branch '2.7':
#17064: fix sporadic permission errors in test_mailbox on windows.
http://hg.python.org/cpython/rev/1c2dbed859ca

--
nosy: +python-dev

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



[issue9874] Message.attach() loses empty attachments

2013-02-11 Thread R. David Murray

R. David Murray added the comment:

Lacking a reproducer, there's not much we can do here, so closing.

--
resolution:  - works for me
stage: test needed - committed/rejected
status: open - closed

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



[issue17171] email.encoders.encode7or8bit does not work with binary data

2013-02-11 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
type:  - behavior

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



[issue15767] add ModuleNotFoundError

2013-02-11 Thread Barry A. Warsaw

Changes by Barry A. Warsaw ba...@python.org:


--
nosy: +barry

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



[issue15767] add ModuleNotFoundError

2013-02-11 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

For me, it mostly comes down to whether end-users are expected to see such 
errors generally or not.  We see ImportErrors all the time, and they are 
clearly errors.  If we're expected to see and deal with MNF, and if in such 
cases it's generally considered an error, then MNFError is better.  If it's 
mostly an internal/hidden thing, then MNF doesn't bother me.

--

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



[issue16935] unittest should understand SkipTest at import time during test discovery

2013-02-11 Thread Zachary Ware

Zachary Ware added the comment:

Sure can.  With a little luck, I'll have the patch ready later today; with less 
luck it'll be sometime later this week.

--

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



[issue17183] Small enhancements to Lib/_markupbase.py

2013-02-11 Thread Guido Reina

New submission from Guido Reina:

In the file: Lib/_markupbase.py, function: _parse_doctype_element there is:

if '' in rawdata[j:]:
return rawdata.find(, j) + 1

rawdata[j:] is being scanned twice.

It would be better to do:
pos = rawdata.find(, j)
if pos != -1:
return pos + 1


Same thing in the function: _parse_doctype_attlist:

if ) in rawdata[j:]:
j = rawdata.find(), j) + 1
else:
return -1

It would be better to do:
pos = rawdata.find(), j)
if pos != -1:
j = pos + 1
else:
return -1

--
messages: 181903
nosy: guido
priority: normal
severity: normal
status: open
title: Small enhancements to Lib/_markupbase.py
type: enhancement
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 
3.4, Python 3.5

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



[issue17183] Small enhancements to Lib/_markupbase.py

2013-02-11 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
assignee:  - ezio.melotti
components: +Library (Lib)
nosy: +ezio.melotti
stage:  - needs patch
versions:  -Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 
3.5

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



[issue17183] Small enhancements to Lib/_markupbase.py

2013-02-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 if '' in rawdata[j:]:
 return rawdata.find(, j) + 1

See issue17170 for this idiom.

--
nosy: +serhiy.storchaka

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



[issue17171] email.encoders.encode7or8bit does not work with binary data

2013-02-11 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f83581135ec4 by R David Murray in branch '3.2':
#17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/f83581135ec4

New changeset cabcddbed377 by R David Murray in branch '3.3':
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/cabcddbed377

New changeset a80b67611c6d by R David Murray in branch 'default':
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/a80b67611c6d

New changeset e44fa71d76fe by R David Murray in branch '2.7':
#17171: backport behavior-confirming test from python3.
http://hg.python.org/cpython/rev/e44fa71d76fe

--
nosy: +python-dev

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



[issue17171] email.encoders.encode7or8bit does not work with binary data

2013-02-11 Thread R. David Murray

R. David Murray added the comment:

Since this was straightforwardly similar to the issue 16564 fix I didn't bother 
with a review.  The 2.7 commit is backporting the behavior-confirming test, 
just for thoroughness.

--
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

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



  1   2   >