ANN: grc 1.5 released

2013-08-15 Thread garabik-news-2005-05
This is generic colouriser, version 1.3.

grc is a colouriser configured by regular expressions, including 
a simple command line wrapper for some commonly used unix commands.

Changes in this version:
 - catch SIGPIPE 
 - add several configuration files
 - preliminary python3 support (as a consequence, at least python2.6 is
   needed)

License: GPL (any version)

URL: http://kassiopeia.juls.savba.sk/~garabik/software/grc.html

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Wed, 14 Aug 2013 13:05:50 -0400, random832 wrote:

 On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote:
 I'm always and still be suprised by the number of hard coded '\n' one
 can find in Python code when the portable (here win)
 
  os.linesep
 '\r\n'
 
 exists.
 
 Because high-level code isn't supposed to use the os module directly.

Say what? My brain hurts. The os module is full of lots of platform 
independent goodies. It is the right way to split and combine pathnames, 
test environment variables, manipulate file permissions, and other useful 
tasks.


 Text-mode streams automatically convert newlines you write to them.

Maybe they do, maybe they don't. It depends on whether Python is built 
with universal newline support, and what sort of text-mode stream you are 
using, and a bunch of other rules that make it a little more complicated 
than just automatically convert.


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


Re: Reading log and saving data to DB

2013-08-15 Thread Guy Tamir
On Thursday, August 15, 2013 1:34:38 AM UTC+3, Dennis Lee Bieber wrote:
 On Wed, 14 Aug 2013 06:18:08 -0700 (PDT), Guy Tamir guytam...@gmail.com
 
 declaimed the following:
 
 
 
 Hi all,
 
 
 
 I have a Ubuntu server running NGINX that logs data for me.
 
 
 
   Is the log coming from NGINX or (since you mention Django below) coming
 
 solely from the Django application.
 
 
 
   If the logging is from the Django application only, you should be able
 
 to have it connect to the database and write directly to it.
 
 -- 
 
   Wulfraed Dennis Lee Bieber AF6VN
 
 wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

the log is from NGINX..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: many constructors in a class?

2013-08-15 Thread Steven D'Aprano
On Wed, 14 Aug 2013 14:16:31 +, climb65 wrote:

 Hello,
 
 here is a small basic question :
 
 Is it possible to have more than one constructor (__init__ function) in
 a class? For instance, to create an object with 2 different ways? If my
 memory is good, I think that with C++ it is possible.
 
 Thanks for your answer.

Yes it is. The built-in type dict is a good example, there is the regular 
default constructor[1] that you can call like this:

dict([('a', 100), ('b', 200)], spam=1, ham=2, eggs=3)


Plus there is an alternative constructor that you can call like this:

dict.fromkeys(['a', 'b', 'spam', 'ham', 'eggs'])


The way to create an alternative constructor is to use a class method:


def MyDict(dict):
@classmethod
def fromkeys(cls, keys):
...


If you need further details, please ask.




[1] The constructor is __new__, not __init__. __init__ is called to 
initialise the instance after __new__ constructs it.


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


Re: Reading log and saving data to DB

2013-08-15 Thread Guy Tamir
On Wednesday, August 14, 2013 4:46:09 PM UTC+3, mar...@python.net wrote:
 On Wed, Aug 14, 2013, at 09:18 AM, Guy Tamir wrote:
 
  Hi all,
 
  
 
  I have a Ubuntu server running NGINX that logs data for me.
 
  I want to write a python script that reads my customized logs and after 
 
  a little rearrangement save the new data into my DB (postgresql).
 
  
 
  The process should run about every 5 minutes and i'm expecting large
 
  chunks of data on several 5 minute windows..
 
  
 
  My plan for achieving this is to install python on the server, write a
 
  script and add it to cron.
 
  
 
  My question is what the simplest way to do this? 
 
  should i use any python frameworks? 
 
 
 
 Rarely do I put framework and simplest way in the same set.
 
 
 
 I would do 1 of 2 things:
 
 
 
 * Write a simple script that reads lines from stdin, and writes to the
 
 db.  Make sure it gets run in init before nginx does and tail -F -n 0 to
 
 that script.  Don't worry about the 5-minute cron.
 
 
 
 * Similar to above but if you want to use cron also store in the db the
 
 offset of the last byte read in the file, then when the cron job kicks
 
 off again seek to that position + 1 and begin reading, at EOF write the
 
 offset again.
 
 
 
 This is irrespective of any log rotating that is going on behind the
 
 scenes, of course.

Not sure i understood the first options and what it means to run before the 
nginx.

The second options sound more like what i had in mind. 
Aren't there any components like this written that i can use? 

since the log fills up a lot i'm having trouble reading so much data and 
writing it all to the DB in a reasonable amount of time.

The table receiving the new data is somewhat complex.. the table's purpose is 
to save data regarding ads shown from my app, the fields are - 
(ad_id,user_source_site,user_location,day_date,specific_hour,views,clicks)
each row is distinct by the first 5 fields since i need to show different types 
of stats..
 
because each new line created may or may not be in the DB i have to run a 
upsert command (update or insert) on each row.. 

This leads to very poor performance.. 
Do have any ideas about how i can make this script more efficient?

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


Re: .split() Qeustion

2013-08-15 Thread wxjmfauth
Le mercredi 14 août 2013 19:14:59 UTC+2, Chris Angelico a écrit :
 On Wed, Aug 14, 2013 at 6:05 PM,  random...@fastmail.us wrote:
 
  On Wed, Aug 14, 2013, at 10:32, wxjmfa...@gmail.com wrote:
 
  I'm always and still be suprised by the number of hard coded
 
  '\n' one can find in Python code when the portable (here
 
  win)
 
 
 
   os.linesep
 
  '\r\n'
 
 
 
  exists.
 
 
 
  Because high-level code isn't supposed to use the os module directly.
 
  Text-mode streams automatically convert newlines you write to them.
 
 
 
 I'm always, and will still be, surprised by the number of hard coded
 
 decimal integers one can find in Python code, when the portable way to
 
 do it is to use ctypes and figure out whether your literals should be
 
 big-endian or little-endian, 32-bit or 64-bit, etc. Yet people
 
 continue to just put decimal literals in their code! It can't be
 
 portable.
 
 
 
 ChrisA

--

As a stupid scientist, I have the habbit to compare
things of the same nature with the same units.

This *string* containing one *character*

 sys.getsizeof('a')
26

consumes 26 *bytes*.


This *string* containing one *character*

 sys.getsizeof('\u2023')
40

consumes 40 *bytes*.

and the difference is

40 [bytes] - 26 [bytes] = 14 [bytes] .

—

Python seems to consider os.linesep as a
str.

 isinstance(os.linesep, str)
True


—

PS A mole is not a number.


jmf


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


Re: .split() Qeustion

2013-08-15 Thread Duncan Booth
Joshua Landau jos...@landau.ws wrote:

 That's true with this example, but is:
 
 lines = [
 Developments in high-speed rail, and high-speed,
 transport more generally, have historically been,
 impeded by the difficulties in managing friction,
 and air resistance, both of which become,
 substantial when vehicles approach high speeds.,
 The vactrain concept eliminates these obstacles,
 by employing magnetically levitating trains in,
 tubes kept at a complete vacuum, allowing for,
 heoretical speeds of thousands of miles per,
 hour. The high cost of constructing such a system,,
 however, and the difficulty of maintaining a,
 vacuum over large distances, has prevented this,
 type of system from ever being built. The,
 Hyperloop can be viewed as a modified vactrain,,
 employing more cost-effective solutions to the,
 same problems the latter was designed to solve.
 ]
 
 really more readable than:
 
 lines = \
 Developments in high-speed rail, and high-speed
 transport more generally, have historically been
 impeded by the difficulties in managing friction
 and air resistance, both of which become
 substantial when vehicles approach high speeds.
 The vactrain concept eliminates these obstacles
 by employing magnetically levitating trains in
 tubes kept at a complete vacuum, allowing for
 heoretical speeds of thousands of miles per
 hour. The high cost of constructing such a system,
 however, and the difficulty of maintaining a
 vacuum over large distances, has prevented this
 type of system from ever being built. The
 Hyperloop can be viewed as a modified vactrain,
 employing more cost-effective solutions to the
 same problems the latter was designed to solve.
 [1:-1].split(\n)
 
 ?

I suppose the question really is whether the author of the second 
example really meant to start with the word 'evelopments'?

If that was a mistake, then the first one is demonstrably less error 
prone. If it was intentional then the second one is definitely less 
readable.

Either way I think you've proved that the first way of writing it is 
more readable.

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


Define a class containing methods for reading a file and then store lines in external variable

2013-08-15 Thread Joug Raw
Hi,

I am really new in python programming and I want to build a class that perform 
various functions to the content(or lines) of any given file. I want to first 
include the opening and reading file function into that class, then add other 
methods.

Here is what I wrote for opening file and reading the lines:

class FileOpration:
def __init__(self,name):
self.name = name
self.filename = self.name
def readAllline(self):
open(self.name).readlines()

file1 = FileOpration(myfile.txt)
print file1.filename
allines = file1.readAllline()
print allines

I define self.name variable because I want to store the specific file that I 
read. This works fine by the test code of print file1.filename. I saw 
myfile.txt on the terminal output.

However, the readAllline() method dose not work. The code only give me None 
as the output on terminal

What was wrong with this code? Thank for the help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Define a class containing methods for reading a file and then store lines in external variable

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 10:33 AM, Joug Raw joug...@gmail.com wrote:
 class FileOpration:
 def __init__(self,name):
 self.name = name
 self.filename = self.name
 def readAllline(self):
 open(self.name).readlines()

 file1 = FileOpration(myfile.txt)
 print file1.filename
 allines = file1.readAllline()

You probably want to return that value:
def readAllline(self):
return open(self.name).readlines()

Then it'll do what you expect. But why wrap this up in a class? Why
not simply call the underlying functions directly?

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


Re: .split() Qeustion

2013-08-15 Thread wxjmfauth
A technical ascpect of triple quoted strings is
that the end of lines are not respected.

 import zzz
 zzz.__doc__
'abc\ndef\n'
 with open('zzz.py', 'rb') as fo:
... r = fo.read()
... 
 r
b'abc\r\ndef\r\n\r\n'

Now, one can argue...

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


Re: .split() Qeustion

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 10:46 AM,  wxjmfa...@gmail.com wrote:
 A technical ascpect of triple quoted strings is
 that the end of lines are not respected.

 import zzz
 zzz.__doc__
 'abc\ndef\n'
 with open('zzz.py', 'rb') as fo:
 ... r = fo.read()
 ...
 r
 b'abc\r\ndef\r\n\r\n'

 Now, one can argue...

Actually, they are respected. Triple-quoted strings are parsed after
the file is read in, and newline handling is dealt with at an earlier
level, same as encodings are. You wouldn't expect that string to
retain information about the source file's encoding, and nor do you
expect it to retain the source file's newline style. A newline is
represented in the file on disk as \r\n or \n (or something else,
even), and in the string as \n. It's that simple.

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


Re: many constructors in a class?

2013-08-15 Thread Fábio Santos
I agree with Steven here.

classmethod is the best practise, most practical, readable, future-proof,
one obvious way to do it.
On 15 Aug 2013 08:29, Steven D'Aprano st...@pearwood.info wrote:

 On Wed, 14 Aug 2013 14:16:31 +, climb65 wrote:

  Hello,
 
  here is a small basic question :
 
  Is it possible to have more than one constructor (__init__ function) in
  a class? For instance, to create an object with 2 different ways? If my
  memory is good, I think that with C++ it is possible.
 
  Thanks for your answer.

 Yes it is. The built-in type dict is a good example, there is the regular
 default constructor[1] that you can call like this:

 dict([('a', 100), ('b', 200)], spam=1, ham=2, eggs=3)


 Plus there is an alternative constructor that you can call like this:

 dict.fromkeys(['a', 'b', 'spam', 'ham', 'eggs'])


 The way to create an alternative constructor is to use a class method:


 def MyDict(dict):
 @classmethod
 def fromkeys(cls, keys):
 ...


 If you need further details, please ask.




 [1] The constructor is __new__, not __init__. __init__ is called to
 initialise the instance after __new__ constructs it.


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

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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Thu, 15 Aug 2013 02:46:20 -0700, wxjmfauth wrote:

 A technical ascpect of triple quoted strings is that the end of lines
 are not respected.
 
 import zzz
 zzz.__doc__
 'abc\ndef\n'


You are misinterpreting what you are seeing. You are not reading lines of 
text from a file. You are importing a module, and they accessing its 
__doc__ attribute. The relationship between the module object and text 
from a file is tenuous, at best:

- the module's file could use \n line endings, or \r, or \r\n, or even 
something else, depending on the platform;

- the module might be a compiled .pyc file, and there are no lines of 
text to read, just byte code;

- or a .dll or .so library, again, no lines of text, just compiled code;

- or there might not even be a file, like the sys module, which is 
entirely built into the interpreter; 

- or it might not even be a module object, you can put anything into 
sys.module. It might be an instance with docstrings computed on the fly.

So you can't conclude *anything* about text files from the fact that 
module docstrings typically contain only \n rather than \r\n line 
endings. Modules are not necessarily text files, and even when they are, 
once you import them, what you get is *not text*, but Python objects.


 with open('zzz.py', 'rb') as fo:
 ... r = fo.read()
 ...
 r
 b'abc\r\ndef\r\n\r\n'

And again, you are misinterpreting what you are seeing. By opening the 
file in binary mode, you are instructing Python to treat it as binary 
bytes, and return *exactly* what is stored on disk. If you opened the 
file in text mode, you would (likely, but not necessarily) get a very 
different result: the string would contain only \n line endings.

Python is not a low-level language like C. If you expect it to behave 
like a low-level language like C, you will be confused and upset.

But to prove that you are mistaken, we can do this:

py s = Triple-quote string\r
... containing carriage-return+newline line\r
... endings.
py s
'Triple-quote string\r\ncontaining carriage-return+newline line\r
\nendings.'


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


Re: many constructors in a class?

2013-08-15 Thread Roy Smith
In article 520c81f6$0$29885$c3e8da3$54964...@news.astraweb.com,
 Steven D'Aprano st...@pearwood.info wrote:

 [1] The constructor is __new__, not __init__. __init__ is called to 
 initialise the instance after __new__ constructs it.

True, but be warned that writing your own __new__() is quite rare and 
probably falls into the realm of dark magic.  If you're just starting 
out, learn about __init__(), and don't worry about __new__() at all.

For those of you coming from a C++ background, Python's __init__() is 
like C++'s constructor, and __new__() is more like operator new.  That's 
not a perfect analogy from a functional standpoint, but it's a good 
guide for how often you'll want to write each one.

And then, of course, there's __enter__() and __exit__(), which are like 
C++'s constructor and destructor, but that's another story :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .split() Qeustion

2013-08-15 Thread wxjmfauth



I perfectly knows what Python does.
I missinterpreting nothing.
I opened my example in binary mode just to show the real
endings.
It still remains the ... has its owns EOL and one
has to be aware of it.
No more, no less.

(... and tokenize.py is funny)

jmf

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


Want to learn Python

2013-08-15 Thread prem kumar
Hi All,

Presently Iam working with QTP(VBscript)..Now planning to learn PYTHON..Could 
you please suggest me like is ti good to learn what is the present condition 
for Python in IT Companies..
Iam not thinking abt only testing purpose even Iam interested to shift to 
development side on python..
Also if anyone knows abt good coaching institute for the same in Bangalore can 
share with me...
Eagerly waiting for response from the group..

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


Re: .split() Qeustion

2013-08-15 Thread Lele Gaifax
wxjmfa...@gmail.com writes:

 As a stupid scientist, I have the habbit to compare
 things of the same nature with the same units.

 This *string* containing one *character*

 sys.getsizeof('a')
 26

 consumes 26 *bytes*.

I'm not an expert in stupid science, and I fail to see the common
nature of the stuff you are comparing. Strings are not characters, and
neither the latter are bytes.

Anyway, trying to apply the same stupid science, I notice a much more
amazing fact:

 sys.getsizeof(True)
24

Does Python really needs twentyfour bytes to store a *single* bit of
information?? Wow, since by definition a byte contains eight bits,
there's a factor of 192... what a shame!

:-)

 —

 Python seems to consider os.linesep as a
 str.

 isinstance(os.linesep, str)
 True

Yes, I bet in stupid languages that would be either a single character,
or a tuple of two or more characters, much more usable and compact.

 —

 PS A mole is not a number.

Oh, nice to know. And OOC, what is a mole in your stupid science?
OTOH, WTF does that matter in current thread and with Python in general?

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: .split() Qeustion

2013-08-15 Thread MRAB

On 15/08/2013 15:38, Lele Gaifax wrote:

wxjmfa...@gmail.com writes:


As a stupid scientist, I have the habbit to compare
things of the same nature with the same units.

This *string* containing one *character*


sys.getsizeof('a')

26

consumes 26 *bytes*.


I'm not an expert in stupid science, and I fail to see the common
nature of the stuff you are comparing. Strings are not characters, and
neither the latter are bytes.

Anyway, trying to apply the same stupid science, I notice a much more
amazing fact:


sys.getsizeof(True)

24

Does Python really needs twentyfour bytes to store a *single* bit of
information?? Wow, since by definition a byte contains eight bits,
there's a factor of 192... what a shame!

:-)


—

Python seems to consider os.linesep as a
str.


isinstance(os.linesep, str)

True


Yes, I bet in stupid languages that would be either a single character,
or a tuple of two or more characters, much more usable and compact.


—

PS A mole is not a number.


Oh, nice to know. And OOC, what is a mole in your stupid science?
OTOH, WTF does that matter in current thread and with Python in general?


A mole is a term from chemistry:

http://en.wikipedia.org/wiki/Mole_%28unit%29

but I have no idea how it relates to Python or even to computers in
general.

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


Re: .split() Qeustion

2013-08-15 Thread Lele Gaifax
MRAB pyt...@mrabarnett.plus.com writes:

 On 15/08/2013 15:38, Lele Gaifax wrote:
 wxjmfa...@gmail.com writes:
 PS A mole is not a number.

 Oh, nice to know. And OOC, what is a mole in your stupid science?
 OTOH, WTF does that matter in current thread and with Python in general?

 A mole is a term from chemistry:

 http://en.wikipedia.org/wiki/Mole_%28unit%29

Yes, I know that, but AFAIU, there is a closer correlation between a
mole and a number than between a string and the number of bytes an
arbitrary computer [language] needs to store it. It did not come out as
funny as I meant :)

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: .split() Qeustion

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 4:30 PM, Lele Gaifax l...@metapensiero.it wrote:
 MRAB pyt...@mrabarnett.plus.com writes:

 On 15/08/2013 15:38, Lele Gaifax wrote:
 wxjmfa...@gmail.com writes:
 PS A mole is not a number.

 Oh, nice to know. And OOC, what is a mole in your stupid science?
 OTOH, WTF does that matter in current thread and with Python in general?

 A mole is a term from chemistry:

 http://en.wikipedia.org/wiki/Mole_%28unit%29

 Yes, I know that, but AFAIU, there is a closer correlation between a
 mole and a number than between a string and the number of bytes an
 arbitrary computer [language] needs to store it. It did not come out as
 funny as I meant :)

A mole is as much a number (6e23) as the light year is a number (9.5e15).

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


Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 01:17:40AM +0100, Rhodri James wrote:
 On Wed, 14 Aug 2013 00:10:41 +0100, Jack Bates tdh...@nottheoilrig.com  
 wrote:
 
  Can anyone suggest a way to get a pair of file descriptor numbers such  
  that data written to one can be read from the other and vice versa?
 
  Is there anything like os.pipe() where you can read/write both ends?
 
 Sockets?  It depends a bit on what you're trying to do, exactly.  If you  
 give us a bit more context, we might be able to give you better advice.

Thanks, I am writing a fixture to test an app. The app normally uses the Python
wrapper for the GnuTLS library to handshake with a service that I want to
mock up in my fixture. The app passes a file descriptor number to
gnutls_transport_set_ptr()

When I test the app, the app and fixture run in the same process. I want a file
descriptor number I can foist on the app, and in the fixture access what is
read/written to it by the GnuTLS wrapper.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 01:55:38AM +0100, Chris Angelico wrote:
 On Wed, Aug 14, 2013 at 1:17 AM, Rhodri James
 rho...@wildebst.demon.co.uk wrote:
  On Wed, 14 Aug 2013 00:10:41 +0100, Jack Bates tdh...@nottheoilrig.com
  wrote:
 
  Can anyone suggest a way to get a pair of file descriptor numbers such
  that data written to one can be read from the other and vice versa?
 
  Is there anything like os.pipe() where you can read/write both ends?
 
 
  Sockets?  It depends a bit on what you're trying to do, exactly.  If you
  give us a bit more context, we might be able to give you better advice.
 
 Specific questions:
 
 1) Do you need different processes to do the reading/writing?

No, only one process is involved.

 2) Do you need to separate individual writes (message mode)?

No, data can be split into smaller writes or merged into a bigger write, so
long as it arrives in order.

 ChrisA

Thank you for your help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 08:34:36AM +, Antoine Pitrou wrote:
 Nobody nobody at nowhere.com writes:
  On Tue, 13 Aug 2013 16:10:41 -0700, Jack Bates wrote:
   Is there anything like os.pipe() where you can read/write both ends?
  
  There's socket.socketpair(), but it's only available on Unix.
  
  Windows doesn't have AF_UNIX sockets, and anonymous pipes (like the ones
  created by os.pipe()) aren't bidirectional.
 
 I'm not sure I understand the problem: you can just create two pair of pipes
 using os.pipe().
 If that's too low-level, you can wrap the fds using BufferedRWPair:
 http://docs.python.org/3.3/library/io.html#io.BufferedRWPair
 
 (actual incantation would be:
  r1, w1 = os.pipe()
  r2, w2 = os.pipe()
 
  end1 = io.BufferedRWPair(io.FileIO(r1, 'r'), io.FileIO(w2, 'w'))
  end2 = io.BufferedRWPair(io.FileIO(r2, 'r'), io.FileIO(w1, 'w'))
 
  end1.write(bfoo)
  end1.flush()
  end2.read(3)  # - return bfoo
 )
 
 An alternative is to use multiprocessing.Pipe():
 http://docs.python.org/3.3/library/multiprocessing.html#multiprocessing.Pipe
 
 In any case, Python doesn't lack facilities for doing what you want.

Thank you for your help, I need to satisfy an interface that requires a single
file descriptor number that can be both read from and written to. Is it
possible with any of the solutions you pointed out to get a single file
descriptor number for each end?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested virtual environments

2013-08-15 Thread Marcel Rodrigues
I don't know how to completely solve this problem, but here is something
that can alleviate it considerably.

If you have a recent version of pip, you can use wheels [1] to save built
packages locally. First create a new virtualenv and install the common
packages. Then put these packages in a wheel directory. Then, for any other
virtualenv that need the common packages, you can easily install then from
the wheel directory (this is fast even for numpy  friends, because nothing
will be compiled again) [2].

# Create a new virtualenv
virtualenv myenv
source myenv/bin/activate
# Install the wheel package
pip install wheel
# Install your common packages
pip install numpy scipy matplotlib
# Create a requirements file
pip freeze  /local/requirements.txt
# Create wheel for the common packages
pip wheel --wheel-dir=/local/wheels -r /local/requirements.txt

Now you have all the built packages saved to /local/wheels, ready to
install on any other environment. You can safely delete myenv. Test it with
the following:

# Create a virtualenv for a new project
virtualenv myproj
source myproj/bin/activate
# Install common packages from wheel
pip install --use-wheel --no-index --find-links=/local/wheels -r
/local/requirements.txt

[1] https://wheel.readthedocs.org
[2]
http://www.pip-installer.org/en/latest/cookbook.html#building-and-installing-wheels



2013/8/9 Luca Cerone luca.cer...@gmail.com

 Dear all, is there a way to nest virtual environments?

 I work on several different projects that involve Python programming.

 For a lot of this projects I have to use the same packages (e.g. numpy,
 scipy, matplotlib and so on), while having to install packages that are
 specific
 for each project.

 For each of this project I created a virtual environment (using virtualenv
 --no-site-packages) and I had to reinstall the shared packages in each of
 them.

 I was wondering if there is a way to nest a virtual environment into
 another,
 so that I can create a common virtual environment  that contains all the
 shared packages and then specialize the virtual environments installing
 the packages specific for each project.

 In a way this is not conceptually different to using virtualenv
 --system-site-packages, just instead of getting access to the system
 packages a virtual environment should be able to access the packages of an
 other one.

 Thanks a lot in advance for the help,
 Luca
 --
 http://mail.python.org/mailman/listinfo/python-list

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


nose config help?

2013-08-15 Thread Tim
hi, I'm using nose to generate and run some tests not for python code, but for 
an html repository. I know this isn't the typical way to use nose, and so I'm 
asking here if the following code smells wrong.

I pass some args with the testconfig plugin and run a class setup method one 
time to get some information from a database. 
Then the tests get generated and run. During the run, a database is updated 
with the result. That is an intentional side-effect of running the testis 
that okay or something that should never be done?

I've shortened the actual code to make it readable, but the main thing is the 
setup (setting class vars), the test generator, and the actual test (plus the 
database update):

class HtmlTester(object):
'''
Run this setup method once before tests begin.
Reads from tconfig args to get document from database.
'''
@classmethod
def setup_class(cls):
name = tconfig['name']
language = tconfig.get('language', 'en')
report = db.conn({'name':name, 
  'language':language, 
  'format':'html})

@attr('images')
def test_images(self):
for image in self.report['images']:
yield (self.check_image, image)

def check_image(self, image):
'''
True if image can be read, otherwise False
'''
r = False
if get_imagesize(image):
p = ImageFile.Parser()
try:
p.feed(open(image).read())
except IOError:
r = False
else:
r = True
   
self.report.update({'image':image, 'result':r, 
'name': self.name, 
'language': self.language})
assert_true(r)
  
 if __name__ == '__main__':
 args = sys.argv[:1] + ['--tc=name:mybook', 
'--tc=language:en' ] + sys.argv[1:]
nose.run(argv=args)

I've used nose before in simpler situations, but not an expert.
This is complex enough that I wonder if the above approach is correct.

thanks,
--Tim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Want to learn Python

2013-08-15 Thread Joel Goldstick
On Thu, Aug 15, 2013 at 10:21 AM, prem kumar premiaskuma...@gmail.com wrote:
 Hi All,

 Presently Iam working with QTP(VBscript)..Now planning to learn PYTHON..Could 
 you please suggest me like is ti good to learn what is the present condition 
 for Python in IT Companies..
I don't really understand the previous sentence.  But guessing a bit,
 If you are concerned about whether python is used in business check
out http://wiki.python.org/moin/OrganizationsUsingPython

As I live in the US I have no idea what the situation is like where you live.

 Iam not thinking abt only testing purpose even Iam interested to shift to 
 development side on python..
 Also if anyone knows abt good coaching institute for the same in Bangalore 
 can share with me...
 Eagerly waiting for response from the group..

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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .split() Qeustion

2013-08-15 Thread Joshua Landau
On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number (9.5e15).

A mole is a number. A light year is a unit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Want to learn Python

2013-08-15 Thread Jordi Riera
On Thursday, August 15, 2013 4:21:43 PM UTC+2, prem kumar wrote:
 Hi All,
 
 
 
 Presently Iam working with QTP(VBscript)..Now planning to learn PYTHON..Could 
 you please suggest me like is ti good to learn what is the present condition 
 for Python in IT Companies..
 
 Iam not thinking abt only testing purpose even Iam interested to shift to 
 development side on python..
 
 Also if anyone knows abt good coaching institute for the same in Bangalore 
 can share with me...
 
 Eagerly waiting for response from the group..
 
 
 
 Thanks,
 
 Premkumar

you should give a try to codecademy.com. The approach of teaching programming 
language is new and really efficient.

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


question about posting data using MultipartPostHandler

2013-08-15 Thread cerr
Hi,

I want to use http post to upload data to a webserver but I want to pass 
multiple arguments within the post i.e.
I know that you can load one item (data)in there like this:
data = {data:open(filename,rb)}
response = opener.open(url, data, timeout=TIMEOUT)
but now I want multiple so I tried this:
multipart = ({data:data}, {fname:fname}, {f:f})
response = opener.open(url, multipart, timeout=TIMEOUT)

but I get an error saying 'tuple' object has no attribute 'items'... how do I 
do this correctly?

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


Re: Pair of filenos read/write each other?

2013-08-15 Thread Antoine Pitrou
Jack Bates tdhfwh at nottheoilrig.com writes:
  
  An alternative is to use multiprocessing.Pipe():
  http://docs.python.org/3.3/library/multiprocessing.html#multiprocessing.Pipe
  
  In any case, Python doesn't lack facilities for doing what you want.
 
 Thank you for your help, I need to satisfy an interface that requires a single
 file descriptor number that can be both read from and written to. Is it
 possible with any of the solutions you pointed out to get a single file
 descriptor number for each end?

Yes, it is what multiprocessing.Pipe() provides:
http://docs.python.org/3.3/library/multiprocessing.html#multiprocessing.Connection.fileno

Regards

Antoine.


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


Re: .split() Qeustion

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote:
 On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number (9.5e15).

 A mole is a number. A light year is a unit.

A mole is an amount of something. Avogadro's Number is a number, which
is what I was hinting at :)

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


Re: .split() Qeustion

2013-08-15 Thread Joshua Landau
On 15 August 2013 19:28, Chris Angelico ros...@gmail.com wrote:
 On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote:
 On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number (9.5e15).

 A mole is a number. A light year is a unit.

 A mole is an amount of something. Avogadro's Number is a number, which
 is what I was hinting at :)

I stand corrected.
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I redirect or launch a html file in wsgi coding?

2013-08-15 Thread Hans
Hi, 

I have code like this:

root@lin-ser-1:~# cat /usr/local/www/wsgi-scripts/myapp.py 
def application(environ, start_response):
import sys
...

status = '200 OK'
req_method=environ['REQUEST_METHOD']
if req_method == 'POST' :
json_received = environ['wsgi.input'].read()
resp=lib_json_http.process_json(json_received)
output = simplejson.dumps(resp)
elif req_method == 'GET' :
webbrowser.open('http://autotestnet.sourceforge.net/')
return   This code does not work
else :
 output = invalid request method

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

POST works OK, for GET, I hope I can redirect it to a url link, or launch a 
local html file, how can I do it? 

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


http post goes into $_REQUEST instead into $_FILES

2013-08-15 Thread cerr
Hi,

I have a Python script that is executing an http POST to transfer a file from 
the client to the server. I have achieved this with below code:

from binascii import hexlify, unhexlify
from httplib import HTTPConnection, HTTPException
import os
import hashlib
import socket
import urllib2
import time
import subprocess

import MultipartPostHandler

def post_file(filename, data):
try:
wakeup()
socket.setdefaulttimeout(TIMEOUT)
#create multipartpost handler
opener = 
urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
#set POST arguments
host = HOST
func = post_file
fname = filename
#assemble post URL
url = http://{0}{1}.format(host, URI)
print POSTING +fname
#assemble multipart header
data = {data:data,f:func,fname:filename}
#execute POST
response = opener.open(url, data, timeout=TIMEOUT)
#reads server return value
retval = response.read()
print retval
if SUCCESS in retval:
return 0
else:
print RETVAL: +retval
return 99
except Exception as e:
print EXCEPTION time +str(time.time())+ - +str(e)
return 99

but my problem is, the data gets posted to the sever but arrives in the 
`$_REQUEST` array and I'm expected to post stuff so that it arrives in the 
`$_FILES` array (this is a LAMP server). How do I need to modify my code to 
deliver it correctly?

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


Re: .split() Qeustion

2013-08-15 Thread Terry Reedy

On 8/15/2013 2:28 PM, Chris Angelico wrote:

On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote:

On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:

A mole is as much a number (6e23) as the light year is a number (9.5e15).


A mole is a number. A light year is a unit.


A mole is an amount of something. Avogadro's Number is a number, which
is what I was hinting at :)


The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for 
the 'something'. In other words, the units are the reacting input units 
and resulting output units in a particular chemical reaction.


--
Terry Jan Reedy

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


Re: .split() Qeustion

2013-08-15 Thread Dave Angel
Terry Reedy wrote:

 On 8/15/2013 2:28 PM, Chris Angelico wrote:
 On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote:
 On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number (9.5e15).

 A mole is a number. A light year is a unit.

 A mole is an amount of something. Avogadro's Number is a number, which
 is what I was hinting at :)

 The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for 
 the 'something'. In other words, the units are the reacting input units 
 and resulting output units in a particular chemical reaction.


To expand a little on that, the unit of amount of something is a gram
mole, which is 6.2 **23 grams times the molecular (or atomic) weight.

My dad (research chemist) used to have to order supplies for his lab in
ton moles, and he used some very small multipliers, since he usually
needed a kilogram or less in his lab.

-- 
DaveA


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


Re: question about posting data using MultipartPostHandler

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 7:12 PM, cerr ron.egg...@gmail.com wrote:
 multipart = ({data:data}, {fname:fname}, {f:f})

 but I get an error saying 'tuple' object has no attribute 'items'... how do 
 I do this correctly?

You're no longer providing a dictionary, but a tuple of dictionaries.
What you want to do is use a single dictionary:

multipart = {data:data, fname:fname, f:f}

That should achieve what you want.

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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote:

 A mole is as much a number (6e23) as the light year is a number
 (9.5e15).

Not quite. A mole (abbreviation: mol) is a name for a specific number, 
like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. 
And I can't believe I still remember that value :-) It's normally used 
only for atoms, ions or molecules, but in principle you could talk about 
anything. E.g. the population of the world is a mere 1.2e-14 mol.

A light-year, on the other hand, is a dimensional quantity. Whereas mole 
is dimensionless, light-year has dimensions of Length, and therefore the 
value depends on the units you measure in:

1 light-year:

= 3.724697e+17 inches
= 0.30660139 parsec
= 9.4607305e+12 kilometres

etc.


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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Thu, 15 Aug 2013 19:28:46 +0100, Chris Angelico wrote:

 On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws wrote:
 On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number
 (9.5e15).

 A mole is a number. A light year is a unit.
 
 A mole is an amount of something. Avogadro's Number is a number, which
 is what I was hinting at :)

Would you consider a dozen to be a number? Normally we use dozen only 
in reference to a dozen of something, not as an abstract pure number, but 
it's still a number in a way that light-year (or mile, or gram, or 
second) is not.

Mole is like dozen. Light-year is like mile. And Avagadro's Number is 
like twelve, only a bit bigger :-)


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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Thu, 15 Aug 2013 17:40:43 -0400, Terry Reedy wrote:

 On 8/15/2013 2:28 PM, Chris Angelico wrote:
 On Thu, Aug 15, 2013 at 5:54 PM, Joshua Landau jos...@landau.ws
 wrote:
 On 15 August 2013 16:43, Chris Angelico ros...@gmail.com wrote:
 A mole is as much a number (6e23) as the light year is a number
 (9.5e15).

 A mole is a number. A light year is a unit.

 A mole is an amount of something. Avogadro's Number is a number, which
 is what I was hinting at :)
 
 The unit for 'mole' is 'ion', 'atom', or 'molecule', as appropriate for
 the 'something'. In other words, the units are the reacting input units
 and resulting output units in a particular chemical reaction.

Careful about the use of the word unit, you're likely to confuse people 
into thinking atom is a unit of measurement like inches, seconds, grams 
or ohms. 

Naturally when dealing with moles of substance you have to take into 
account the kind of substance. In much the same way it makes a difference 
whether you are catering for a dozen people, a dozen couples, or a dozen 
football teams, a mole of oxygen molecules is not the same as a mole of 
oxygen atoms. But it's still the same number of things in each case, only 
the thing differs.


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


Re: .split() Qeustion

2013-08-15 Thread Roy Smith
In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com,
 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote:
 
  A mole is as much a number (6e23) as the light year is a number
  (9.5e15).
 
 Not quite. A mole (abbreviation: mol) is a name for a specific number, 
 like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. 
 And I can't believe I still remember that value :-)

I remember it as 6.022e23 :-)

In my high school chemistry class, there was a wooden cube, about 1/2 
meter on a side, sitting on the lecture desk in the front of the room.  
The only writing on it was 6.022 x 10^23.  It sat there all year.

The volume of the cube was that of 1 mole of an ideal gas at STP.

 A light-year, on the other hand, is a dimensional quantity. Whereas mole 
 is dimensionless, light-year has dimensions of Length, and therefore the 
 value depends on the units you measure in:
 
 1 light-year:
 
 = 3.724697e+17 inches
 = 0.30660139 parsec
 = 9.4607305e+12 kilometres

Hold your hands out in front of you, palms facing towards each other, 
one shoulder-width apart.  That distance is about one light-nanosecond.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Thu, 15 Aug 2013 22:56:57 +, Dave Angel wrote:

 To expand a little on that, the unit of amount of something is a gram
 mole, which is 6.2 **23 grams times the molecular (or atomic) weight.

The unit of amount of substance is mole. Gram-mole is an unfortunate 
synonym for mole. Unfortunate, because it looks like it should have 
dimensions of Mass, but it is actually a dimensionless number, and 
exactly equal to mole.

As usual, we can blame the damn engineers and their sloppy, ad-hoc 
thinking for abominations like this:

http://web.utk.edu/~dad/mole.html

Also, you're quoting Avogadro's Constant incorrectly: it's 6.02e23, or if 
you prefer, 6.02*10**23, not 6.2**23, which is a factor of about 358581 
too small.


 My dad (research chemist) used to have to order supplies for his lab in
 ton moles, and he used some very small multipliers, since he usually
 needed a kilogram or less in his lab.

That's just sad. The supplier won't be counting out individual molecules, 
they'll be putting it on a scale and weighing it. So your dad had to 
convert the desired weight into a ridiculously impractical unit to place 
the order, and the supplier no doubt had to convert that unit back into 
mass in order to weigh it out and supply it. If you want a kilogram of X, 
why not order a kilogram of X, instead of converting it into megamol?

Sigh, I know the answer to that question. We've always done it this way.


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


Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Fri, 16 Aug 2013 04:39:16 +, Steven D'Aprano wrote:

 On Thu, 15 Aug 2013 22:56:57 +, Dave Angel wrote:
 
 To expand a little on that, the unit of amount of something is a
 gram mole, which is 6.2 **23 grams times the molecular (or atomic)
 weight.
 
 The unit of amount of substance is mole. Gram-mole is an unfortunate
 synonym for mole. 

Oops, dropped a word there... 

The *SI unit* of amount of substance.



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


Re: .split() Qeustion

2013-08-15 Thread Dave Angel
Roy Smith wrote:

 In article 520da6d1$0$3$c3e8da3$54964...@news.astraweb.com,
  Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 On Thu, 15 Aug 2013 16:43:41 +0100, Chris Angelico wrote:
 
  A mole is as much a number (6e23) as the light year is a number
  (9.5e15).
 
 Not quite. A mole (abbreviation: mol) is a name for a specific number, 
 like couple (2) or dozen (12) or gross (144), only much bigger: 6.02e23. 
 And I can't believe I still remember that value :-)

 I remember it as 6.022e23 :-)

 In my high school chemistry class, there was a wooden cube, about 1/2 
 meter on a side, sitting on the lecture desk in the front of the room.  
 The only writing on it was 6.022 x 10^23.  It sat there all year.

 The volume of the cube was that of 1 mole of an ideal gas at STP.

 A light-year, on the other hand, is a dimensional quantity. Whereas mole 
 is dimensionless, light-year has dimensions of Length, and therefore the 
 value depends on the units you measure in:
 
 1 light-year:
 
 = 3.724697e+17 inches
 = 0.30660139 parsec
 = 9.4607305e+12 kilometres

 Hold your hands out in front of you, palms facing towards each other, 
 one shoulder-width apart.  That distance is about one light-nanosecond.

Narrow shoulders.

I figure it just under a foot.  I once attended a lecture by Grace
Hopper where she handed out nanoseconds, pieces of wire about a foot
long.  She said that the beaurocrats were always asking how much is a
nanosecond, and couldn't imagine what a billionth was like.  So she gave
them something physical.

-- 
Signature file not found

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


[issue18744] pathological performance using tarfile

2013-08-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could you please provide a simple script which shows the problem?

--
nosy: +serhiy.storchaka

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



[issue17628] str==str: compare the first character before calling memcmp()

2013-08-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Perhaps it worth manually inline unicode_eq() in these tight inner loops. Then 
we can move PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a) out of the loop.

--

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



[issue18743] References to non-existant StringIO module

2013-08-15 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
nosy: +serhiy.storchaka
stage:  - needs patch

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



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-15 Thread Michal Vyskocil

Michal Vyskocil added the comment:

The fast scalars approach looks great!

--

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



[issue18745] Test enum in test_json is ignorant of infinity value

2013-08-15 Thread Vajrasky Kok

New submission from Vajrasky Kok:

Test enum json in Lib/test/test_json/test_enum.py is ignorant of infinity 
values. Also, NaN, but since NaN is a weirdo, let's not take that into account.

The unit test should represent of what will work in every case. For example:

def test_floats(self):
 for enum in FloatNum:
self.assertEqual(self.dumps(enum), repr(enum.value))

This will fail if enum is infinity.

This wisdom about infinity was bestowed upon me when I was reading 
Lib/test/test_json/test_float.py.

def test_floats(self):
for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100, 
3.1]:
self.assertEqual(float(self.dumps(num)), num)
self.assertEqual(self.loads(self.dumps(num)), num)

def test_ints(self):
for num in [1, 132, 164]:
self.assertEqual(self.dumps(num), str(num))
self.assertEqual(int(self.dumps(num)), num)

As you can see, in float case, we don't use str(num) because it does not work 
with infinity.

Attached the patch to refactor the test to handle infinity value. For the 
completeness sake, I added the case of negative infinity and NaN as well.

--
components: Tests
files: add_infinity_to_test_enum_in_json.patch
keywords: patch
messages: 195238
nosy: ethan.furman, vajrasky
priority: normal
severity: normal
status: open
title: Test enum in test_json is ignorant of infinity value
versions: Python 3.4
Added file: 
http://bugs.python.org/file31298/add_infinity_to_test_enum_in_json.patch

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



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Or we can wrap the resolve_address() method with the @functools.lru_cache() 
 decorator.

Sounds ok to me.

--

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



[issue17628] str==str: compare the first character before calling memcmp()

2013-08-15 Thread STINNER Victor

STINNER Victor added the comment:

In issue #18719, Raymond modified Python 2.7, but he didn't touch the following 
macro:

#define Py_UNICODE_MATCH(string, offset, substring) \
((*((string)-str + (offset)) == *((substring)-str))  \
((*((string)-str + (offset) + (substring)-length-1) == *((substring)-str 
+ (substring)-length-1)))  \
 !memcmp((string)-str + (offset), (substring)-str, 
(substring)-length*sizeof(Py_UNICODE)))

It was said that looking for the last character before calling memcmp() is 
inefficient for the CPU cache. This macro should also be modified.

--

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



[issue17628] str==str: compare the first character before calling memcmp()

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

It's also bad for memory read performance if the string is rather long. The 
memory controller performs best when code reads memory sequential. The talk 
http://www.youtube.com/watch?v=MC1EKLQ2Wmg about mythbusting modern hardware 
sums it up real nice.

--

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



[issue18296] test_os.test_trailers() is failing on AMD64 FreeBSD 9.0 dtrace 3.x

2013-08-15 Thread koobs

koobs added the comment:

As per our IRC conversation, our 'koobs-freebsd10' bot also reproduces the 
failure and can be used to test the patch.

--

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



[issue18296] test_os.test_trailers() is failing on AMD64 FreeBSD 9.0 dtrace 3.x

2013-08-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 924d327da3af by Victor Stinner in branch '3.3':
Issue #18296: Try to fix TestSendfile.test_trailers() of test_os on FreeBSD
http://hg.python.org/cpython/rev/924d327da3af

New changeset 92039fb68483 by Victor Stinner in branch 'default':
(Merge 3.3) Issue #18296: Try to fix TestSendfile.test_trailers() of test_os on 
FreeBSD
http://hg.python.org/cpython/rev/92039fb68483

--
nosy: +python-dev

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



[issue18746] test_threading.test_finalize_with_trace() fails on FreeBSD buildbot

2013-08-15 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +koobs

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



[issue18746] test_threading.test_finalize_with_trace() fails on FreeBSD buildbot

2013-08-15 Thread STINNER Victor

New submission from STINNER Victor:

The following test fails on FreeBSD buildbot:

def test_finalize_with_trace(self):
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
assert_python_ok(-c, if 1:
import sys, threading

# A deadlock-killer, to prevent the
# testsuite to hang forever
def killer():
import os, time
time.sleep(2)
print('program blocked; aborting')
os._exit(2)
t = threading.Thread(target=killer)
t.daemon = True
t.start()

# This is the trace function
def func(frame, event, arg):
threading.current_thread()
return func

sys.settrace(func)
)

I ran it manually on my FreeBSD 9.1 VM, I get the following error. I don't know 
if it's the same error than the buildbot.

(...)
# clear builtins._
(...)
# restore sys.stderr
# cleanup __main__
# cleanup[1] _sysconfigdata
(...)
# cleanup[1] threading
Exception ignored in: function WeakSet.__init__.locals._remove at 
0x801b11058
Traceback (most recent call last):
  File /usr/home/haypo/prog/python/default/Lib/_weakrefset.py, line 38, in 
_remove
  File x.py, line 17, in func
AttributeError: 'NoneType' object has no attribute 'current_thread'
# cleanup[1] _weakrefset
(...)
# cleanup[3] _codecs
PyThreadState_Clear: warning: thread still has a frame


The weakref is probably threading._dangling.

IMO Py_Finalize() should first clear the trace function. Tracing Python 
exception while Python is dying (exiting) is insane. I'm surprised that it 
works :-)

--
messages: 195244
nosy: haypo, ncoghlan, pitrou
priority: normal
severity: normal
status: open
title: test_threading.test_finalize_with_trace() fails on FreeBSD buildbot
versions: Python 3.4

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



[issue18746] test_threading.test_finalize_with_trace() fails on FreeBSD buildbot

2013-08-15 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file31299/finalize_clear_trace.patch

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



[issue18219] csv.DictWriter is slow when writing files with large number of columns

2013-08-15 Thread Peter Otten

Peter Otten added the comment:

Note that set operations on dict views work with lists, too. So the only change 
necessary is to replace

wrong_fields = [k for k in rowdict if k not in self.fieldnames]

with

wrong_fields = rowdict.keys() - self.filenames

(A backport to 2.7 would need to replace keys() with viewkeys())

--
nosy: +peter.otten

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



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-15 Thread Mark Dickinson

Mark Dickinson added the comment:

Ah, Tim saw through my cunningly-laid false trail of incorrect issue numbers.  
Step 1 of my world domination plan is foiled!

Yes, let's fix this.  In my mind, it's definitely a bug that ints and longs 
aren't interchangeable here, and it would be nice to have 2.7 and 3.x behaving 
the same way.  I do have some worries about the fix breaking / changing 
existing code, but given that it'll only affect log of a long, those worries 
barely register.

--
type:  - behavior

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



[issue18335] Add textwrap.dedent, .indent, as str methods.

2013-08-15 Thread Julian Berman

Changes by Julian Berman julian+python@grayvines.com:


--
nosy: +Julian

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Christian Heimes

New submission from Christian Heimes:

A couple of reports and check-in messages like

  Postgres / pgcrypto CVE-2013-1900
  http://bugs.ruby-lang.org/issues/4579
  http://www.exim.org/lurker/message/20130402.171710.92f14a60.fi.html

suggests that OpenSSL's PRNG should be reset or re-seeded after fork(). 
Otherwise child processes can generate the same or similar pseudo random values.

Python doesn't have an API to run code before and after fork yet. The patch 
uses pthread_atfork() for the task. It's available on all pthread platforms -- 
which are all official supported platforms that have fork(), too.

The patch doesn't use RAND_cleanup() like Postgres because child process would 
hav to initial the PRNG again by opening and reading from /dev/urandom. The 
atfork prepare hook pulls from random bytes from the PRNG and stores them in a 
static buffer. The child handler seeds the PRNG from that buffer + pid + 
current time. PID and current time are mixed into the state to extenuate race 
conditions.

--
components: Extension Modules
files: openssl_prng_atfork.patch
keywords: patch
messages: 195247
nosy: christian.heimes, haypo
priority: normal
severity: normal
stage: patch review
status: open
title: Re-seed OpenSSL's PRNG after fork
type: security
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file31300/openssl_prng_atfork.patch

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Are there any uses of the OpenSSL PRNG from Python?
Is the PRNG used for SSL session keys, or another mechanism?

--
nosy: +pitrou, sbt
type: security - enhancement
versions:  -Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

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



[issue18335] Add textwrap.dedent, .indent, as str methods.

2013-08-15 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
stage: test needed - patch review

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



[issue16500] Add an 'atfork' module

2013-08-15 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +neologix

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +neologix

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

The ssl module exposes OpenSSL's PRNG and advertises the API as secure CPRNG: 
http://docs.python.org/3/library/ssl.html#random-generation

OpenSSL uses its own PRNG to create (amongst others) session keys for SSL 
connections.

--

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



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Using the custom builders, it seems to happen randomly in test_rlock:

test_rlock (test.test_multiprocessing_spawn.WithManagerTestLock) ... Assertion 
failed: !collecting, file ..\Modules\gcmodule.c, line 1617
ok

http://buildbot.python.org/all/builders/AMD64%20Windows%20Server%202008%20%5BSB%5D%20custom

--

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 The ssl module exposes OpenSSL's PRNG and advertises the API as secure
 CPRNG: http://docs.python.org/3/library/ssl.html#random-generation

AFAICT, Python's PRNG isn't reset after fork, so I don't think OpenSSL's
should be reset.
OTOH, multiprocessing does reseed the random module after fork, so it
should also do so for the ssl module if already loaded.

We may add a note in the ssl docs stating that it's better to reseed
after fork().

--

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

Python doesn't have a builtin PRNG. We use the OS's CPRNG such as /dev/urandom 
or CryptGenRandom(). Both use a system wide state and are not affected by 
process state. OpenSSL's PRNG is different because it uses an internal state. 
AFAIK it only polls the system's entropy poll when the PRNG is used for the 
first time.

It's not only multiprocessing. What about forking webservers etc. that use 
HTTPS?

--

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



[issue18748] libgcc_s.so.1 must be installed for pthread_cancel to work

2013-08-15 Thread Maries Ionel Cristian

New submission from Maries Ionel Cristian:

Running the file couple of times will make the interpreter fail with: 
libgcc_s.so.1 must be installed for pthread_cancel to work

From what I've seen it is triggered from PyThread_delete_key (tries to load 
libgcc_s.so at that time).

How does it happen?

The main thread will close fd 4 (because fh object is getting dereferenced to 
0) exactly at the same time libpthread will try to open and read libgcc_s.so 
with the same descriptor (4)

It's fairly obvious that the file handling in bug.py is a bug, but the 
interpreter should not crash like that !

This doesn't happen on python2.7. Also, python2.7 appears to be linked with 
libgcc_s.so.1 directly while the 3.x does not (I've tried 3.2 from ubuntu 
repos, and built 3.3 and 3.4 myself on ubuntu 12.04.2) - at least that's what 
ldd indicates.

--
components: Build, Extension Modules
files: bug.py
messages: 195253
nosy: ionel.mc
priority: normal
severity: normal
status: open
title: libgcc_s.so.1 must be installed for pthread_cancel to work
type: crash
versions: Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file31301/bug.py

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Python doesn't have a builtin PRNG.

Of course it does. It's in the random module, and you can seed() it:

 random.seed(5)
 random.random()
0.6229016948897019
 random.random()
0.7417869892607294
 random.seed(5)
 random.random()
0.6229016948897019

See e.g. issue12856. And the multiprocessing module:
http://hg.python.org/cpython/file/92039fb68483/Lib/multiprocessing/forkserver.py#l195

 We use the OS's CPRNG such as /dev/urandom or CryptGenRandom().

We?

 It's not only multiprocessing. What about forking webservers etc.
 that use HTTPS?

Well, are they affected? I haven't understood your previous answer.
(OpenSSL uses its own PRNG to create (amongst others) session keys for SSL 
connections)

Note that it seems debatable whether it's an OpenSSL bug:
http://www.openwall.com/lists/oss-security/2013/04/12/3

--

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

Am 15.08.2013 15:14, schrieb Antoine Pitrou:
 Python doesn't have a builtin PRNG.
 
 Of course it does. It's in the random module, and you can seed() it:

Now you are nit-picking. Although random is a PRNG, it is not a CPRNG.
I'm clearly talking about the integrity of a CPRNG here.

 We use the OS's CPRNG such as /dev/urandom or CryptGenRandom().
 
 We?

Python's os.urandom() and _PyOS_URandom().

 Well, are they affected? I haven't understood your previous answer.
 (OpenSSL uses its own PRNG to create (amongst others) session keys for SSL 
 connections)

Yes, they are are affected. A forking HTTPS server does:

1) listen() on a TCP port
2) accept() new TCP connection
3) fork() a child process to handle request
4) do SSL handshake in the child process
5) read/write data in child process

When the OpenSSL's CPRNG is already initialized before 3) than all child
processes created by 3) will have almost the same PRNG state. According
to http://bugs.ruby-lang.org/issues/4579 the PRNG will return the same
value when PID numbers are recycled.

 Note that it seems debatable whether it's an OpenSSL bug:
 http://www.openwall.com/lists/oss-security/2013/04/12/3

It probably is an OpenSSL bug but the declaration doesn't help us. It's
not the first time Python has to work around OpenSSL, e.g. #18709.

--

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 When the OpenSSL's CPRNG is already initialized before 3) than all child
 processes created by 3) will have almost the same PRNG state. According
 to http://bugs.ruby-lang.org/issues/4579 the PRNG will return the same
 value when PID numbers are recycled.

Thanks. Here is some discussion of the reseeding strategy:
http://marc.info/?l=openssl-devm=130432419329454w=2

More precisely, instead of reseeding in the child, you can simply
perturb the PRNG with a constant in the parent, to make sure the same
PRNG state doesn't get re-used.

--

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



[issue18749] [issue 18606] Re: Add statistics module to standard library

2013-08-15 Thread Steven D'Aprano

New submission from Steven D'Aprano:

I hope I'm doing the right thing by replying in-line. This is my first code 
review, please let me know if I'm doing something wrong.

By the way, the email hasn't gone to the tracker again. Is that a bug in the 
tracker? I've taken the liberty of changing the address to 
rep...@bugs.python.org.

On 15/08/13 22:58, ezio.melo...@gmail.com wrote:

 http://bugs.python.org/review/18606/diff/8927/Lib/statistics.py
 File Lib/statistics.py (right):

 http://bugs.python.org/review/18606/diff/8927/Lib/statistics.py#newcode113
 Lib/statistics.py:113: __date__ = 2013-08-13
 Are these still needed after inclusion?

Probably not. Also the licence will need to be changed.

 http://bugs.python.org/review/18606/diff/8927/Lib/statistics.py#newcode194
 Lib/statistics.py:194: 
 This would be good in the rst docs, but IMHO docstrings should be less
 verbose.
 If you end up copy/pasting all these in the rst file, you will duplicate
 all the docs and they will risk to get out of sync (in addition to have
 to update both every time).

Personally, I like having detailed docs in the docstring, at my fingers in the 
interactive interpreter. But I'll follow the consensus here.

 http://bugs.python.org/review/18606/diff/8927/Lib/statistics.py#newcode277
 Lib/statistics.py:277: assert isinstance(x, float) and
 isinstance(partials, list)
 Is this a good idea?

I think so :-) add_partials is internal/private, and so I don't have to worry 
about the caller providing wrong arguments, say a non-float. But I want some 
testing to detect coding errors. Using assert for this sort of internal 
pre-condition is exactly what assert is designed for.

 http://bugs.python.org/review/18606/diff/8927/Lib/statistics.py#newcode524
 Lib/statistics.py:524: mode(data [, max_modes]) - mode(s)
 The form mode(data, max_modes=1) - mode(s) is preferred.

Is it? I see plenty of examples in the standard library of that form, e.g. 
str.find:

find(...)
 S.find(sub [,start [,end]]) - int

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py
 File Lib/test/test_statistics.py (right):

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py#newcode46
 Lib/test/test_statistics.py:46: 'missing name %s in __all__' % name)
 FWIW This should be already covered by test___all__.

Sorry, I don't understand this. test__all__?

[...]
 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py#newcode144
 Lib/test/test_statistics.py:144: assert data != sorted(data)
 Why not assertNotEqual?

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py#newcode385
 Lib/test/test_statistics.py:385: assert x == inf
 Why not assertEqual?

In general, I use bare asserts for testing code logic, even if the code is test 
code. So if I use self.assertSpam(...) then I'm performing a unit test of the 
module being tested. If I use a bare assert, I'm asserting something about the 
test logic itself.

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py#newcode417
 Lib/test/test_statistics.py:417: self.assertTrue(math.isnan(sum(data)))
 Since you seem to use this quite often, it might be better to define a
 assertIsNaN (and possibly assertIsNotNaN) in NumericTestCase and provide
 a better error message in case of failure.
 The same could apply for assertIsInf.

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics.py#newcode913
 Lib/test/test_statistics.py:913: self.assertTrue(isinstance(result,
 Decimal))
 assertIsInstance

I used to be able to remember all the unittest assert* methods... there are so 
many now, 31 not including deprecated aliases.

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics_approx.py
 File Lib/test/test_statistics_approx.py (right):

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics_approx.py#newcode1
 Lib/test/test_statistics_approx.py:1: Numeric approximated equal
 comparisons and unit testing.
 Do I understand correctly that this is just an helper module used in
 test_statistics and that it doesn't actually test anything from the
 statistics module?

Correct. It does, however, test itself.

 http://bugs.python.org/review/18606/diff/8927/Lib/test/test_statistics_approx.py#newcode137
 Lib/test/test_statistics_approx.py:137: # and avoid using
 TestCase.almost_equal, because it sucks :-)
 Could you elaborate on this?

Ah, I misspelled TestCase.AlmostEqual.

- Using round() to test for equal-to-some-tolerance is quite an idiosyncratic 
way of doing approx-equality tests. I've never seen anyone do it that way 
before. It surprises me.

- It's easy to think that ``places`` means significant figures, not decimal 
places.

- There's now a delta argument (when was that added?) that is the same as my 
absolute error tolerance ``tol``, but no relative error argument.

- You can't set a  per-instance error tolerance.

 

[issue18749] [issue 18606] Re: Add statistics module to standard library

2013-08-15 Thread Ezio Melotti

Ezio Melotti added the comment:

 I hope I'm doing the right thing by replying in-line. This is my
 first code review, please let me know if I'm doing something wrong.

 By the way, the email hasn't gone to the tracker again. Is that a
 bug in the tracker? I've taken the liberty of changing the address
 to rep...@bugs.python.org.

Apparently that doesn't work, since it created a new issue :)

The best way is to reply directly on http://bugs.python.org/review/18606/.  You 
can either reply to the individual comments (better), or to the whole message 
like you did here.  I don't know if there's a way to reply via email.

--
nosy: +ezio.melotti
resolution:  - invalid
stage:  - committed/rejected
status: open - closed

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



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

Updated patch.

I'm going to add documentation when everybody is happy with the patch.

--
nosy: +pitrou
Added file: http://bugs.python.org/file31302/hashlib_abc2.patch

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



[issue18533] Avoid error from repr() of recursive dictview

2013-08-15 Thread Ben North

Ben North added the comment:

Is anything further needed from me before this can be reviewed?

--

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



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-15 Thread Christian Heimes

Changes by Christian Heimes li...@cheimes.de:


--
stage: patch review - committed/rejected

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



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

The builtin hash algorithms still had upper case names. I fixed it in 
revision http://hg.python.org/cpython/rev/9a4949f5d15c

--

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



[issue18533] Avoid error from repr() of recursive dictview

2013-08-15 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Please visit
http://www.python.org/psf/contrib/
http://www.python.org/psf/contrib/contrib-form/
and submit a Contributor Agreement. This process is complete when '*' appears 
after your name here, as with mine and others.

--

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



[issue13248] deprecated in 3.2/3.3, should be removed in 3.4

2013-08-15 Thread Larry Hastings

Changes by Larry Hastings la...@hastings.org:


--
nosy: +larry

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



[issue18750] ''' % [1] doens't fail

2013-08-15 Thread Andrew Svetlov

New submission from Andrew Svetlov:

I think this is a bug.
Can be reproduced on all Pythons (from 2.6 to 3.4a).
Maybe should be fixed for 3.4 only as backward incompatible change.

--
messages: 195263
nosy: asvetlov
priority: normal
severity: normal
status: open
title: ''' % [1] doens't fail

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



[issue13248] deprecated in 3.2/3.3, should be removed in 3.4

2013-08-15 Thread Senthil Kumaran

Changes by Senthil Kumaran sent...@uthcode.com:


--
nosy: +orsenthil

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread STINNER Victor

STINNER Victor added the comment:

This issue was already discussed in the atfork issue:
http://bugs.python.org/issue16500#msg179838

See also:
http://www.openwall.com/lists/oss-security/2013/04/12/3
I believe it is wrong to fix this in PostgreSQL.  Rather, this is a
bug in the OpenSSL fork protection code.  It should either install a
fork hook, or reseed the PRNG from /dev/urandom if a PID change is
detected.

--

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



[issue18747] Re-seed OpenSSL's PRNG after fork

2013-08-15 Thread STINNER Victor

STINNER Victor added the comment:

Another link:
http://article.gmane.org/gmane.comp.encryption.openssl.user/48480/match=does+child+process+still+need+reseeded+after+fork

--

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



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ok, I enabled faulthandler in the child process and I got the explanation:
http://buildbot.python.org/all/builders/AMD64%20Windows%20Server%202008%20%5BSB%5D%20custom/builds/5/steps/test/logs/stdio

multiprocessing's manager Server uses daemon threads... Daemon threads are not 
joined when the interpreter shuts down, they are simply frozen at some point. 
Unfortunately, it may happen that a deamon thread is frozen while it was 
doing a cyclic garbage collection, which later triggers the assert.

I'm gonna replace the assert by a plain if, then.

--
resolution:  - fixed
stage: needs patch - committed/rejected

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



[issue18751] A manager's server never joins its threads

2013-08-15 Thread Antoine Pitrou

New submission from Antoine Pitrou:

The Server class in multiprocessing.managers creates daemon threads and never 
joins them. This is in contrast with e.g. the Pool class, which creates daemon 
threads but uses util.Finalize to join them.

(not joining daemon threads may have adverse effects such as resource leaks or 
otherwise unexpected glitches)

Issue spawned from http://bugs.python.org/issue8713#msg195178.

--
components: Library (Lib)
messages: 195267
nosy: pitrou, sbt
priority: normal
severity: normal
status: open
title: A manager's server never joins its threads
type: behavior
versions: Python 3.4

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



[issue18750] ''' % [1] doens't fail

2013-08-15 Thread R. David Murray

R. David Murray added the comment:

What is it that doesn't fail?  The expression in the title is the beginning of 
a triple quoted string with no closing triple quote.

If you mean '' % [1] not falling, it has been that way forever (well, python2.4 
is as far back as I can test), so if it is deemed worth changing it certainly 
should not be backported.

I suspect it is some consequence of the C level similarities between lists and 
dicts, since '' % {anything} is supposed to not produce an error.

--
nosy: +r.david.murray

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



[issue18750] '' % [1] doens't fail

2013-08-15 Thread STINNER Victor

STINNER Victor added the comment:

I don't understand why str % list and str % dict behaves differently than str % 
int:

 'abc' % [1]
'abc'
 'abc' % ([1],)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting
 'abc' % 1
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting
 'abc' % {1:2}
'abc'
 'abc' % ({1:2},)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: not all arguments converted during string formatting

--
nosy: +haypo
title: ''' % [1] doens't fail - '' % [1] doens't fail

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



[issue18727] test for writing dictionary rows to CSV

2013-08-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thanks. One more question: is there a reason you don't simply call getvalue() 
at the end (rather than seek(0) followed by several readline() calls)?

--

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



[issue18425] IDLE Unit test for IdleHistory.py

2013-08-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 0e9d41edb2e4 by Terry Jan Reedy in branch '2.7':
Issue #18425: Unittests for idlelib.IdleHistory. First patch by R. Jayakrishnan.
http://hg.python.org/cpython/rev/0e9d41edb2e4

New changeset c4cac5d73e9d by Terry Jan Reedy in branch '3.3':
Issue #18425: Unittests for idlelib.IdleHistory. First patch by R. Jayakrishnan.
http://hg.python.org/cpython/rev/c4cac5d73e9d

--

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



[issue18750] '' % [1] doens't fail

2013-08-15 Thread R. David Murray

R. David Murray added the comment:

haypo: str % dict is a feature:

   %(a)s % {'a': 1, 'b': 2}
  '1'

--

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



[issue18739] math.log of a long returns a different value of math.log of an int

2013-08-15 Thread Tim Peters

Tim Peters added the comment:

+1 on fixing it in 2.7, for the reasons Mark gave.

Way back when I introduced the original scheme, log(a_long) raised an 
exception, and the `int` and `long` types had a much higher wall between them.  
The original scheme changed an annoying failure into a pretty good 
approximation, and because int operations never returned a long back then the 
relatively rare code using longs forced their use.

In the meantime, you can change failing cases of log(some_long) to 
log(int(some_long)).  int(some_long) will convert to int if possible (avoiding 
this path in the log code), but return some_long unchanged otherwise.  In the 
old days, int(some_long) would fail if some_long was too big to fit in an int - 
that's different now too - and for the better :-)

--

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



[issue18750] '' % [1] doens't fail

2013-08-15 Thread Andrew Svetlov

Andrew Svetlov added the comment:

For dict it is correct from my perspective.
 % {'a': 'b'}
tries to substitute format specs like %(a)s and does nothing if spec is not 
present.

But list case like
 % [1]
confuse me.

--

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



[issue18226] IDLE Unit test for FormatParagrah.py

2013-08-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 47307e7c80e1 by Terry Jan Reedy in branch '2.7':
Issue #18226: Fix ImportError and subsequent TypeError in 2.7 backport.
http://hg.python.org/cpython/rev/47307e7c80e1

--

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



[issue18425] IDLE Unit test for IdleHistory.py

2013-08-15 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
resolution:  - fixed
superseder:  - IdleHistory.History: eliminate unused parameter; other cleanup.

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



[issue18425] IDLE Unit test for IdleHistory.py

2013-08-15 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
status: open - closed

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



[issue18226] IDLE Unit test for FormatParagrah.py

2013-08-15 Thread Terry J. Reedy

Terry J. Reedy added the comment:

test.regrtest is semi-useless, at least for idle, in 2.7 -- see commit message. 
First run single file directly or python -m test.test_idle.

--

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



[issue18744] pathological performance using tarfile

2013-08-15 Thread K Richard Pixley

K Richard Pixley added the comment:

New info...

I see the degradation on most of the linux boxes I've tried:
* ubuntu-13.04, (raring), 64-bit
* rhel-5.4 64-bit
* rhel-5.7 64-bit
* suse-11 64-bit

I see some degradation on MacOsX-10.8.4 but it's in the acceptable range, more 
like 2x than 60x.  That is still suspicious, but not as problematic.

--

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



[issue18744] pathological performance using tarfile

2013-08-15 Thread K Richard Pixley

K Richard Pixley added the comment:

Here's a script that tests for the problem.

--
Added file: http://bugs.python.org/file31303/tarproblem.py

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



  1   2   >