PyCon early-bird deadline: MONDAY Jan. 17

2011-01-14 Thread Catherine Devlin
The early-bird registration deadline is coming up fast: it's this Monday,
Jan. 17!  (AUDIENCE GASPS)

Fortunately, everything you need is right here:

PyCon 2011, March 9-17: http://us.pycon.org
Register: https://www.cteusa.com/pycon4/
Tutorial list: http://us.pycon.org/2011/schedule/lists/tutorials/
Talk list: http://us.pycon.org/2011/schedule/lists/talks/
Hotel reservation: https://www.cteusa.com/pycon4/

Also, keep in mind that, for the first time ever, we've had to place a cap
of 1500 on PyCon registration.  Delaying too long won't just cause you to
miss the early-bird discount, it might make you miss PyCon altogether.
While there might be a certain historical thrill in being able to say, Yes,
I was one of the people turned away from the world's first sold-out
PyCon... no, don't do that.

Please forward this notice in Python-related groups and mailing lists you
belong to.  How will you live with yourself if a friend misses PyCon because
you didn't tell them?

See you in Atlanta!
-- 
- Catherine
http://catherinedevlin.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


New Python Sheffield group

2011-01-14 Thread Daley Chetwynd
Hi all,

I'm starting up a new Python user group in Sheffield, United Kingdom.
It's being held on the final Tuesday of each month at the GIST Lab,
Sheffield:

http://thegisthub.net/groups/gistlab/

The first meeting is on Tues Jan 25th 2011 from 18:30 - 21:00. If you'd
like to attend, please register for free at:

pythonsheffield.eventbrite.com

The Python Sheffield group is open to all levels of Python user. If
you're in the Sheffield area then you're more than welcome to attend. If
you know Python users in Sheffield, please pass the word on.   :)

I've set up the Twitter account @pysheff and the Google group:

http://groups.google.com/group/python-sheffield

Hope to see some of you there. Thanks,

Daley Chetwynd

--

-- 
http://www.fastmail.fm - Send your email first class

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

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


Re: Multiple independently started python processes and sharing of a module

2011-01-14 Thread Martin P. Hellwig

On 01/14/11 03:04, Kushal Kumaran wrote:

- Original message -

Hi all,

I have the following problem (which I already have a hacked around
solution that works but I'd would like some more input on it):

I have a situation where multiple python processes are started
independently from each other but by the same user with the same
environment (as happens with mod_wsgi, when not using daemon mode).

All of these processes access a single module which needs
synchronization for some of the commands, for example a db (MySQLdb)
module where when a select is done, the fetchall must be done of that
same process before another process can do anything else.



If the processes are independent, they are not sharing the database connection, 
unless you've taken steps to make it so.  MySQLdb imported in one process 
should not interfere with MySQLdb importerd in another process.


snip



It might be a misconfiguration but, under mod_wsgi with apache it does.

Cheers,

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


how to use priority queue with multiprocessing

2011-01-14 Thread Marco Hornung
Hey, 

--
question
--
How can I use a priority queue to schedule jobs within the multiprocessing 
pool module?

--
my scenario
--
I want to run several jobs on a server. The jobs are being sent by users. 
However, all jobs have a different priority, and high-priority jobs should be 
processed before any low-priority job gets touched.
Currently I just append all incoming jobs to the multiprocessing worker pool as 
follows:
### initialize worker pool
pool= PriorityPool(processes=worker_count)
process_handles = []

### distribute function execution over several processes
for job_parameter in job_parameter_list:
handle = pool.apply_async(process_function, [job_parameter,])
process_handles.append(handle)

This will only put the jobs in some kind of a list - and execute the jobs in 
the order they come in. Is it possible to use a priority queue for the 
process-pool?

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


ANNOUNCE: NHI1-0.11, PLMK-2.0 und libmsgque-5.0

2011-01-14 Thread Andreas Otto
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Dear User,


ANNOUNCE:Major Feature Release


  libmsgque: Application-Server-Toolkit for
 C, C++, JAVA, C#, Go, TCL, PERL, PHP, PYTHON, RUBY, VB.NET
  PLMK:  Programming-Language-Microkernel
  NHI1:  Non-Human-Intelligence #1


SUMMARY
===


Finish release 4 of wp2 with adding Factory support.
The Factory add the ability to create NEW server-types on-the-fly and
introduce the self-programming capability to NHI1.

The Factory is an important part of the object management and has the
following basic features:

 * create a new instance identified by an Identifier or using an
   already available instance as template
 * cleanup and delete an instance
 * provide an Identifier for factory lookup and as an unique
   application name
 * identify the server in the network

The link between the Factory-Identifier and the Factory-Interface is
important for the future development of libmsgque. Message-Routing,
Service-Location and Persistent-Transactions depend on this feature.

The relationship between the MqFactoryS and the MqS is the same as
the relationship between a type and an instance of the type in a
regular programming language.
The MqFactoryS define the type of the server and the MqS define a
single instance of the server. Every kind of server has !!only one!!
specific MqFactoryS object but every instance of a server has one
MqS object used for object management. Decreasing the size and the
complexity of a MqS object will improve the server performance.
In future more fields, defined in the MqSetupS attribute of the the
MqS object, will move into MqFactoryS object.



LINKS
=

  libmsgque including PHP documentation:
http://nhi1.berlios.de/theLink/index.htm
  NHI1:
http://nhi1.berlios.de/
  DOWNLOAD:
http://developer.berlios.de/projects/nhi1/



mfg, Andreas Otto (aotto1968)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNMBYJAAoJEGTcPijNG3/AxGkH/1Nf7GBL7DWAUktwaFs7Bs69
7voAXXWgIug+X42MqmsjFY8TrVGSHJfB8au+gecP1z6RQnPlubT2Od9T3GbXJL5h
ZeyK8r2cf7reqp0W63iw0Gh+mDV/bmcjqjA8RTvw95du8l8t0W+zSjcDmeMct/a6
o8eTvQTfCyr7+LcOqjzVEA19XVVgJBF55DA24+HACVFgXfRchpylZiXegmAC0iFy
gWKDAyiC95wJzZuqK+a5hPAYOZ+nhAaEMDVY0olN81qnWnb7j6uubSWAbgdXPWaP
zu1gXoGo2fugqQt8XB1Ux8gHZhXOXVQGxcX2LyMUwiI1iXxnLVXXL1K3p7+Wnng=
=/7W5
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple independently started python processes and sharing of a module

2011-01-14 Thread Kushal Kumaran
On Fri, Jan 14, 2011 at 1:51 PM, Martin P. Hellwig
martin.hell...@dcuktec.org wrote:
 On 01/14/11 03:04, Kushal Kumaran wrote:

 - Original message -

 Hi all,

 I have the following problem (which I already have a hacked around
 solution that works but I'd would like some more input on it):

 I have a situation where multiple python processes are started
 independently from each other but by the same user with the same
 environment (as happens with mod_wsgi, when not using daemon mode).

 All of these processes access a single module which needs
 synchronization for some of the commands, for example a db (MySQLdb)
 module where when a select is done, the fetchall must be done of that
 same process before another process can do anything else.


 If the processes are independent, they are not sharing the database
 connection, unless you've taken steps to make it so.  MySQLdb imported in
 one process should not interfere with MySQLdb importerd in another process.

 snip

 It might be a misconfiguration but, under mod_wsgi with apache it does.


Ah, I didn't notice the mod_wsgi reference.  I'm out of my depth here.
 Hopefully someone with mod_wsgi experience will chime in.

This might help though:
https://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

It seems if you're not using 'daemon' mode, global data might be shared.

You could create new connections for each request (and close them when
done).  There won't be interference between select/fetch across
multiple database connections.  Additionally, the documentation of
MySQLdb says it is a bad idea to share database connections between
threads.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple independently started python processes and sharing of a module

2011-01-14 Thread Martin P. Hellwig

On 01/14/11 10:05, Kushal Kumaran wrote:
cut

This might help though:
https://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

It seems if you're not using 'daemon' mode, global data might be shared.


Yes I read that thoroughly before I started out implementing a solution.
But in my case I wanted something that worked as expected and not be 
depending on specific configuration of underlying technology as I can 
not assure that these condition will be met.



You could create new connections for each request (and close them when
done).  There won't be interference between select/fetch across
multiple database connections.  Additionally, the documentation of
MySQLdb says it is a bad idea to share database connections between
threads.



That is a possible solution too, however the performance impact is in 
the range of 40% while doing forced synchronization and overhead of the 
singleton wrapper is around 20%. So the latter is what I have gone with.


Thanks for bouncing off ideas though, much appreciated.

--
mph


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


Re: Resolve circular reference

2011-01-14 Thread Hrvoje Niksic
Magnus Lyckå ly...@carmen.se writes:

 a = X()
 del a
 Deleted __main__.X instance at 0x00CCCF80
 a=X()
 b=X()
 a.b=b
 b.a=a
 del a
 gc.collect()
 0
 del b
 gc.collect()
 4

If your method has a __del__ at all, the automatic cyclic collector is
disabled.  It detects the cycle, but it only stores the objects in
gc.garbage, to give you a chance to do something about them, such as
break the cycle(s) yourself.  For example:

 class X(object):
...   def __del__(self):
... print 'deleted', self
...
 a, b = X(), X()
 a.cycle = b
 b.cycle = a
 del a, b
 import gc
 gc.collect()
4
 gc.garbage
[__main__.X object at 0xb76d84cc, __main__.X object at 0xb76d980c]
 del gc.garbage[0].cycle
 del gc.garbage[:]
deleted __main__.X object at 0xb76d980c
deleted __main__.X object at 0xb76d84cc
-- 
http://mail.python.org/mailman/listinfo/python-list


FTP problem

2011-01-14 Thread Thomas Philips
I'm using ftplib for the first time, and am having trouble getting it
to work. I type

 from ftplib import FTP
 ftp = FTP('ftp.indexftp.barcap.com', 'A Valid Username', ' A Valid 
 Password')

where I have suppressed the user name and password, and I get

Traceback (most recent call last):
  File pyshell#2, line 1, in module
ftp = FTP('ftp.indexftp.barcap.com')
  File C:\Python26\lib\ftplib.py, line 116, in __init__
self.connect(host)
  File C:\Python26\lib\ftplib.py, line 131, in connect
self.sock = socket.create_connection((self.host, self.port),
self.timeout)
  File C:\Python26\lib\socket.py, line 498, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11001] getaddrinfo failed

I have tried this on two different computers and on two different
versions of Python (2.6 and 2.7). I get the same error both times, and
have no understanding of what the problem might be. Any assistance
would be greatly appreciated.

Sincerely

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


Re: FTP problem

2011-01-14 Thread python
Thomas,

 ftp = FTP('ftp.indexftp.barcap.com', 'A Valid Username', ' A Valid Password')

Your FTP URI is bad. When I try to connect to your site from the Windows
FTP client, I get the following response:

Unknown host ftp.indexftp.barcap.com.

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


Re: FTP problem

2011-01-14 Thread Sudheer Satyanarayana



gaierror: [Errno 11001] getaddrinfo failed
That part of the error indicates, your computer is unable to resolve the 
IP address for the hostname


ftp.indexftp.barcap.com

Make sure the hostname is valid.

--
With warm regards,
Sudheer. S
Personal home page - http://sudheer.net | Tech Chorus - 
http://techchorus.net

Web and IT services - http://binaryvibes.co.in
--
http://mail.python.org/mailman/listinfo/python-list


unbalanced tree iteration issue

2011-01-14 Thread Alex Boyko
Dear All!

I have deal with large unbalanced trees and I have to implement post-order
tree traversal. My first attempt is shown below (Node and Tree classes)
and based on recursive generators approach.

class Node():
def __init__(self,value):
self.childs = []
self.value = value

class Tree():

def __init__(self, root):
self.root = root
self.numberCells = 1

def add(self, node, child):
node.childs.append(child)
self.numberCells+=1

def __iter__(self):
return self.postorder(self.root)

def postorder(self, node):
if node:
for child in node.childs:
for n in self.postorder(child):
yield n
yield node


It works fine for small test trees. But, my tree has approximately 30
nodes, and shown post order traversal with generators takes 80 sec against 1
sec with simple recursive routine:


def recursiveFromTop(node):
for child in node.childs:
recursiveFromTop(child)
## here I can do some computations with current node's data


So, I'd like to know how should I implement (if it's possible of course)
__iter__ for my tree class based on recursion without generators? Please,
can You show me the ways?
because I'm very passionate in idea iterate through my tree with simple:

for node in tree:
   do something with node


Thanks in Advance!
Best Regards!
Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


wx Just Print!

2011-01-14 Thread Mark Carter
I'm using Python 2.6.5. I would like to be able to print an RTF file,
with no prompts for printers or anything like that.

Here's the code so far:
import wx.richtext
rtp = wx.richtext.RichTextPrinting()
rtp.PrintFile('C:\\path\\to\\file.rtf')

When I run it, it says: ... assert (wxThePrintPaperDatabase*) NULL)
failed ...

What is the fix?
-- 
http://mail.python.org/mailman/listinfo/python-list


TestFixtures 1.8.0 Released!

2011-01-14 Thread Chris Withers

Hi All,

I'm very happy to announce the first fully-documented release of 
TestFixtures, my collection of testing fixtures and helpers that I've 
been collecting for the last couple of years.


Along with my own take on a lot of the common fixtures and helpers, it 
has some bits that I haven't seen anywhere else and so would like to 
point out:


- Comparison objects for comparing objects that don't natively support
  comparison:

  http://packages.python.org/testfixtures/comparing.html#comparison-objects

- Helpful mock objects for when you want to test code that makes use of
  datetime.datetime.now, datetime.date.today or time.time:

  http://packages.python.org/testfixtures/datetime.html

- Helpers for capturing and checking messages logged from your code
  using the python logging framework:

  http://packages.python.org/testfixtures/logging.html

- Helpers for working with temporary directories in tests. In
  particular, quickly and easily creating temporary directories and
  files within them and making assertions about things written to them
  by the code under test:

  http://packages.python.org/testfixtures/files.html

There's plenty more in there too!

Please do let me know what you find useful, if you find any bugs or if 
there are any features you'd like to see added.


The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


http://www.simplistix.co.uk/software/python/testfixtures

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread leoboiko
Of course I searched for one and couldn’t find; that goes without
saying.  Otherwise I wouldn’t even bother writing a message, isn’t
it?  I disagree people should cruft their messages with details about
how they failed to find information, as that is unrelated to the
question at hand and has no point other than polluting people’s
mailboxes.

I also see no reason to reply to a simple question with such
discourtesy, and cannot understand why someone would be so aggressive
to a stranger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread kost BebiX
14.01.2011, 14:15, Alex Boyko alex.kyr...@gmail.com:
 Dear All!

 I have deal with large unbalanced trees and I have to implement post-order 
 tree traversal. My first attempt is shown below (Node and Tree classes) 
 and based on recursive generators approach.

 class Node():
     def __init__(self,value):
         self.childs = []
         self.value = value

 class Tree():

     def __init__(self, root):
         self.root = root
         self.numberCells = 1

     def add(self, node, child):
         node.childs.append(child)
         self.numberCells+=1

     def __iter__(self):
         return self.postorder(self.root)

     def postorder(self, node):
         if node:
             for child in node.childs:
                 for n in self.postorder(child):
                     yield n
             yield node

 It works fine for small test trees. But, my tree has approximately 30 
 nodes, and shown post order traversal with generators takes 80 sec against 1 
 sec with simple recursive routine:

 def recursiveFromTop(node):
     for child in node.childs:
         recursiveFromTop(child)
         ## here I can do some computations with current node's data

 So, I'd like to know how should I implement (if it's possible of course) 
 __iter__ for my tree class based on recursion without generators? Please, can 
 You show me the ways?
 because I'm very passionate in idea iterate through my tree with simple:

 for node in tree:
    do something with node

 Thanks in Advance!
 Best Regards!
 Alex

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

Well, I think it's actually because the difference is that you would not do 
yielding, you would just put everything in memory and then return it.

ret_val = [x for x in self.postorder(child)]
return ret_val + [self]

or something like that (but beware of memory). But that's strange. This code 
works fast:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

def w(s):
sys.stdout.write(%s % s)
sys.stdout.flush()

class Node():
__slots__ = ('childs', 'value',)

def __init__(self, value):
self.childs = []
self.value = value

def post_order(self):
for child in self.childs:
yield child
yield self

def build_tree():
def append_1000_childs(node):
for i in xrange(20):
node.childs.append(Node(10))

def append_n_levels(node, levels=1):
if levels = 1:
append_1000_childs(node)
if levels  1:
for child in node.childs:
append_n_levels(child, levels - 1)

root = Node(10)
append_n_levels(root, 5)
return root

if __name__ == '__main__':
from datetime import datetime

w(building tree...)
_t = datetime.now()
root = build_tree()
w(done\n)
w(datetime.now() - _t)
w(\n)

w(doing generator post_order...)
_t = datetime.now()
for item in root.post_order():
fake = item.value
w(done\n)
w(datetime.now() - _t)
w(\n)

def post_order(root):
for child in root.childs:
post_order(child)
fake = item.value

w(doing non-generator post_order...)
_t = datetime.now()
post_order(root)
w(done\n)
w(datetime.now() - _t)
w(\n)

$ python postorder.py 
building tree...done
0:01:34.422288
doing generator post_order...done
0:00:00.18
doing non-generator post_order...done
0:00:01.232272

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread kost BebiX
14.01.2011, 14:15, Alex Boyko alex.kyr...@gmail.com:
 Dear All!

 I have deal with large unbalanced trees and I have to implement post-order 
 tree traversal. My first attempt is shown below (Node and Tree classes) 
 and based on recursive generators approach.

 class Node():
     def __init__(self,value):
         self.childs = []
         self.value = value

 class Tree():

     def __init__(self, root):
         self.root = root
         self.numberCells = 1

     def add(self, node, child):
         node.childs.append(child)
         self.numberCells+=1

     def __iter__(self):
         return self.postorder(self.root)

     def postorder(self, node):
         if node:
             for child in node.childs:
                 for n in self.postorder(child):
                     yield n
             yield node

 It works fine for small test trees. But, my tree has approximately 30 
 nodes, and shown post order traversal with generators takes 80 sec against 1 
 sec with simple recursive routine:

 def recursiveFromTop(node):
     for child in node.childs:
         recursiveFromTop(child)
         ## here I can do some computations with current node's data

 So, I'd like to know how should I implement (if it's possible of course) 
 __iter__ for my tree class based on recursion without generators? Please, can 
 You show me the ways?
 because I'm very passionate in idea iterate through my tree with simple:

 for node in tree:
    do something with node

 Thanks in Advance!
 Best Regards!
 Alex

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

Forgot to make new-style object)
class Node(object):

The results for new-style objects are:
$ python postorder.py 
building tree...done
0:00:26.180799
doing generator post_order...done
0:00:00.17
doing non-generator post_order...done
0:00:01.117986

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread kost BebiX
14.01.2011, 14:17, Alex Boyko alex.kyr...@gmail.com:
 Dear All!

 I have deal with large unbalanced trees and I have to implement post-order 
 tree traversal. My first attempt is shown below (Node and Tree classes) 
 and based on recursive generators approach.

 class Node():
     def __init__(self,value):
         self.childs = []
         self.value = value

 class Tree():

     def __init__(self, root):
         self.root = root
         self.numberCells = 1

     def add(self, node, child):
         node.childs.append(child)
         self.numberCells+=1

     def __iter__(self):
         return self.postorder(self.root)

     def postorder(self, node):
         if node:
             for child in node.childs:
                 for n in self.postorder(child):
                     yield n
             yield node

 It works fine for small test trees. But, my tree has approximately 30 
 nodes, and shown post order traversal with generators takes 80 sec against 1 
 sec with simple recursive routine:

 def recursiveFromTop(node):
     for child in node.childs:
         recursiveFromTop(child)
         ## here I can do some computations with current node's data

 So, I'd like to know how should I implement (if it's possible of course) 
 __iter__ for my tree class based on recursion without generators? Please, can 
 You show me the ways?
 because I'm very passionate in idea iterate through my tree with simple:

 for node in tree:
    do something with node

 Thanks in Advance!
 Best Regards!
 Alex

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

God damn pypy is fast))

$ ~/bin/pypy-1.4.1-linux64/bin/pypy ./postorder.py 
building tree...done
0:00:03.000854
doing generator post_order...done
0:00:00.69
doing non-generator post_order...done
0:00:00.240168

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread Stefan Behnel

leoboiko, 14.01.2011 14:06:

Of course I searched for one and couldn’t find; that goes without
saying.  Otherwise I wouldn’t even bother writing a message, isn’t
it?  I disagree people should cruft their messages with details about
how they failed to find information, as that is unrelated to the
question at hand and has no point other than polluting people’s
mailboxes.


http://www.catb.org/~esr/faqs/smart-questions.html#beprecise
http://www.catb.org/~esr/faqs/smart-questions.html#volume

Stefan

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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Stefan Behnel

Steven D'Aprano, 14.01.2011 01:15:

On Thu, 13 Jan 2011 12:45:31 -0800, leoboiko wrote:

Is there an equivalent to the textwrap module that knows about the
Unicode line breaking algorithm (UAX #14,
http://unicode.org/reports/tr14/ )?


Is access to Google blocked where you are, or would you just like us to
do your searches for you?

If you have tried searching, please say so, otherwise most people will
conclude you haven't bothered, and most likely will not bother to reply.


I think the OP was asking for something like the textwrap module (which 
the OP apparently knows about), but based on a special line break algorithm 
which, as suggested by the way the OP asks, is not supported by textwrap.


Sadly, the OP did not clearly state that the required feature is really not 
supported by textwrap and in what way textwrap behaves differently. That 
would have helped in answering.


Stefan

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


Re: [TIP] TestFixtures 1.8.0 Released!

2011-01-14 Thread Phlip
[ please set  the reply-to to testing-in-python@ !]

 The package is on PyPI and a full list of all the links to docs, issue
 trackers and the like can be found here:

 http://www.simplistix.co.uk/software/python/testfixtures

The number one problem with all the test fixture systems I ever
auditioned for Django models was unbelievable slowness.

Thats' a major bummer for TDD, because you should integrate after
every few edits, and a slow integration derails your flow. On a
project with 500 tests the complete run could be 5 minutes.

Some fixture systems use JSON to represent model values, and they pump
the JSON directly into SQL insert statements.

I was using farmdev's fixture system, and it was incredibly slow. It
also did not use raw SQL. It fully resolved all records into model
objects, and called save() on them.

(The extra round trip thru a model's validations would be nice - if we
were testing validations. That's what explicit tests are for!)

I rewrote the fixture loader, going direct to SQL, and got a major speed boost.

Then I rewrote it again, going directly from XML to our (very simple 
stereotypical) model objects, and called save(). The speed boost
remained. I have no idea what farmdev fixture was doing to slow things
down.

Anyway thanks for the library, but you can see I can't use its fixture
loader; I'm just putting this out here.

But does it do Django models, and are they performant?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread leoboiko
On Jan 14, 11:48 am, Stefan Behnel stefan...@behnel.de wrote:
 Sadly, the OP did not clearly state that the required feature
 is really not supported by textwrap and in what way textwrap
 behaves differently. That would have helped in answering.

Oh, textwrap doesn’t work for arbitrary Unicode text at all.  For
example, it separates combining sequences:

 s = tiếng Việt # precomposed
 len(s)
10
 s = tiếng Việt # combining
 len(s) # number of unicode characters; ≠ line length
14
 print(textwrap.fill(s, width=4)) # breaks sequences
tiê
ng
Viê
t

It also doesn’t know about double-width characters:

 s1 = 日本語のテキト
 s2 = 12345678901234 # both s1 and s2 use 14 columns
 print(textwrap.fill(s1, width=7))
日本語のテキト
 print(textwrap.fill(s2, width=7))
1234567
8901234

It doesn’t know about non-ascii punctuation:

 print(textwrap.fill(abc-def, width=5)) # ASCII minus-hyphen
abc-
def
 print(textwrap.fill(abc‐def, width=5)) # true hyphen U+2010
abc‐d
ef

It doesn’t know East Asian filling rules (though this is
perhaps pushing it a bit beyond textwrap’s goals):

 print(textwrap.fill(日本語、中国語, width=3))
日本語
、中国 # should avoid linebreak before CJK punctuation
語


And it generally doesn’t try to pick good places to break lines
at all, just making the assumption that 1 character = 1 column
and that breaking on ASCII whitespaces/hyphens is enough.  We
can’t really blame textwrap for that, it is a very simple module
and Unicode line breaking gets complex fast (that’s why the
consortium provides a ready-made algorithm).  It’s just that,
with python3’s emphasis on Unicode support, I was surprised not
to be able to find an UAX #14 implementation.  I thought someone
would surely have written one and I simply couldn’t find, so I
asked precisely that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TestFixtures 1.8.0 Released!

2011-01-14 Thread Jack Keegan
I'm new to python and have just been looking into a solution for Mocking
objects. In particular, at the moment, testing some code that needs to
access hardware IOs using DLLs. I do this using Ctypes.
However, on my dev machine, I don't have the same hardware so calling the
DLL functions will not work as expected. Therefore I'd like to mock out the
ctypes dll calls. Can you give me an indication of how you would go about
doing this with Simplistix? Just so you know, I use py.test for unit
testing.

Thanks,

Jack

On Fri, Jan 14, 2011 at 12:38 PM, Chris Withers ch...@simplistix.co.ukwrote:

 Hi All,

 I'm very happy to announce the first fully-documented release of
 TestFixtures, my collection of testing fixtures and helpers that I've been
 collecting for the last couple of years.

 Along with my own take on a lot of the common fixtures and helpers, it has
 some bits that I haven't seen anywhere else and so would like to point out:

 - Comparison objects for comparing objects that don't natively support
  comparison:

  http://packages.python.org/testfixtures/comparing.html#comparison-objects

 - Helpful mock objects for when you want to test code that makes use of
  datetime.datetime.now, datetime.date.today or time.time:

  http://packages.python.org/testfixtures/datetime.html

 - Helpers for capturing and checking messages logged from your code
  using the python logging framework:

  http://packages.python.org/testfixtures/logging.html

 - Helpers for working with temporary directories in tests. In
  particular, quickly and easily creating temporary directories and
  files within them and making assertions about things written to them
  by the code under test:

  http://packages.python.org/testfixtures/files.html

 There's plenty more in there too!

 Please do let me know what you find useful, if you find any bugs or if
 there are any features you'd like to see added.

 The package is on PyPI and a full list of all the links to docs, issue
 trackers and the like can be found here:

 http://www.simplistix.co.uk/software/python/testfixtures

 cheers,

 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TestFixtures 1.8.0 Released!

2011-01-14 Thread Jack Keegan
Appologies, please read the 2nd last line as:
Can you give me an indication of how you would go about doing this with
TestFixtures? :)

Thanks

Jack


On Fri, Jan 14, 2011 at 2:39 PM, Jack Keegan whatsjacksem...@gmail.comwrote:

 I'm new to python and have just been looking into a solution for Mocking
 objects. In particular, at the moment, testing some code that needs to
 access hardware IOs using DLLs. I do this using Ctypes.
 However, on my dev machine, I don't have the same hardware so calling the
 DLL functions will not work as expected. Therefore I'd like to mock out the
 ctypes dll calls. Can you give me an indication of how you would go about
 doing this with Simplistix? Just so you know, I use py.test for unit
 testing.

 Thanks,

 Jack

 On Fri, Jan 14, 2011 at 12:38 PM, Chris Withers ch...@simplistix.co.ukwrote:

 Hi All,

 I'm very happy to announce the first fully-documented release of
 TestFixtures, my collection of testing fixtures and helpers that I've been
 collecting for the last couple of years.

 Along with my own take on a lot of the common fixtures and helpers, it has
 some bits that I haven't seen anywhere else and so would like to point out:

 - Comparison objects for comparing objects that don't natively support
  comparison:


 http://packages.python.org/testfixtures/comparing.html#comparison-objects

 - Helpful mock objects for when you want to test code that makes use of
  datetime.datetime.now, datetime.date.today or time.time:

  http://packages.python.org/testfixtures/datetime.html

 - Helpers for capturing and checking messages logged from your code
  using the python logging framework:

  http://packages.python.org/testfixtures/logging.html

 - Helpers for working with temporary directories in tests. In
  particular, quickly and easily creating temporary directories and
  files within them and making assertions about things written to them
  by the code under test:

  http://packages.python.org/testfixtures/files.html

 There's plenty more in there too!

 Please do let me know what you find useful, if you find any bugs or if
 there are any features you'd like to see added.

 The package is on PyPI and a full list of all the links to docs, issue
 trackers and the like can be found here:

 http://www.simplistix.co.uk/software/python/testfixtures

 cheers,

 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
 --
 http://mail.python.org/mailman/listinfo/python-list




 --
 The earth is a very small stage in a vast cosmic arena. Think of the rivers
 of blood spilled by all those generals and emperors so that in glory and in
 triumph they could become the momentary masters of a fraction of a dot.
 - Carl Sagan [Pale Blue Dot]




-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TestFixtures 1.8.0 Released!

2011-01-14 Thread Chris Withers

Hi Jack,

On 14/01/2011 14:39, Jack Keegan wrote:

objects. In particular, at the moment, testing some code that needs to
access hardware IOs using DLLs. I do this using Ctypes.
However, on my dev machine, I don't have the same hardware so calling
the DLL functions will not work as expected. Therefore I'd like to mock
out the ctypes dll calls. Can you give me an indication of how you would
go about doing this with TestFixtures? Just so you know, I use py.test for
unit testing.


I've not used ctypes myself so let me know if things don't work ;-)

I'd suggest developing mock objects to work in place of your ctypes 
objects. You may well find that if you're just wanting to test that the 
right calls are made you can use an existing mock objects such as:


http://pypi.python.org/pypi/mock/

...and then compare the method_calls attribute of the mock with what you 
expect it to be.


TestFixtures provides some handy tools for managing the insertion and 
removal of mock objects, read here:


http://packages.python.org/testfixtures/mocking.html

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: TestFixtures 1.8.0 Released!

2011-01-14 Thread Jack Keegan
Hi Chris,

Thanks for that. I'll give it a go.

Cheers,

Jack

On Fri, Jan 14, 2011 at 2:49 PM, Chris Withers ch...@simplistix.co.ukwrote:

 Hi Jack,


 On 14/01/2011 14:39, Jack Keegan wrote:

 objects. In particular, at the moment, testing some code that needs to
 access hardware IOs using DLLs. I do this using Ctypes.
 However, on my dev machine, I don't have the same hardware so calling
 the DLL functions will not work as expected. Therefore I'd like to mock
 out the ctypes dll calls. Can you give me an indication of how you would
 go about doing this with TestFixtures? Just so you know, I use py.test for
 unit testing.


 I've not used ctypes myself so let me know if things don't work ;-)

 I'd suggest developing mock objects to work in place of your ctypes
 objects. You may well find that if you're just wanting to test that the
 right calls are made you can use an existing mock objects such as:

 http://pypi.python.org/pypi/mock/

 ...and then compare the method_calls attribute of the mock with what you
 expect it to be.

 TestFixtures provides some handy tools for managing the insertion and
 removal of mock objects, read here:

 http://packages.python.org/testfixtures/mocking.html


 cheers,

 Chris

 --
 Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk




-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FTP problem

2011-01-14 Thread Anurag Chourasia
Please make the below change to get past this problem

Change

*ftp.*indexftp.barcap.com

to

indexftp.barcap.com

Regards,
Anurag

On Fri, Jan 14, 2011 at 5:25 PM, Thomas Philips tkp...@gmail.com wrote:

 I'm using ftplib for the first time, and am having trouble getting it
 to work. I type

  from ftplib import FTP
  ftp = FTP('ftp.indexftp.barcap.com', 'A Valid Username', ' A Valid
 Password')

 where I have suppressed the user name and password, and I get

 Traceback (most recent call last):
  File pyshell#2, line 1, in module
ftp = FTP('ftp.indexftp.barcap.com')
  File C:\Python26\lib\ftplib.py, line 116, in __init__
self.connect(host)
  File C:\Python26\lib\ftplib.py, line 131, in connect
self.sock = socket.create_connection((self.host, self.port),
 self.timeout)
  File C:\Python26\lib\socket.py, line 498, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
 gaierror: [Errno 11001] getaddrinfo failed

 I have tried this on two different computers and on two different
 versions of Python (2.6 and 2.7). I get the same error both times, and
 have no understanding of what the problem might be. Any assistance
 would be greatly appreciated.

 Sincerely

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

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


Is it possible to let a virtual file created by cStringIO have a filename so that functions can read it by its filename?

2011-01-14 Thread Cun Zhang
Hi,all
I hope use cStringIO to create virtual file, but my customed function which
is from a shared library imported by ctypes
just accepts a filename(string type) as parameter.

So I'm wondering whether there is any method that make the virtual file
created by cStringIO like a normal file which have

a filename, so it can be called by my functions.



Thank you!

Yours,

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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Steven D'Aprano
On Fri, 14 Jan 2011 05:06:15 -0800, leoboiko wrote:

 Of course I searched for one and couldn’t find; that goes without
 saying.  Otherwise I wouldn’t even bother writing a message, isn’t it? 

You wouldn't say that if you had the slightest idea about how many people 
write to newsgroups and web forums asking for help without making the 
tiniest effort to solve the problem themselves. So, no, it *doesn't* go 
without saying -- unless, of course, you want the answer to also go 
without saying.


 I disagree people should cruft their messages with details about how
 they failed to find information, as that is unrelated to the question at
 hand and has no point other than polluting people’s mailboxes.

This is total nonsense -- how on earth can you say that it is unrelated 
to the question you are asking? It tells others what they should not 
waste their time trying, because you've already tried it. You don't need 
to write detailed step-by-step instructions of everything you've tried, 
but you can point us in the directions you've already traveled.

Think of it this way... if you were paying money for professional advice, 
would you be happy to receive a bill for time spent doing the exact same 
things you have already tried? I'm sure you wouldn't be. So why do you 
think it is okay to waste the time of unpaid volunteers? That's just 
thoughtless and selfish.

If you think so little of other people's time that you won't even write a 
few words to save them from going down the same dead-ends that you've 
already tried, then don't be surprised if they think so little of your 
time that they don't bother replying even when they know the answer.

 I also see no reason to reply to a simple question with such
 discourtesy, and cannot understand why someone would be so aggressive to
 a stranger.

If you think my reply was aggressive and discourteous, you've got a lot 
to learn about public forums.


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


Re: unbalanced tree iteration issue

2011-01-14 Thread Alex Boyko
Thank you for your reply, but I have question about your code. Your defined:

   def post_order(self):
   for child in self.childs:
   yield child
   yield self

just for Node , not for Tree, and do

   w(doing generator post_order...)
   _t = datetime.now()
   for item in root.post_order():
   fake = item.value
   w(done\n)
   w(datetime.now() - _t)
   w(\n)

what give us only iterating along root's children, not iterating along
tree...Or I didn't catch your though?

Best Regards
Alex

2011/1/14 kost BebiX k...@ya.ru

 14.01.2011, 14:15, Alex Boyko alex.kyr...@gmail.com:
  Dear All!
 
  I have deal with large unbalanced trees and I have to implement
 post-order tree traversal. My first attempt is shown below (Node and
 Tree classes) and based on recursive generators approach.
 
  class Node():
  def __init__(self,value):
  self.childs = []
  self.value = value
 
  class Tree():
 
  def __init__(self, root):
  self.root = root
  self.numberCells = 1
 
  def add(self, node, child):
  node.childs.append(child)
  self.numberCells+=1
 
  def __iter__(self):
  return self.postorder(self.root)
 
  def postorder(self, node):
  if node:
  for child in node.childs:
  for n in self.postorder(child):
  yield n
  yield node
 
  It works fine for small test trees. But, my tree has approximately 30
 nodes, and shown post order traversal with generators takes 80 sec against 1
 sec with simple recursive routine:
 
  def recursiveFromTop(node):
  for child in node.childs:
  recursiveFromTop(child)
  ## here I can do some computations with current node's data
 
  So, I'd like to know how should I implement (if it's possible of course)
 __iter__ for my tree class based on recursion without generators? Please,
 can You show me the ways?
  because I'm very passionate in idea iterate through my tree with simple:
 
  for node in tree:
 do something with node
 
  Thanks in Advance!
  Best Regards!
  Alex
 
  --
  http://mail.python.org/mailman/listinfo/python-list

 Well, I think it's actually because the difference is that you would not do
 yielding, you would just put everything in memory and then return it.

 ret_val = [x for x in self.postorder(child)]
 return ret_val + [self]

 or something like that (but beware of memory). But that's strange. This
 code works fast:

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 import sys

 def w(s):
sys.stdout.write(%s % s)
sys.stdout.flush()

 class Node():
__slots__ = ('childs', 'value',)

def __init__(self, value):
self.childs = []
self.value = value

 def post_order(self):
for child in self.childs:
yield child
yield self

 def build_tree():
def append_1000_childs(node):
for i in xrange(20):
node.childs.append(Node(10))

def append_n_levels(node, levels=1):
if levels = 1:
append_1000_childs(node)
if levels  1:
 for child in node.childs:
 append_n_levels(child, levels - 1)

root = Node(10)
append_n_levels(root, 5)
return root

 if __name__ == '__main__':
from datetime import datetime

w(building tree...)
_t = datetime.now()
root = build_tree()
w(done\n)
w(datetime.now() - _t)
w(\n)

w(doing generator post_order...)
_t = datetime.now()
for item in root.post_order():
fake = item.value
w(done\n)
w(datetime.now() - _t)
w(\n)

def post_order(root):
for child in root.childs:
post_order(child)
fake = item.value

w(doing non-generator post_order...)
_t = datetime.now()
post_order(root)
w(done\n)
w(datetime.now() - _t)
w(\n)

 $ python postorder.py
 building tree...done
 0:01:34.422288
 doing generator post_order...done
 0:00:00.18
 doing non-generator post_order...done
 0:00:01.232272

 --
 jabber: k...@ya.ru

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


Re: unbalanced tree iteration issue

2011-01-14 Thread Alex Boyko
So I mean, your approach with generators showed good results in terms of
time efficiency 'cos iteration was done for root and root's  children.

On 14 January 2011 18:57, Alex Boyko alex.kyr...@gmail.com wrote:

 Thank you for your reply, but I have question about your code. Your
 defined:

def post_order(self):
for child in self.childs:
yield child
yield self

 just for Node , not for Tree, and do

w(doing generator post_order...)
_t = datetime.now()
for item in root.post_order():
fake = item.value
w(done\n)
w(datetime.now() - _t)
w(\n)

 what give us only iterating along root's children, not iterating along
 tree...Or I didn't catch your though?

 Best Regards
 Alex

 2011/1/14 kost BebiX k...@ya.ru

 14.01.2011, 14:15, Alex Boyko alex.kyr...@gmail.com:
  Dear All!
 
  I have deal with large unbalanced trees and I have to implement
 post-order tree traversal. My first attempt is shown below (Node and
 Tree classes) and based on recursive generators approach.
 
  class Node():
  def __init__(self,value):
  self.childs = []
  self.value = value
 
  class Tree():
 
  def __init__(self, root):
  self.root = root
  self.numberCells = 1
 
  def add(self, node, child):
  node.childs.append(child)
  self.numberCells+=1
 
  def __iter__(self):
  return self.postorder(self.root)
 
  def postorder(self, node):
  if node:
  for child in node.childs:
  for n in self.postorder(child):
  yield n
  yield node
 
  It works fine for small test trees. But, my tree has approximately
 30 nodes, and shown post order traversal with generators takes 80 sec
 against 1 sec with simple recursive routine:
 
  def recursiveFromTop(node):
  for child in node.childs:
  recursiveFromTop(child)
  ## here I can do some computations with current node's data
 
  So, I'd like to know how should I implement (if it's possible of course)
 __iter__ for my tree class based on recursion without generators? Please,
 can You show me the ways?
  because I'm very passionate in idea iterate through my tree with simple:
 
  for node in tree:
 do something with node
 
  Thanks in Advance!
  Best Regards!
  Alex
 
  --
  http://mail.python.org/mailman/listinfo/python-list

 Well, I think it's actually because the difference is that you would not
 do yielding, you would just put everything in memory and then return it.

 ret_val = [x for x in self.postorder(child)]
 return ret_val + [self]

 or something like that (but beware of memory). But that's strange. This
 code works fast:

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 import sys

 def w(s):
sys.stdout.write(%s % s)
sys.stdout.flush()

 class Node():
__slots__ = ('childs', 'value',)

def __init__(self, value):
self.childs = []
self.value = value

 def post_order(self):
for child in self.childs:
yield child
yield self

 def build_tree():
def append_1000_childs(node):
for i in xrange(20):
node.childs.append(Node(10))

def append_n_levels(node, levels=1):
if levels = 1:
append_1000_childs(node)
if levels  1:
 for child in node.childs:
 append_n_levels(child, levels - 1)

root = Node(10)
append_n_levels(root, 5)
return root

 if __name__ == '__main__':
from datetime import datetime

w(building tree...)
_t = datetime.now()
root = build_tree()
w(done\n)
w(datetime.now() - _t)
w(\n)

w(doing generator post_order...)
_t = datetime.now()
for item in root.post_order():
fake = item.value
w(done\n)
w(datetime.now() - _t)
w(\n)

def post_order(root):
for child in root.childs:
post_order(child)
fake = item.value

w(doing non-generator post_order...)
_t = datetime.now()
post_order(root)
w(done\n)
w(datetime.now() - _t)
w(\n)

 $ python postorder.py
 building tree...done
 0:01:34.422288
 doing generator post_order...done
 0:00:00.18
 doing non-generator post_order...done
 0:00:01.232272

 --
 jabber: k...@ya.ru



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


Re: unbalanced tree iteration issue

2011-01-14 Thread Ian Kelly
On Fri, Jan 14, 2011 at 5:15 AM, Alex Boyko alex.kyr...@gmail.com wrote:
 So, I'd like to know how should I implement (if it's possible of course)
 __iter__ for my tree class based on recursion without generators?

You could try something like this (untested):

from itertools import chain, imap

...

def postorder(self, node):
return chain(chain.from_iterable(imap(self.postorder,
node.childs)), [node])


Or you could write the iterator the old-fashioned way, as an object
with state (also untested):

def __iter__(self):
return PostOrderIter(self.root)

class PostOrderIter(object):

def __iter__(self, node):
self.stack = [(node, 0)]

def next(self):
if not self.stack:
raise StopIteration
node, index = self.stack.pop()
if index  len(node.childs):
child = node.childs[index]
self.stack.append((node, index+1))
self.stack.append((child, 0))
return self.next()
else:
return node
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread kost BebiX
14.01.2011, 18:57, Alex Boyko alex.kyr...@gmail.com:
 2011/1/14 kost BebiX k...@ya.ru
 14.01.2011, 14:15, Alex Boyko alex.kyr...@gmail.com:

 Dear All!

 I have deal with large unbalanced trees and I have to implement post-order 
 tree traversal. My first attempt is shown below (Node and Tree classes) 
 and based on recursive generators approach.

 class Node():
     def __init__(self,value):
         self.childs = []
         self.value = value

 class Tree():

     def __init__(self, root):
         self.root = root
         self.numberCells = 1

     def add(self, node, child):
         node.childs.append(child)
         self.numberCells+=1

     def __iter__(self):
         return self.postorder(self.root)

     def postorder(self, node):
         if node:
             for child in node.childs:
                 for n in self.postorder(child):
                     yield n
             yield node

 It works fine for small test trees. But, my tree has approximately 30 
 nodes, and shown post order traversal with generators takes 80 sec against 
 1 sec with simple recursive routine:

 def recursiveFromTop(node):
     for child in node.childs:
         recursiveFromTop(child)
         ## here I can do some computations with current node's data

 So, I'd like to know how should I implement (if it's possible of course) 
 __iter__ for my tree class based on recursion without generators? Please, 
 can You show me the ways?
 because I'm very passionate in idea iterate through my tree with simple:

 for node in tree:
    do something with node

 Thanks in Advance!
 Best Regards!
 Alex


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

 Well, I think it's actually because the difference is that you would not do 
 yielding, you would just put everything in memory and then return it.

 ret_val = [x for x in self.postorder(child)]
 return ret_val + [self]

 or something like that (but beware of memory). But that's strange. This code 
 works fast:

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 import sys

 def w(s):
    sys.stdout.write(%s % s)
    sys.stdout.flush()

 class Node():
    __slots__ = ('childs', 'value',)

    def __init__(self, value):
        self.childs = []
        self.value = value

    def post_order(self):
        for child in self.childs:
            yield child
        yield self

 def build_tree():
    def append_1000_childs(node):
        for i in xrange(20):
            node.childs.append(Node(10))

    def append_n_levels(node, levels=1):
        if levels = 1:
            append_1000_childs(node)
            if levels  1:
                for child in node.childs:

                    append_n_levels(child, levels - 1)

    root = Node(10)
    append_n_levels(root, 5)
    return root

 if __name__ == '__main__':
    from datetime import datetime

    w(building tree...)
    _t = datetime.now()
    root = build_tree()
    w(done\n)
    w(datetime.now() - _t)
    w(\n)

    w(doing generator post_order...)
    _t = datetime.now()
    for item in root.post_order():
        fake = item.value
    w(done\n)
    w(datetime.now() - _t)
    w(\n)

    def post_order(root):
        for child in root.childs:
            post_order(child)
            fake = item.value

    w(doing non-generator post_order...)
    _t = datetime.now()
    post_order(root)
    w(done\n)
    w(datetime.now() - _t)
    w(\n)

 $ python postorder.py
 building tree...done
 0:01:34.422288
 doing generator post_order...done
 0:00:00.18
 doing non-generator post_order...done
 0:00:01.232272

 --
 jabber: k...@ya.ru
 Thank you for your reply, but I have question about your code. Your defined:

def post_order(self):
for child in self.childs:
yield child
yield self

 just for Node , not for Tree, and do

w(doing generator post_order...)
_t = datetime.now()
for item in root.post_order():
fake = item.value
w(done\n)
w(datetime.now() - _t)
w(\n)

 what give us only iterating along root's children, not iterating along 
 tree...Or I didn't catch your though?

 Best Regards
 Alex


Well, isn't tree is a root node and it's children? Why do you need Tree class 
anyway?

p.s.: please, do not top-post the messages, write your reply at bottom because 
it will then be easier to read for those who will google this page.

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread Ian Kelly
On Fri, Jan 14, 2011 at 11:07 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 class PostOrderIter(object):

    def __iter__(self, node):
        self.stack = [(node, 0)]

That __iter__ should actually be __init__, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread Ian Kelly
2011/1/14 kost BebiX k...@ya.ru:
 Well, isn't tree is a root node and it's children?

And its grandchildren, great-grandchildren, etc.  What Alex is saying
is that the implementation you posted traverses the root and its
immediate children, but does not recur any further than that.  That is
why it was so fast.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unbalanced tree iteration issue

2011-01-14 Thread kost BebiX
14.01.2011, 20:19, Ian Kelly ian.g.ke...@gmail.com:
 2011/1/14 kost BebiX k...@ya.ru;:

  Well, isn't tree is a root node and it's children?

 And its grandchildren, great-grandchildren, etc.  What Alex is saying
 is that the implementation you posted traverses the root and its
 immediate children, but does not recur any further than that.  That is
 why it was so fast.

Oh, yeah, sorry, forgot the recursion. It should be (if I'm not wrong again):

def post_order(self):
for child in self.childs:
for po in child.post_order():
yield po
yield self

if you give it more deepness:

$ python postorder.py 
building tree...done
0:00:25.839462
doing generator post_order...done
0:00:02.776876
doing non-generator post_order...done
0:00:01.092648

still not bad, but if you'll give it more deepness

$ python postorder.py 
building tree...done
0:00:16.078972
doing generator post_order...done
0:00:03.119023
doing non-generator post_order...done
0:00:00.841976

it will be worse

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to use priority queue with multiprocessing

2011-01-14 Thread John Nagle

On 1/13/2011 9:07 AM, Marco Hornung wrote:

Hey,

--



question

--


How can I use a priority queue to schedule jobs within the 
multiprocessing pool module?


--



my scenario

--


I want to run several jobs on a server. The jobs are being sent by 
users. However, all jobs have a different priority, and high-priority 
jobs should be processed before any low-priority job gets touched.

Currently I just append all incoming jobs to the multiprocessing
worker pool as follows: ### initialize worker pool pool =
PriorityPool(processes=worker_count) process_handles = []

### distribute function execution over several processes for
job_parameter in job_parameter_list: handle =
pool.apply_async(process_function, [job_parameter,])
process_handles.append(handle)

This will only put the jobs in some kind of a list - and execute the
jobs in the order they come in. Is it possible to use a priority
queue for the process-pool?



   You''ll probably have to track the available processes yourself,
starting a new job when there's a process available.

   One way to do this is to have a management thread for each
process.  Each management thread starts a subprocess, gets
a work item from the priority queue (blocking if necessary),
gives it to the subprocess, waits for the subprocess to
return a result, and goes back to get another work item.

   This is straightforward, except for working out a way
to cleanly shut the thing down.  One way to do that is
to have a shutdown flag visible to all the threads.
That's checked before getting a new task.  If it's set,
the thread terminates its subprocess and returns.
Set the terminate flag in a signal handler for control-C.

   (I have something that manages multiple processes
using a priority queue, where the queue is implemented
using MySQL.  This allows me to put a whole cluster to
work.)

John Nagle

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


Developing a program to make a family tree.

2011-01-14 Thread Ata Jafari
Hi there.
I'm trying to develop a program like family tree maker. I have all
information, so there is no need to search on the net. This must be
something like trees. Can someone help me? I'm at the beginning.
Thanks.

--
Ata J. Tabrizi
atae.tabr...@metu.edu.tr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread Antoine Pitrou

Hey,

On 14 Jan 2011 16:07:12 GMT
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 
  I also see no reason to reply to a simple question with such
  discourtesy, and cannot understand why someone would be so aggressive to
  a stranger.
 
 If you think my reply was aggressive and discourteous, you've got a lot 
 to learn about public forums.

Perhaps you've got to learn about politeness yourself! Just because
some people are jerks on internet forums (or in real life) doesn't mean
everyone should; this is quite a stupid and antisocial excuse actually.

You would never have reacted this way if the same question had been
phrased by a regular poster here (let alone on python-dev). Taking
cheap shots at newcomers is certainly not the best way to welcome
them.

Thank you

Antoine.


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


Elliptic Curve Prime factorisation

2011-01-14 Thread mukesh tiwari
Hello all , I have implemented Elliptic curve prime factorisation
using wikipedia [ 
http://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization].
I think that this code is not optimised and posting for further
improvement. Feel free to comment and if you have any link regarding
Elliptic curve prime factorisation , kindly post it.
Thank you

import math
import random

#y^2=x^3+ax+b mod n

def extended_gcd(a,b):   # taken from wikipedia
x,y,lastx,lasty=0,1,1,0
while b!=0:
q=a/b
a,b=b,a%b
x,lastx=(lastx-q*x,x)
y,lasty=(lasty-q*y,y)
if a0:
return (-a,-lastx,-lasty)
else:
return (a,lastx,lasty)
def gcd(a,b):
if a  0:  a = -a
if b  0:  b = -b
if a == 0: return b
if b == 0: return a
while b != 0:
(a, b) = (b, a%b)
return a

def randomCurve(N):
A,u,v=random.randrange(N),random.randrange(N),random.randrange(N)
B=(v*v-u*u*u-A*u)%N
return [(A,B,N),(u,v)]

def addPoint(E,p_1,p_2):
if p_1==Identity: return [p_2,1]
if p_2==Identity: return [p_1,1]
a,b,n=E
(x_1,y_1)=p_1
(x_2,y_2)=p_2
x_1%=n
y_1%=n
x_2%=n
y_2%=n
if x_1 != x_2 :
d,u,v=extended_gcd(x_1-x_2,n)
s=((y_1-y_2)*u)%n
x_3=(s*s-x_1-x_2)%n
y_3=(-y_1-s*(x_3-x_1))%n
else:
if (y_1+y_2)%n==0:return [Identity,1]
else:
d,u,v=extended_gcd(2*y_1,n)
s=((3*x_1*x_1+a)*u)%n
x_3=(s*s-2*x_1)%n
y_3=(-y_1-s*(x_3-x_1))%n

return [(x_3,y_3),d]

def mulPoint(E,P,m):
Ret=Identity
d=1
while m!=0:
if m%2!=0: Ret,d=addPoint(E,Ret,P)
if d!=1 : return [Ret,d]  # as soon as i got anything otherthan 
1
return
P,d=addPoint(E,P,P)
if d!=1 : return [Ret,d]
m=1
return [Ret,d]




def ellipticFactor(N,m,times=5):
for i in xrange(times):
E,P=randomCurve(N);
Q,d=mulPoint(E,P,m)
if d!=1 : return d
return N

if __name__==__main__:
n=input()
m=int(math.factorial(1000))
while n!=1:
k=ellipticFactor(n,m)
n/=k
print k

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


Re: Developing a program to make a family tree.

2011-01-14 Thread Jon Clements
On Jan 14, 7:39 pm, Ata Jafari a.j.romani...@gmail.com wrote:
 Hi there.
 I'm trying to develop a program like family tree maker. I have all
 information, so there is no need to search on the net. This must be
 something like trees. Can someone help me? I'm at the beginning.
 Thanks.

 --
 Ata J. Tabrizi
 atae.tabr...@metu.edu.tr

If you're after mature and actively developed Genealogy software
developed in Python, then check out http://gramps-project.org/
The developer list is very friendly.

Otherwise, you're in for a struggle, as you need to choose a storage
back-end, a GUI (wxWindows/GTK/Qt4 etc...), how to handle GEDCOM
format (unless it's not going to be compatible with other software),
does it need to produce web pages/reports (and in what formats).

I strongly suggest looking at GRAMPS and see what you're setting
yourself up for :)

hth

Jon

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


Re: how to use priority queue with multiprocessing

2011-01-14 Thread Adam Tauno Williams
On Fri, 2011-01-14 at 10:57 -0800, John Nagle wrote: 
 On 1/13/2011 9:07 AM, Marco Hornung wrote:
 I want to run several jobs on a server. The jobs are being sent by 
 users. However, all jobs have a different priority, and high-priority 
 jobs should be processed before any low-priority job gets touched.
  Currently I just append all incoming jobs to the multiprocessing
  worker pool as follows: ### initialize worker pool pool 
  =
  PriorityPool(processes=worker_count) process_handles = []
  ### distribute function execution over several processes for
  job_parameter in job_parameter_list: handle =
  pool.apply_async(process_function, [job_parameter,])
  process_handles.append(handle)
  This will only put the jobs in some kind of a list - and execute the
  jobs in the order they come in. Is it possible to use a priority
  queue for the process-pool?
 You''ll probably have to track the available processes yourself,
 starting a new job when there's a process available.

Which is exactly what we do in OpenGroupwre Coils' OIE.

There is a process [job] list which is sorted by priority and the next
available process is started when a worker is available.  We use
multiprocessing to create a *process*, rather than a thread, for each
job.

 One way to do this is to have a management thread for each
 process.  Each management thread starts a subprocess, gets
 a work item from the priority queue (blocking if necessary),
 gives it to the subprocess, waits for the subprocess to
 return a result, and goes back to get another work item.

We have a manager process and an executor process.  These communicate
via AMQ, but you could use any mechanism.  The manager process controls
the process [job] list.  When a process needs to be started a message is
send to the executor which creates a worker process if an opening is
available.  Otherwise it messages the manager process to place the
process in a queued state.  When a worker process completes it messages
the executor which in turn messages the manager that a process slot may
be available; then the manager looks up the next available process and
messages the executor to start it - provided a worker slot is still
available the executor will start the worker [otherwise the process
will go back into a queued state]. 

 This is straightforward, except for working out a way
 to cleanly shut the thing down.  One way to do that is
 to have a shutdown flag visible to all the threads.

Using a message bus helps a lot, and with multiprocessing you just do a
join/isalive to make sure a worker is still working.

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


Re: Is it possible to let a virtual file created by cStringIO have a filename so that functions can read it by its filename?

2011-01-14 Thread Chris Rebert
On Fri, Jan 14, 2011 at 7:52 AM, Cun Zhang apzc2...@gmail.com wrote:
 Hi,all
 I hope use cStringIO to create virtual file, but my customed function which
 is from a shared library imported by ctypes
 just accepts a filename(string type) as parameter.

 So I'm wondering whether there is any method that make the virtual file
 created by cStringIO like a normal file which have
 a filename, so it can be called by my functions.

That's not possible. (c)StringIO presents a file-like interface at the
Python level, but under the covers, it's not implemented using
anything like a normal file; thus, it doesn't have a presence on any
filesystem. I would suggest using a temporary file
(http://docs.python.org/library/tempfile.html ) for communicating with
the C module, writing the contents of the StringIO object to the
temporary file if necessary.
(It's probably also possible to hack something together with FUSE, but
it'd be a slow, platform-specific kludge.)

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: The good, the bad, and the ugly!

2011-01-14 Thread Albert van der Horst
In article fe37271c-793d-4018-ac70-6db528270...@f30g2000yqa.googlegroups.com,
Adam Skutt  ask...@gmail.com wrote:
SNIP

Replacing TkInter with some sort of minimized wxwidgets is a dumb idea
for some very obvious reasons, reasons that are obvious if you simply
look at a widget gallery and then the applications you run on your own
computer.  Quite honestly, if you're not capable of that, there's
little reason to believe you'll ever be able to bring forth a
coherent, cogent proposal.

I really don't follow that. You need a tremendous set to write gimp.
Obviously you won't write gimp in Python.

Now you want to jot together three cooperating screens to specify
some properties for say bluetooth. The proposed set is ample for
that, no?
Such things make up a substantial part of the applications
as far as numbers is concerned. They are probably written by
people who don't want to dive very deeply into GUI.
(Maybe they are more bluetooth experts than GUI-experts, what
would you say?)


Adam

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Colin J. Williams

On 14-Jan-11 14:47 PM, Antoine Pitrou wrote:


Hey,

On 14 Jan 2011 16:07:12 GMT
Steven D'Apranosteve+comp.lang.pyt...@pearwood.info  wrote:



I also see no reason to reply to a simple question with such
discourtesy, and cannot understand why someone would be so aggressive to
a stranger.


If you think my reply was aggressive and discourteous, you've got a lot
to learn about public forums.


Perhaps you've got to learn about politeness yourself! Just because
some people are jerks on internet forums (or in real life) doesn't mean
everyone should; this is quite a stupid and antisocial excuse actually.

You would never have reacted this way if the same question had been
phrased by a regular poster here (let alone on python-dev). Taking
cheap shots at newcomers is certainly not the best way to welcome
them.

Thank you

Antoine.



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


do you know what's CGI? (web history personal story)

2011-01-14 Thread Xah Lee
some extempore thought.

Do you know what is CGI?

Worked with Mathematica for 5 hours yesterday. Fantastic! This old
hand can still do something! lol. My plane curve packages soon to be
out n am gonna be rich.

...gosh what godly hours i've spend on Mathematica in 1990s. Surprised
to find that i even Unproctected builtin symbols to fix things. (get
rid of asymptotes in ParametricPlot) (Draft notes as i go: Mathematica
Version 3 to Version 7 Conversion Notes)

... i recall, i stopped doing Mathematica in 1998 because it's a
career dead-end as a programing lang, and dived into the utterly
idiotic Perl  unix  mysql world. (See: The Unix Pestilence ◇ Xah
Lee's Computing Experience (Impression Of Lisp from Mathematica).)

Well, dead-end just as Emacs Lisp i'm spending my nights with in the
past 4 years. LOL. And on that note, same thing can be said with
haskell, OCaml.

Though, fringe langs are picking up these days. Remember Python, ruby,
in year 2000? Who'd imagined they'd become mainstream. But it took 10+
years. (See: Language, Purity, Cult, and Deception.)

Also got reminded my age recently. Someone on stackoverflow is asking
about what are those “A:” and “B:” drives on Windows. (anyone heard of
floppy drives?) In another incident, i was chatting to a friend, and
the topic went to internet tech in 1990s, and i was telling him about
how PHP (aka Pretty Home Page) came about, then naturally i discussed
CGI. After a while, i realized, those who are around 20 years old
today were under 10 in the 1990s. They wouldn't know what was CGI, and
no amount of explanation can tell them exactly it was like, because it
has become HISTORY — if you didn't live it, you can't feel it.

http://xahlee.blogspot.com/2011/01/do-you-know-what-is-cgi.html

 Xah ∑ http://xahlee.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: The good, the bad, and the ugly!

2011-01-14 Thread geremy condra
On Wed, Dec 29, 2010 at 5:03 PM, rantingrick rantingr...@gmail.com wrote:
 On Dec 29, 6:41 pm, Gerry Reno gr...@verizon.net wrote:

 Also, what do you think about frameworks such as pyjamas?  It lets you
 write in python and compiles everything down to Javascript so it can be
 used across the Web as well as on the desktop.

 Hmm, this is like two double edged swords smashing one another in
 battle.

Seriously, get off of WoW and go write some code. If you'd spent the
last year programming instead of doing your best Xah Lee impression
you might have actually made some progress on this.

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


Re: Python use growing fast

2011-01-14 Thread John Ladasky
On Jan 10, 1:43 pm, Alice Bevan–McGregor al...@gothcandy.com wrote:
 On 2011-01-10 13:02:09 -0800, MRAB said:

 Wikipedia is a Wiki; everyone is free to contribute and correct mistakes.

         - Alice.

Except for some of us.

I tried to make a correction to a chemistry Wikipedia entry several
months back.  I received a message saying that a series of IP
addresses which happen to include the one that my ISP assigned me had
been blocked, due to hacking problems.  Wikipedia provided a link to
contact a real human being to request that an address be unblocked.  I
submitted a request, and -- nothing happened.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx Just Print!

2011-01-14 Thread Miki
I think you need to create a wxApp first. Try adding app = wx.PySimpleApp() at 
the beginning.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread Steven D'Aprano
On Fri, 14 Jan 2011 20:47:35 +0100, Antoine Pitrou wrote:

 You would never have reacted this way if the same question had been
 phrased by a regular poster here (let alone on python-dev). Taking cheap
 shots at newcomers is certainly not the best way to welcome them.

You're absolutely correct. Regular posters have demonstrated their 
ability to perform the basics -- if you had asked the question, I could 
assume that you would have done a google search, because I know you're 
not a lazy n00b who expects others to do their work for them. But the 
Original Poster has not, as far as I can see, ever posted here before. He 
has no prior reputation and gives no detail in his post.

You have focused on my first blunt remark, and ignored the second:

If you have tried searching, please say so, otherwise most people will 
conclude you haven't bothered, and most likely will not bother to reply.

This is good, helpful advice, and far more useful to the OP than just 
ignoring his post. You have jumped to his defense (or rather, you have 
jumped to criticise me) but I see that you haven't replied to his 
question or given him any advice in how to solve his problem. Instead of 
encouraging him to ask smarter questions, you encourage the behaviour 
that hinders his ability to get help from others.

The only other person I can see who has attempted to actually help the OP 
is Stefan Behnel, who tried to get more information about the problem 
being solved in order to better answer the question. The OP has, so far 
as I can see, not responded, although he has taken the time to write to 
me in private to argue further.


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


Re: Tkinter: The good, the bad, and the ugly!

2011-01-14 Thread Zeissmann
 Seriously, get off of WoW and go write some code. If you'd spent the
 last year programming instead of doing your best Xah Lee impression you
 might have actually made some progress on this.

I'm curious, is Xah Lee some sort of a Usenet meme? Cause this is not the 
first time I see his name in the context of a lightweight invective.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 and Unicode line breaking

2011-01-14 Thread leoboiko
On Jan 14, 8:10 pm, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
 The only other person I can see who has attempted to actually help the OP
 is Stefan Behnel, who tried to get more information about the problem
 being solved in order to better answer the question. The OP has, so far
 as I can see, not responded, although he has taken the time to write to
 me in private to argue further.

I have written in private because I really feel this discussion is out-
of-place here.  This thread is already in the first page of google
results for “python unicode line breaking”, “python uax #14” etc.  I
feel it would be good to use this place to discuss Unicode line
breaking, not best practices on asking questions, or in how
disappointly impolite the Internet has become.  (Briefly: As a tech
support professional myself, I prefer direct, concise questions than
crufty ones; and I try to ask questions in the most direct manner
precisely _because_ I don’t want to waste the time of kind volunteers
with my problems.)


As for taking the time to provide information, I wonder if there was
any technical problem that prevented you from seeing my reply to
Stefan, sent Jan 14, 12:29PM? He asked how exacly the stdlib module
“textwrap” differs from the Unicode algorithm, so I provided some
commented examples.

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


Re: Is it possible to let a virtual file created by cStringIO have a filename so that functions can read it by its filename?

2011-01-14 Thread Steven Howe

On 01/14/2011 12:51 PM, Chris Rebert wrote:

On Fri, Jan 14, 2011 at 7:52 AM, Cun Zhangapzc2...@gmail.com  wrote:

Hi,all
I hope use cStringIO to create virtual file, but my customed function which
is from a shared library imported by ctypes
just accepts a filename(string type) as parameter.

So I'm wondering whether there is any method that make the virtual file
created by cStringIO like a normal file which have
a filename, so it can be called by my functions.

That's not possible. (c)StringIO presents a file-like interface at the
Python level, but under the covers, it's not implemented using
anything like a normal file; thus, it doesn't have a presence on any
filesystem. I would suggest using a temporary file
(http://docs.python.org/library/tempfile.html ) for communicating with
the C module, writing the contents of the StringIO object to the
temporary file if necessary.
(It's probably also possible to hack something together with FUSE, but
it'd be a slow, platform-specific kludge.)

Cheers,
Chris
--
http://blog.rebertia.com


However, as the only reason to have the cstringIO object have a name is
for you to open or close it. The rest of the functionality is the same, 
reading and writing too.



--
in a terminal ...
import cStringIO

ab = cStringIO.StringIO() # an output type, as it was call with nothing.
cd = cStringIO.StringIO( 'a filled buffer') # an input type.

type( ab ) == cStringIO.OutputType
True

type( cd ) == cStringIO.InputType
True

Working with these properties  we get


Let's assume you have class with read and write ability,
which assumes opening a file or cStringIO object (could
extend to StringIO object with out much changing ).


class foo:
def __init__( self ):
 Define some variables. House keeping. 
self.readState = False
self.writeState = False
self.readObj = None
self.writeObj = None

def fooOpenWrite( self, fileobj ):
if type( fileobj ) === StringType:
self.writeObj = open( fileobj, 'wb' )
elif type( fileobj ) == cStringIO.OutputType:
self.writeObj = fileobj
else:
self.writeState = False
return
self.readState = True
return True

def fooOpenRead( self, fileobj ):
if type( fileobj ) === StringType:
self.readObj = open( fileobj, 'wb' )
elif type( fileobj ) == cStringIO.OutputType:
self.readObj = fileobj
else:
self.readState = False
return
self.readState = True
return

def fooRead( self ):
for x in self.readObj:
print x

def fooWrite( self, str ):
self.readObj.write( str )


Steven

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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Antoine Pitrou
On 14 Jan 2011 22:10:02 GMT
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 
 This is good, helpful advice, and far more useful to the OP than just 
 ignoring his post. You have jumped to his defense (or rather, you have 
 jumped to criticise me) but I see that you haven't replied to his 
 question or given him any advice in how to solve his problem.

Simply because I have no elaborate answer to give, even in the light of
his/her recent precisions on the topic (and, actually, neither do you).
Asking for precisions is certainly fine; doing it in an agressive way
is not, especially when the original message doesn't look like the
usual blunt, impolite and typo-ridden can you do my homework message.

Also, I would expect someone familiar with the textwrap module's (lack
of) unicode capabilities would have been able to answer the first
message without even asking for precisions.

Regards

Antoine.


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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Antoine Pitrou
On Fri, 14 Jan 2011 06:29:27 -0800 (PST)
leoboiko leobo...@gmail.com wrote:
 
 And it generally doesn’t try to pick good places to break lines
 at all, just making the assumption that 1 character = 1 column
 and that breaking on ASCII whitespaces/hyphens is enough.  We
 can’t really blame textwrap for that, it is a very simple module
 and Unicode line breaking gets complex fast (that’s why the
 consortium provides a ready-made algorithm).  It’s just that,
 with python3’s emphasis on Unicode support, I was surprised not
 to be able to find an UAX #14 implementation.  I thought someone
 would surely have written one and I simply couldn’t find, so I
 asked precisely that.

If you're willing to help on that matter (or some aspects of them,
textwrap-specific or not), you can open an issue on
http://bugs.python.org and propose a patch.

See also http://docs.python.org/devguide/#contributing if you need more
info on how to contribute.

Regards

Antoine.


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


Re: Developing a program to make a family tree.

2011-01-14 Thread Billy Earney
try http://gramps-project.org/, which is created in python.. :)

On Fri, Jan 14, 2011 at 1:39 PM, Ata Jafari a.j.romani...@gmail.com wrote:

 Hi there.
 I'm trying to develop a program like family tree maker. I have all
 information, so there is no need to search on the net. This must be
 something like trees. Can someone help me? I'm at the beginning.
 Thanks.

 --
 Ata J. Tabrizi
 atae.tabr...@metu.edu.tr
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Developing a program to make a family tree.

2011-01-14 Thread Kushal Kumaran
- Original message -
 Hi there.
 I'm trying to develop a program like family tree maker. I have all
 information, so there is no need to search on the net. This must be
 something like trees. Can someone help me? I'm at the beginning.
 Thanks.
 

Family trees are nothing like trees, actually.  If you start with that 
assumption, your software will sadly not be usable by many people.

-- 
regards,
kushal

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


Re: python 3 and Unicode line breaking

2011-01-14 Thread Steven D'Aprano
On Fri, 14 Jan 2011 14:26:09 -0800, leoboiko wrote:
...
 As for taking the time to provide information, I wonder if there was any
 technical problem that prevented you from seeing my reply to Stefan,
 sent Jan 14, 12:29PM? 

Presumably, since I haven't got it in my news client. This is not the 
first time.


 He asked how exacly the stdlib module “textwrap”
 differs from the Unicode algorithm, so I provided some commented
 examples.

Does this help?


http://packages.python.org/kitchen/api-text-display.html

  kitchen.text.display.wrap(text, width=70, initial_indent=u'',
  subsequent_indent=u'', encoding='utf-8', errors='replace')

Works like we want textwrap.wrap() to work 
[...]
textwrap.wrap() from the python standard libray has two drawbacks
that this attempts to fix:

   1. It does not handle textual width. It only operates on bytes or
  characters which are both inadequate (due to multi-byte and
  double width characters).
   2. It malforms lists and blocks.



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


Re: Elliptic Curve Prime factorisation

2011-01-14 Thread Steven D'Aprano
On Fri, 14 Jan 2011 11:52:21 -0800, mukesh tiwari wrote:

 Hello all , I have implemented Elliptic curve prime factorisation using
 wikipedia [
 http://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization]. I
 think that this code is not optimised and posting for further
 improvement. Feel free to comment and if you have any link regarding
 Elliptic curve prime factorisation , kindly post it. Thank you


I don't think you can optimize it further in pure Python, although it is 
probably a good candidate for something like Cython, Pyrex or Shedskin.

I think the code can be optimized for easier reading by putting single 
spaces around operators, following commas, etc. I find your style 
difficult to read.

It could do with a docstring explaining what it does and how to use it, 
and some doctests. But other than that, it looks good. Have you 
considered putting it up on the ActiveState Python cookbook?



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


Re: Developing a program to make a family tree.

2011-01-14 Thread Tim Harig
On 2011-01-14, Ata Jafari a.j.romani...@gmail.com wrote:
 I'm trying to develop a program like family tree maker. I have all
 information, so there is no need to search on the net. This must be
 something like trees. Can someone help me? I'm at the beginning.

I don't know anything specific about family tree software and you don't
really specify what you want your software to do.  I can only assume
that you are interested in taking the data in some format which contains
the links between family members and creating a tree representation of
that data?

If I was going to attempt something like this, I would probably generate
the representation as a set of postscript instructions.  I would start
with a basic template for a union which could be essentially pasted
into different places in the output page.  Then generating your tree
is a simple matter of laying out the templates to match your data,
filling in the template fields for each persion within their union,
and drawing the connecting lines of the tree.

Since I was already generating postscript anyway, I would probably
implement much of the actual logic in postscript (the built in stacks
provide an exellent way to process tree like structures in all of their
nested levels). I would Python provide any user interface for manipulating
the data and to dump the data into the postscript program.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elliptic Curve Prime factorisation

2011-01-14 Thread Dan Stromberg
On Fri, Jan 14, 2011 at 11:52 AM, mukesh tiwari
mukeshtiwari.ii...@gmail.com wrote:
 Hello all , I have implemented Elliptic curve prime factorisation
 using wikipedia [ 
 http://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization].
 I think that this code is not optimised and posting for further
 improvement. Feel free to comment and if you have any link regarding
 Elliptic curve prime factorisation , kindly post it.
 Thank you

You can get a lot of good suggestions for your code quickly and easily
by going over it with pylint.

For performance, you could try the gmpy module - it's good at dealing
with large numbers.  For an example, you might examine
http://stromberg.dnsalias.org/svn/huge-prime/trunk .  BTW, huge-prime
dates from just shortly before I started routinely going over my code
with pylint.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elliptic Curve Prime factorisation

2011-01-14 Thread mukesh tiwari
On Jan 15, 7:02 am, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
 On Fri, 14 Jan 2011 11:52:21 -0800, mukesh tiwari wrote:
  Hello all , I have implemented Elliptic curve prime factorisation using
  wikipedia [
 http://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization]. I
  think that this code is not optimised and posting for further
  improvement. Feel free to comment and if you have any link regarding
  Elliptic curve prime factorisation , kindly post it. Thank you

 I don't think you can optimize it further in pure Python, although it is
 probably a good candidate for something like Cython, Pyrex or Shedskin.

 I think the code can be optimized for easier reading by putting single
 spaces around operators, following commas, etc. I find your style
 difficult to read.

 It could do with a docstring explaining what it does and how to use it,
 and some doctests. But other than that, it looks good. Have you
 considered putting it up on the ActiveState Python cookbook?

 --
 Steven

Thank you for your suggestion. I posted it ActiveState  with comments.
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import math
import random
#y^2=x^3+ax+b mod n

# ax+by=gcd(a,b). This function returns [gcd(a,b),x,y]. Source
Wikipedia
def extended_gcd(a,b):
x,y,lastx,lasty=0,1,1,0
while b!=0:
q=a/b
a,b=b,a%b
x,lastx=(lastx-q*x,x)
y,lasty=(lasty-q*y,y)
if a0:
return (-a,-lastx,-lasty)
else:
return (a,lastx,lasty)
def gcd(a,b):
if a  0:  a = -a
if b  0:  b = -b
if a == 0: return b
if b == 0: return a
while b != 0:
(a, b) = (b, a%b)
return a

# pick first a point P=(u,v) with random non-zero coordinates u,v (mod
N), then pick a random non-zero A (mod N),
# then take B = u^2 - v^3 - Ax (mod N).
# http://en.wikipedia.org/wiki/Lenstra_elliptic_curve_factorization

def randomCurve(N):
A,u,v=random.randrange(N),random.randrange(N),random.randrange(N)
B=(v*v-u*u*u-A*u)%N
return [(A,B,N),(u,v)]

# Given the curve y^2 = x^3 + ax + b over the field K (whose
characteristic we assume to be neither 2 nor 3), and points
# P = (xP, yP) and Q = (xQ, yQ) on the curve, assume first that xP !=
xQ. Let the slope of the line s = (yP - yQ)/(xP - xQ); since K  # is
a field, s is well-defined. Then we can define R = P + Q = (xR, - yR)
by
#   s=(xP-xQ)/(yP-yQ) Mod N
#   xR=s^2-xP-xQMod N
#   yR=yP+s(xR-xP)  Mod N
# If xP = xQ, then there are two options: if yP = -yQ, including the
case where yP = yQ = 0, then the sum is defined as 0[Identity]. 
#
thus, the inverse of each point on the curve is found by reflecting it
across the x-axis. If yP = yQ != 0, then R = P + P = 2P =   # (xR,
-yR) is given by
#   s=3xP^2+a/(2yP) Mod N
#   xR=s^2-2xP  Mod N
#   yR=yP+s(xR-xP)  Mod N
#   http://en.wikipedia.org/wiki/Elliptic_curve#The_group_law''')

def addPoint(E,p_1,p_2):
if p_1==Identity: return [p_2,1]
if p_2==Identity: return [p_1,1]
a,b,n=E
(x_1,y_1)=p_1
(x_2,y_2)=p_2
x_1%=n
y_1%=n
x_2%=n
y_2%=n
if x_1 != x_2 :
d,u,v=extended_gcd(x_1-x_2,n)
s=((y_1-y_2)*u)%n
x_3=(s*s-x_1-x_2)%n
y_3=(-y_1-s*(x_3-x_1))%n
else:
if (y_1+y_2)%n==0:return [Identity,1]
else:
d,u,v=extended_gcd(2*y_1,n)
s=((3*x_1*x_1+a)*u)%n
x_3=(s*s-2*x_1)%n
y_3=(-y_1-s*(x_3-x_1))%n

return [(x_3,y_3),d]

# http://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication
#   Q=0 [Identity element]
#   while m:
#   if (m is odd) Q+=P
#   P+=P
#   m/=2
#   return Q')

def mulPoint(E,P,m):
Ret=Identity
d=1
while m!=0:
if m%2!=0: Ret,d=addPoint(E,Ret,P)
if d!=1 : return [Ret,d]  # as soon as i got anything otherthan 
1
return
P,d=addPoint(E,P,P)
if d!=1 : return [Ret,d]
m=1
return [Ret,d]




def ellipticFactor(N,m,times=5):
for i in xrange(times):
E,P=randomCurve(N);
Q,d=mulPoint(E,P,m)
if d!=1 : return d
return N

if __name__==__main__:
n=input()
m=int(math.factorial(1000))
while n!=1:
k=ellipticFactor(n,m)
n/=k
print k
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python use growing fast

2011-01-14 Thread rantingrick
On Jan 10, 9:24 pm, Dan Stromberg drsali...@gmail.com wrote:

 About JavaScript's popularity:
 1) I've been getting the impression that JavaScript is popular in a
 manner similar to how x86 machine language is popular: That is, it's
 used all over, but few people hand code it (though admittedly, there
 are probably more people hand coding JavaScript than people hand
 coding x86 assembler today)

Exactly, another half baked language that has been shoved down our
throats like artery clogging Big Macs and French Fries! Oh how many
times i have lamented for Python's eloquent syntax whilst brain
farting Javascript idiosyncrasies!

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


[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Committed to release27-maint r87992

--
resolution:  - fixed

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



[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

That's the wrong way of porting though... py3k first, then 2.7 and 3.1.

--
nosy: +georg.brandl

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Pierre Quentel pierre.quen...@gmail.com added the comment:

@Victor

Thanks for the comments

- I don't understand why FieldStorage changes sys.stdout and sys.stderr (see 
remarks about IOMix above): please remove the charset argument (it is also 
confusing to have two encoding arguments). it should be done somewhere else

done

please remove the O_BINARY hack: the patch is for Python 3.2 and I closed 
issue #10841. If you would like a backport, another patch should be written 
later

done

encoding = 'latin-1' # ?: write a real comment or remove it

I removed this part

'self.fp.read(...) # bytes': you should add a test on the type if you are not 
sure that fp.read() gives bytes

added tests in read_urlencoded(), read_multi() and read_binary()

 file: the file(-like) object from which you can read the data *as bytes*: 
you should mention that TextIOWrapper is also tolerated (accepted?)

not done : here file is not the argument passed to the FieldStorage 
constructor, but the attribute of values returned from calls to FieldStorage. 
In the new implementation, its read() method always returns bytes

you may set fp directly to sys.stdin.buffer (instead of sys.stdin) if fp is 
None (it will be easier after removing the O_BINARY thing)
 
done
 
 the patch adds a tab in an empty line, please don't do that :-)
 
done (hopefully :-)
 
you should add a (private?) attribute to FieldStorage to decide if it works on 
bytes or unicode, instead of using self.filename is not None test (eg. 
self._use_bytes = (self.filename is not None)

done

 i don't like the idea of having a generic self.__write() method supporting 
bytes and unicode. it would prefer two methods, eg. self.__write_text() and 
self.__write_binary() (they can share a third private method)
 
not done, the argument of __write is always bytes
 
i don't like stream_encoding name: what is the stream here? do you process 
a file, a string or a stream? why not just self.encoding?

done

 - import email.parser,email.feedparser one import is useless here. I prefer 
from email.feedparser import FeedParser because you get directly a 
ImportError if the symbol is missing. And it's already faster to get FeedParser 
instead of email.feedparser.FeedParser in a loop (dummy micro-optimization)

done

 even I like the following change, please do it in a separated patch:
-if type(value) is type([]):
+if isinstance(value,list):

not done

I really don't like the IOMix thing:

removed

I vote +0 to commit the patch now (if the release manager agrees), and +1 if 
all of my remarks are fixed.

should be close to +0.8 now ;-)

--
Added file: http://bugs.python.org/file20402/cgi_32.patch

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Changes by Pierre Quentel pierre.quen...@gmail.com:


Removed file: http://bugs.python.org/file20387/cgi_32.patch

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



[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Committed to py3k r87993

--

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



[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Ah, true - I forgot svnmerge for 27-maint was based on the py3k branch.

--

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



[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Georg, thanks - will keep that in mind. Here I started with 2.7 since this is 
what the user reported on. I plan to have it committed to all 3 branches today 
anyhow.

--

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



[issue9844] calling nonexisting function under __INSURE__

2011-01-14 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Backported to release31: r87994 (with svnmerge)

--
resolution:  - fixed
status: open - closed

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



[issue10902] Doc type: run_* instead of run* on http://docs.python.org/library/pdb.html

2011-01-14 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Committed to release31 in r87995 (with svnmerge)

--
status: open - closed

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



[issue10278] add time.wallclock() method

2011-01-14 Thread Matt Joiner

Matt Joiner anacro...@gmail.com added the comment:

This is sorely needed. IMO the current behaviour of time.clock works for 
Windows, and clock_gettime(CLOCK_MONOTONIC) on POSIX or 
clock_gettime(CLOCK_MONOTONIC_RAW) on Linux=2.6.28.

There are some related discussions on StackOverflow that may contain useful 
ideas also:
http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python
http://stackoverflow.com/questions/4687408/retrieve-wall-time-in-python-using-the-standard-library

--
nosy: +anacrolix

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Etienne Robillard

Etienne Robillard e...@gthcfoundation.org added the comment:

+1

thanks for this input. I agree for the most part. However if the io
semantics in python 3 is radically different than on python 2, I could
have expected that WSGI scripts would similarly depend on a newer
type of file descriptor access using the ``sys`` module.

cheers!

--

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



[issue10903] ZipExtFile:_update_crc fails for CRC = 0x80000000

2011-01-14 Thread arindam

New submission from arindam arindampa...@gmail.com:

File: zipfile.py
Function: _update_crc
statement: if eof and self._running_crc != self._expected_crc:

Due to comparison of long with int, if eof and self._running_crc != 
self._expected_crc: fails when _expected_crc is negative (0x8000 or more). 
Type of _running_crc is long while _expected_crc is int.

How to reproduce: Unzip a zip file containing a file having CRC = 0x8000.

The issue is seen with 3.1 also.

--
components: Library (Lib)
messages: 126250
nosy: arindam
priority: normal
severity: normal
status: open
title: ZipExtFile:_update_crc fails for CRC = 0x8000
type: behavior
versions: Python 2.7

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Glenn Linderman

Glenn Linderman v+pyt...@g.nevcal.com added the comment:

Pierre, Thank you for the new patch, with the philosophy of it's broke, so 
let's produce something the committers like to get it fixed.

I see you overlooked removing the second use of O_BINARY.  Locally, I removed 
that also, and tested your newest patch, and it still functions great for me.

--

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



[issue10904] PYTHONIOENCODING is not in manpage

2011-01-14 Thread Peter Kleiweg

New submission from Peter Kleiweg pklei...@xs4all.nl:

The environment variable PYTHONIOENCODING should be documented in de manpage

--
assignee: docs@python
components: Documentation, IO
messages: 126252
nosy: docs@python, pebbe
priority: normal
severity: normal
status: open
title: PYTHONIOENCODING is not in manpage
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/issue10904
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Pierre Quentel pierre.quen...@gmail.com added the comment:

Glenn, you read my mind ;-)

Thanks for mentioning the O_BINARY thing. New (last !) patch attached

--
Added file: http://bugs.python.org/file20403/cgi_32.patch

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Changes by Pierre Quentel pierre.quen...@gmail.com:


Removed file: http://bugs.python.org/file20402/cgi_32.patch

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



[issue10905] zipfile: fix arcname with leading '///' or '..'

2011-01-14 Thread Zhigang Wang

New submission from Zhigang Wang w1z...@gmail.com:

We only support arcname with one leading '/', but not more. This patch fixes it.

We don't support arcname with '..' well. The default behavior of unzip and 7z 
is to ignore all '..'. This patch does the same.

Also updated the doc. If there are other security related issues exist, we 
should revise the doc.

Please review.

--
components: Library (Lib)
files: python-zipfile-fix-arcname.patch
keywords: patch
messages: 126254
nosy: zhigang
priority: normal
severity: normal
status: open
title: zipfile: fix arcname with leading '///' or '..'
type: security
versions: Python 3.3
Added file: http://bugs.python.org/file20404/python-zipfile-fix-arcname.patch

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



[issue10905] zipfile: fix arcname with leading '///' or '..'

2011-01-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

What happens when the archive contains both 'foo' and '../foo'? They seem to be 
extracted at the same place.

--
nosy: +amaury.forgeotdarc

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

r87996+r87997 adds encoding and errors argument to parse_qs() and parse_qsl() 
of urllib.parse. It is needed to decoded correctly %XX syntax in cgi.

r87998 is the patch on the cgi module.

Changes with cgi_32.patch:

 * Use TextIOWrapper instead of TextIOBase, because TextIOBase has no buffer
   attribute
 * typo in a docstring: it must must = must
 * (docstring) default: sys.stdin = default: sys.stdin.buffer
 * PEP 8: hasattr(a,b) = hasattr(a, b) (same for isinstance) and
   encoding = 'utf-8' = encoding='utf-8' (in the argument list)
 * xxx.decode(...) # str: remove useless # str comment. decode() always give
   unicode in Python 3 (same change for .encode() # bytes)
 * Rename next variables to next_boundary because next is a builtin
   function in Python 3 (unrelated change).
 * FieldStorage.innerboundary and FieldStorage.outerboundary are bytes objects:
   encode innerboundary in the constructor, and raise an error if outerboundary
   is not a bytes object
 * Rename _use_bytes to _binary_file
 * isinstance(bytes) test: write the type, not the value, in the error message
 * Replace line[:2] == b'--' by line.startswith(b'--'), and then replace
   line.strip() by line.rstrip()
 * test_fieldstorage_multipart() uses ASCII (and specifiy the encoding to 
FieldStorage)
 * add FieldStorage.errors attribute: pass it to parse_qsl()
 * add errors attribute to FieldStorage: same default value than 
urllib.parse.unquote(): 'replace'
 * parse(): pass encoding argument to parse_qs()
 * FieldStorage: pass encoding and errors arguments to parse_qsl()

Because the patch on TextIOBase, it patched the docstring:
---
fp  : file pointer; default: sys.stdin.buffer
(not used when the request method is GET)
Can be :
1. an instance of (a subclass of) TextIOWrapper, in this case it
must provide an attribute buffer = the binary layer that returns
bytes from its read() method, and preferably an attribute
encoding (defaults to latin-1)
2. an object whose read() and readline() methods return bytes
---
becomes
---
fp  : file pointer; default: sys.stdin.buffer
(not used when the request method is GET)
Can be :
1. a TextIOWrapper object
2. an object whose read() and readline() methods return bytes
---

Replace type(value) is type([]) is done in another commit: r87999.

I consider that the work on this issue is done, and so I close it. If I am 
wrong, explain why and repoen the issue.

Please test the cgi as much as possible before Python 3.2 final: reopen the 
issue if it doesn't work.

--
resolution:  - fixed
status: open - closed

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Oh, I forgot to credit the author(s): who wrote the patch?

--

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



[issue10905] zipfile: fix arcname with leading '///' or '..'

2011-01-14 Thread Zhigang Wang

Zhigang Wang w1z...@gmail.com added the comment:

$ unzip -l t.zip 
Archive:  t.zip
  Length  DateTimeName
-  -- -   
3  01-14-2011 21:11   ../foo
3  01-14-2011 21:11   foo
- ---
6 2 files
[zhigang@localhost tmp]$ unzip -d aa t.zip
Archive:  t.zip
warning:  skipped ../ path component(s) in ../foo
 extracting: aa/foo  
replace aa/foo? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
 extracting: aa/foo  


$ 7za x -oaa t.zip 

7-Zip (A) 9.13 beta  Copyright (c) 1999-2010 Igor Pavlov  2010-04-15
p7zip Version 9.13 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,1 CPU)

Processing archive: t.zip

file aa/foo
already exists. Overwrite with 
../foo?
(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? A
Extracting  ../foo
Extracting  foo

Everything is Ok

Files: 2
Size:   6
Compressed: 198

--

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



[issue10905] zipfile: fix arcname with leading '///' or '..'

2011-01-14 Thread Zhigang Wang

Zhigang Wang w1z...@gmail.com added the comment:

Yes, in zipfile, we just overwrite it. Actually, ZipFile.extract() overwrite 
existing files already. If we want it more powerful, we can add a 'overwrite' 
parameter. But turning zipfile a full featured zip/unzip tool needs much more 
extra work...

--

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



[issue3978] ZipFileExt.read() can be incredibly slow; patch included

2011-01-14 Thread Andre Berg

Andre Berg andre.b...@email.de added the comment:

If I may chime in, as I don't know where else to put this.

I am still seeing the same performance as the OP when I use extractall() with a 
password protected ZIP of size 287 MB (containing one compressed movie file of 
size 297 MB).

The total running time for extractall.py was
real35m24.448s
user34m52.423s
sys0m1.448s

For a bash script using unzip -P the running time on the same file was

real0m19.026s
user0m8.359s
sys 0m0.414s

extractall.py loops over the contents of a directory using os.walk, identifies 
zip files by file extension and extracts a certain portion of the filename as 
password using a regex. If I leave the ZipFile.extractall part out of it and 
run it it takes 0.15 s.

This is with Python 2.7.1 and Python 3.1.2 on Mac OS X 10.6.4 on an 8-core 
MacPro with 16 GB of RAM. The file is read from an attached USB drive. Maybe 
that makes a difference. I wish I could tell you more.

This is just for the record. I don't expect this to be fixed.

--
nosy: +andreb

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



[issue3978] ZipFileExt.read() can be incredibly slow; patch included

2011-01-14 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 I am still seeing the same performance as the OP when I use
 extractall() with a password protected ZIP of size 287 MB (containing
 one compressed movie file of size 297 MB).

Please try with a non-password protected file.

--

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Pierre Quentel pierre.quen...@gmail.com added the comment:

Thanks a lot Victor !

I wrote the patch : Pierre Quentel (pierre.quen...@gmail.com) with many
inputs by Glenn Linderman

2011/1/14 STINNER Victor rep...@bugs.python.org


 STINNER Victor victor.stin...@haypocalc.com added the comment:

 Oh, I forgot to credit the author(s): who wrote the patch?

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue4953
 ___


--
title: cgi module cannot handle POST with multipart/form-data in3.x - 
cgi module cannot handle POST with multipart/form-data in 3.x
Added file: http://bugs.python.org/file20405/unnamed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4953
___Thanks a lot Victor !brbrI wrote the patch : Pierre Quentel (a 
href=mailto:pierre.quen...@gmail.com;pierre.quen...@gmail.com/a) with many 
inputs by Glenn Lindermanbrbrdiv class=gmail_quote2011/1/14 STINNER 
Victor span dir=ltrlt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;/spanbr
blockquote class=gmail_quote style=margin: 0pt 0pt 0pt 0.8ex; border-left: 
1px solid rgb(204, 204, 204); padding-left: 1ex;div class=imbr
STINNER Victor lt;a 
href=mailto:victor.stin...@haypocalc.com;victor.stin...@haypocalc.com/agt; 
added the comment:br
br
/divOh, I forgot to credit the author(s): who wrote the patch?br
br
--br
divdiv/divdiv class=h5br
___br
Python tracker lt;a 
href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;br
lt;a href=http://bugs.python.org/issue4953; 
target=_blankhttp://bugs.python.org/issue4953/agt;br
___br
/div/div/blockquote/divbrdiv class=ogc-tooltip-class 
id=ogc_tooltip_id/div
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10906] wsgiref should mention that CGI scripts usually expect HTTPS variable to be set to 'on'

2011-01-14 Thread anatoly techtonik

New submission from anatoly techtonik techto...@gmail.com:

http://docs.python.org/library/wsgiref.html#wsgiref.util.guess_scheme

The documentation says servers typically set HTTPS variable to a value of “1” 
or “yes”, when a request is received via SSL, but CGI tutorials, IIS and Apache 
set this to “on”.

Misleading documentation may be the reason of the bug with mod_wsgi that 
changes Apache's variable from “on” to “1” - 
https://issues.apache.org/bugzilla/show_bug.cgi?id=50581

The documentation should at least stress that “on” is the mainstream value for 
this variable. It will help to mention at least one popular server that returns 
“1”.

--
assignee: docs@python
components: Documentation
messages: 126263
nosy: docs@python, techtonik
priority: normal
severity: normal
status: open
title: wsgiref should mention that CGI scripts usually expect HTTPS variable to 
be set to 'on'
versions: Python 3.2

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

TODO: Add more tests to test_cgi. What is the latest patch for test_cgi?

--

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



[issue8232] webbrowser.open incomplete on Windows

2011-01-14 Thread Dev Player

Dev Player devpla...@gmail.com added the comment:

Don't forget to check if the MS Internet Explorer's advanced option to open new 
URLS in a seperate windows effects this.  Users can have this advanced setting 
set differently on different computers(or even accounts). Also different 
browser versions call that option by different names. And I think there may 
even be a way to turn off tabs altogether, so check that too.

--
nosy: +devplayer

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Changes by Pierre Quentel pierre.quen...@gmail.com:


Removed file: http://bugs.python.org/file20405/unnamed

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread Pierre Quentel

Pierre Quentel pierre.quen...@gmail.com added the comment:

My latest patch for test_cgi is in cgi_32.patch

I will try to add more tests later

--

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

haypo What is the latest patch for test_cgi?
quentel My latest patch for test_cgi is in cgi_32.patch

Ok, but cgi_32.patch doesn't add any test. I only adapt existing tests for your 
other changes.

I remove cgi_32.patch because it was commited.

--

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

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


Removed file: http://bugs.python.org/file20403/cgi_32.patch

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Remove cgi_plus_tests.diff: it looks to be an old version of cgi_32.patch.

@r.david.murray: Did you write cgi_plus_tests.diff, or is it based on the work 
on Pierre Quentel?

--

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

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


Removed file: http://bugs.python.org/file20269/cgi_plus_tests.diff

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

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


Removed file: http://bugs.python.org/file12750/tmpav1vve.html

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

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


Removed file: http://bugs.python.org/file12751/tmpy44zj7.html

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



[issue4953] cgi module cannot handle POST with multipart/form-data in 3.x

2011-01-14 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Remove tmpy44zj7.html and tmpav1vve.html: a similar file is included in 
full_source_and_error.zip.

--

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



  1   2   >