WSDL and XML generation

2009-07-28 Thread guitarzero
Hi all
Newbie in Python, i am looking for some pointers (or better existing
modules) to do the followings:

- generate (correct) XML messages from a WSDL file
- make some modifications inside XML messages *before* sending them to
the server hosting the Web services (described by previously
mentionned WSDL file)
- parse the answer.

Some ideas ?
Thanks in advance
Stephane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Testoob: How do you use testoob.collector_from_globals / collector_from_modules?

2009-07-28 Thread orip
Hi Harry,

I forwarded this to the Testoob list at http://groups.google.com/group/testoob

Ori.

On Jul 27, 4:12 pm, Harry Ebbers  wrote:
> Hi,
>
> For a project I'm creating unittests using testoob. When all tests are
> in a single file there is no problem
>
> if __name__ == '__main__':
>     testoob.main()
>  does the trick as usual.
>
> But for a number of python-applications they have asked me to group
> unittests in different files, based on common functionality (e.g. GUI,
> main-application, etcetera).
>
> Ican get it to work by importing all unittestclasses in the following
> way and than use the normal if __name__ == '__main__' construction
>
> (from GUI import GUItests
> from APP import APPtests
>
> if __name__ == '__main__':
>     testoob.main())
>
> But looking at the future I would like to use testsuites.
>
> On the internet I found the functions testoob.collector_from_globals
> and collector_from_modules which one can use to 'easily' create
> testsuites which can be used with testoob. But no examples on how to
> use them can be found.
>
> Can anybody supply me with a working example?
>
> TIA
>
> Harry Ebbers

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


Re: RSA cryptography between Python and Java

2009-07-28 Thread M.-A. Lemburg
Rob Knop wrote:
> I've created an RSA key in Java.  I have exported the public key by
> making it into a X509EncodedKeySpec and spitting out the result of
> getEncoded().
> 
> I want to use this public key to encode something in python that I will
> send to Java, and then decode in Java with the corresponding private
> key.
> 
> Are there any python libraries that will take a public key in this
> format and do RSA encoding on it?

M2Crypto will let you do this:

http://chandlerproject.org/bin/view/Projects/MeTooCrypto

If you have access to the raw key data (instead of having it
encoded in a X509 certificate), then you can also use PyCrypto,
which does require setting up OpenSSL first:

http://www.dlitz.net/software/pycrypto/

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 28 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bad certificate error

2009-07-28 Thread Nick Craig-Wood
jakecjacobson  wrote:
>  I am getting the following error when doing a post to REST API,
> 
>  Enter PEM pass phrase:
>  Traceback (most recent call last):
>File "./ices_catalog_feeder.py", line 193, in ?
>  main(sys.argv[1])
>File "./ices_catalog_feeder.py", line 60, in main
>  post2Catalog(catalog_host, catalog_port, catalog_path, os.path.join
>  (input_dir, file), collection_name, key_file, cert_file)
>File "./ices_catalog_feeder.py", line 125, in post2Catalog
>  connection.request('POST', path, parameters, head)
>File "/usr/lib/python2.4/httplib.py", line 810, in request
>  self._send_request(method, url, body, headers)
>File "/usr/lib/python2.4/httplib.py", line 833, in _send_request
>  self.endheaders()
>File "/usr/lib/python2.4/httplib.py", line 804, in endheaders
>  self._send_output()
>File "/usr/lib/python2.4/httplib.py", line 685, in _send_output
>  self.send(msg)
>File "/usr/lib/python2.4/httplib.py", line 652, in send
>  self.connect()
>File "/usr/lib/python2.4/httplib.py", line 1079, in connect
>  ssl = socket.ssl(sock, self.key_file, self.cert_file)
>File "/usr/lib/python2.4/socket.py", line 74, in ssl
>  return _realssl(sock, keyfile, certfile)
>  socket.sslerror: (1, 'error:14094412:SSL
>  routines:SSL3_READ_BYTES:sslv3 alert bad certificate')
> 
> 
>  My code where this error occurs is:
> 
>  head = {"Content-Type" : "application/x-www-form-urlencoded",
>  "Accept" : "text/plain"}
>  parameters = urlencode({"collection" : collection, "entryxml" : open
>  (file,'r').read()})
>  print "Sending the file to: " + host
> 
>  try:
>   try:
>   # Default port is 443.
>   # key_file is the name of a PEM formatted file that contains 
> your
>  private key.
>   # cert_file is a PEM formatted certificate chain file.
>   connection = httplib.HTTPSConnection(host, int(port), key_file,
>  cert_file)
>   connection.request('POST', path, parameters, head)
>   response = connection.getresponse()
>   print response.status, response.reason
>   except httplib.error, (value,message):
>   print value + ':' + message
>  finally:
>   connection.close()
> 
>  I was wondering if this is due to the server having a invalid server
>  cert?

I'd say judging from the traceback you messed up key_file or cert_file
somehow.

Try using the openssl binary on them (read the man page to see how!)
to check them out.

>  If I go to this server in my browser, I get a "This server tried to
>  identify itself with invalid information".  Is there a way to
>  ignore this issue with Python?  Can I setup a trust store and add
>  this server to the trust store?

Invalid how?  Self signed certificate? Domain mismatch? Expired certificate?

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining __name__ from the code that called a function

2009-07-28 Thread Gabriel Genellina
En Tue, 28 Jul 2009 03:21:10 -0300, Paul Johnston   
escribió:



In ToscaWidgets 2 experimental, when defining resources you often do
something like this:
CSSLink(modname=__name__, filename='static/mycss.css')

Now, what I'd like to do is make the "modname=__name__" optional, to
make code more concise. I figure there must be some way (using inspect
or something) to determine what __name__ would be in the code that
just called my function. Couldn't immediately see how to do this - any
suggestions?


In CPython, you may use sys._getframe(1).f_globals['__name__'] but I don't  
know how portable is that across Python implementations.


--
Gabriel Genellina

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


Re: ioctl on socket

2009-07-28 Thread jacopo mondi
Gabriel Genellina wrote:
> En Mon, 27 Jul 2009 16:35:51 -0300, jacopo mondi 
> escribió:
> 
>> Is there a reason why there is no ioctl interface for socket either then
>> for windows platform? It's technical issues or what else??
> 
> I don't completely understand your question. On Windows, you can use
> socket.ioctl with sockets, and DeviceIoControl (from the pywin32 package)
> with other files. On Linux, you have fcntl.ioctl that works with any kind
> of file.
> 
Ok, thanks a lot, my question was because I didn't know about
fcntl.ioct, I thought that ioctl wrapping was implemented inside
socketmodule.c as 'bind', 'connect', 'accept' etc. are, and I was
disoriented because no documentation for socket usage on Linux nor the
code have references about ioctl, except for windows.

I hope the reason why you didn't completely understood my question is
not my english, if it be so I'm sorry and I ask anyone to correct me,
it's the only way to improve ;)

thanks a lot
jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do I put resources (images, audio files) when I wrote Python program?

2009-07-28 Thread Marco Mariani

Piotrek wrote:


that? I think about puting these files in /usr/share/myprogram and then
reading it the normal way (so the path "/usr/share/myprogram" would be just
hardwired in my program). Is it the way one usually does it in Python
program or is there any more sofisticated way?


Just keep them in your sources, and create an empty __init__.py file in 
the images directory.
Then install setuptools and use the pkg_resources module. It will work 
even if your application is installed as an egg through easy_install, 
possibly zipped.



To open a resource file:

f = pkg_resources.resource_stream('path.to.package', 'resource.png')
f.read()


"""
Return a readable file-like object for the specified resource; it 
may be an actual file, a StringIO, or some similar object. The stream is 
in "binary mode", in the sense that whatever bytes are in the resource 
will be read as-is.

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


The longest word

2009-07-28 Thread NiklasRTZ
Newbie hello onwards to the .py manual asks meantime how the longest
word gets determined?
First word, ok
 'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)]
'a'
rfind is another subset
>>> 'a aa aaa aa'[:'a aa aaa aa'.rfind(' ',1,10)]
'a aa aaa'
One row should be able. It's a direct word 'a aa aaa...' and can be a
variable, it's no big deal it occurs twice still naturally easier if
also occured just once.
Sincere thanks & regards
Niklas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread Hendrik van Rooyen
On Monday 27 July 2009 16:49:25 Aahz wrote:
> In article ,
>
> Hendrik van Rooyen   wrote:
> >On Sunday 26 July 2009 21:26:46 David Robinow wrote:
> >>  I'm a mediocre programmer. Does this mean I should switch to PHP?
> >
> >I have searched, but I can find nothing about this mediocre language.
> >
> >Could you tell us more?
> >
> :-P
>
> (For anyone who is confused by Hendrik's humor, he is saying that David
> was referring to a programming language named "mediocre".  English
> grammar is confusing!)

This is true - I intended, when I started the post, to make a crack about
how he knew that he was mediocre - If there were some exam or test
that you have to pass or fail to be able to make the claim to mediocrity.
I was imagining a sort of devil's rating scale for programmers, that
could cause one to say things like:  "I am studying hard so that I can
get my mediocre certificate, and one day I hope to reach hacker rank".

And then the similarity to "I am a COBOL programmer" struck me, 
and I abandoned the ratings.

- Hendrik

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


Re: The longest word

2009-07-28 Thread Bearophile
On Jul 28, 10:26 am, NiklasRTZ  wrote:
> Newbie hello onwards to the .py manual asks meantime how the longest
> word gets determined?
> First word, ok
>  'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)]

Your language is not easy to understand, but I think you want to find
the longest word in a string.
If this is the input string:
txt = "a aa aaa aa"

There are several ways to do it, I'll show a simple one.

You can split it into its parts (not having Python a built-in lazy
split yet, you can split it all at once). You can do it with the
string split method. It produces a list of the words, more or less
(but you may have words like "gone,", you may have to take care of
them too, this requires some code.

Once you have a list of words, you have to take the longest. A simple
way is to replace each word with a tuple that contains the length of
the word and the word itself, then pick the tuple with the highest
length value. But Python allows you to do such operation in a faster
way: you can use the max() function, it has a "key" function that
allows you to remap on the fly what you mean by "max". So you just
have to give it a function (reference) that given the word spits its
length, such function is "len" itself.

If you instead want to find the position of the longest word the
program gets a little longer. Ask if you need something different.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The longest word

2009-07-28 Thread NiklasRTZ
On Jul 28, 5:02 am, Bearophile  wrote:
> On Jul 28, 10:26 am, NiklasRTZ  wrote:
>
> > Newbie hello onwards to the .py manual asks meantime how the longest
> > word gets determined?
> > First word, ok
> >  'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)]
>
> Your language is not easy to understand, but I think you want to find
> the longest word in a string.
> If this is the input string:
> txt = "a aa aaa aa"
>
> There are several ways to do it, I'll show a simple one.
>
> You can split it into its parts (not having Python a built-in lazy
> split yet, you can split it all at once). You can do it with the
> string split method. It produces a list of the words, more or less
> (but you may have words like "gone,", you may have to take care of
> them too, this requires some code.
>
> Once you have a list of words, you have to take the longest. A simple
> way is to replace each word with a tuple that contains the length of
> the word and the word itself, then pick the tuple with the highest
> length value. But Python allows you to do such operation in a faster
> way: you can use the max() function, it has a "key" function that
> allows you to remap on the fly what you mean by "max". So you just
> have to give it a function (reference) that given the word spits its
> length, such function is "len" itself.
>
> If you instead want to find the position of the longest word the
> program gets a little longer. Ask if you need something different.
>
> Bye,
> bearophile

Thank you. This seems to work:
sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '),lambda a,b: len(a)-
len(b))[-1]
'sdfsdfsdfsdf'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The longest word

2009-07-28 Thread Piet van Oostrum
> NiklasRTZ  (N) wrote:

>N> Newbie hello onwards to the .py manual asks meantime how the longest
>N> word gets determined?
>N> First word, ok
>N>  'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)]
>N> 'a'
>N> rfind is another subset
> 'a aa aaa aa'[:'a aa aaa aa'.rfind(' ',1,10)]
>N> 'a aa aaa'
>N> One row should be able. It's a direct word 'a aa aaa...' and can be a
>N> variable, it's no big deal it occurs twice still naturally easier if
>N> also occured just once.
>N> Sincere thanks & regards
>N> Niklas

1. Is this homework?
2. It sounds very confusing. Are you trying to find the longest word in
   a series of words seperated by spaces? find and rfind will not help
   you much. You should start with var.split() if var contains the text.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Override a method but inherit the docstring

2009-07-28 Thread Jean-Michel Pichavant

Shai wrote:

On Jul 27, 5:05 pm, Jean-Michel Pichavant 
wrote:
  

Ben Finney wrote:


The docstring for ‘FooGonk.frobnicate’ is, intentionally, perfectly
applicable to the ‘BarGonk.frobnicate’ method also. Yet in overriding
the method, the original docstring is not associated with it.
  

I've also tried within the python interpreter, and it can perfectly
solve docstring inheritance. So why would you explicitly assign
docstring to child methods ?




What do you mean by "can perfectly solve docstring inheritance" ?

After the following,

class Foo(object):
def foo(self):
"Frobber"
pass

class Bar(Foo):
def foo(self):
pass

help(Bar.foo) does not display "Frobber" on my interpreter.

  
You're right. I must have made some dumb mistake. So interpreters do not 
solve docstring inheritance, Epydoc does.


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


Re: The longest word

2009-07-28 Thread Piet van Oostrum
> NiklasRTZ  (N) wrote:

>N> Thank you. This seems to work:
>N> sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '),lambda a,b: len(a)-
>N> len(b))[-1]
>N> 'sdfsdfsdfsdf'

simpler:

sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '), key=len)[-1]
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extract images from PDF files

2009-07-28 Thread superpollo

David Lyon wrote:

pdftohtml on sourceforge may help...



also see: http://linuxcommand.org/man_pages/pdfimages1.html

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


Re: The longest word

2009-07-28 Thread Peter Otten
NiklasRTZ wrote:

> On Jul 28, 5:02 am, Bearophile  wrote:
>> On Jul 28, 10:26 am, NiklasRTZ  wrote:
>>
>> > Newbie hello onwards to the .py manual asks meantime how the longest
>> > word gets determined?
>> > First word, ok
>> > 'a aa aaa aa'[:'a aa aaa aa'.find(' ',1,10)]
>>
>> Your language is not easy to understand, but I think you want to find
>> the longest word in a string.
>> If this is the input string:
>> txt = "a aa aaa aa"
>>
>> There are several ways to do it, I'll show a simple one.
>>
>> You can split it into its parts (not having Python a built-in lazy
>> split yet, you can split it all at once). You can do it with the
>> string split method. It produces a list of the words, more or less
>> (but you may have words like "gone,", you may have to take care of
>> them too, this requires some code.
>>
>> Once you have a list of words, you have to take the longest. A simple
>> way is to replace each word with a tuple that contains the length of
>> the word and the word itself, then pick the tuple with the highest
>> length value. But Python allows you to do such operation in a faster
>> way: you can use the max() function, it has a "key" function that
>> allows you to remap on the fly what you mean by "max". So you just
>> have to give it a function (reference) that given the word spits its
>> length, such function is "len" itself.
>>
>> If you instead want to find the position of the longest word the
>> program gets a little longer. Ask if you need something different.
>>
>> Bye,
>> bearophile
> 
> Thank you. This seems to work:
> sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '),lambda a,b: len(a)-
> len(b))[-1]
> 'sdfsdfsdfsdf'

To spell out bearophile's more efficient suggestion:

>>> max("a AAA aa a  sdfsdfsdfsdf vv".split(), key=len)
'sdfsdfsdfsdf'



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


Re: bad certificate error

2009-07-28 Thread jakecjacobson
On Jul 28, 3:29 am, Nick Craig-Wood  wrote:
> jakecjacobson  wrote:
> >  I am getting the following error when doing a post to REST API,
>
> >  Enter PEM pass phrase:
> >  Traceback (most recent call last):
> >    File "./ices_catalog_feeder.py", line 193, in ?
> >      main(sys.argv[1])
> >    File "./ices_catalog_feeder.py", line 60, in main
> >      post2Catalog(catalog_host, catalog_port, catalog_path, os.path.join
> >  (input_dir, file), collection_name, key_file, cert_file)
> >    File "./ices_catalog_feeder.py", line 125, in post2Catalog
> >      connection.request('POST', path, parameters, head)
> >    File "/usr/lib/python2.4/httplib.py", line 810, in request
> >      self._send_request(method, url, body, headers)
> >    File "/usr/lib/python2.4/httplib.py", line 833, in _send_request
> >      self.endheaders()
> >    File "/usr/lib/python2.4/httplib.py", line 804, in endheaders
> >      self._send_output()
> >    File "/usr/lib/python2.4/httplib.py", line 685, in _send_output
> >      self.send(msg)
> >    File "/usr/lib/python2.4/httplib.py", line 652, in send
> >      self.connect()
> >    File "/usr/lib/python2.4/httplib.py", line 1079, in connect
> >      ssl = socket.ssl(sock, self.key_file, self.cert_file)
> >    File "/usr/lib/python2.4/socket.py", line 74, in ssl
> >      return _realssl(sock, keyfile, certfile)
> >  socket.sslerror: (1, 'error:14094412:SSL
> >  routines:SSL3_READ_BYTES:sslv3 alert bad certificate')
>
> >  My code where this error occurs is:
>
> >  head = {"Content-Type" : "application/x-www-form-urlencoded",
> >  "Accept" : "text/plain"}
> >  parameters = urlencode({"collection" : collection, "entryxml" : open
> >  (file,'r').read()})
> >  print "Sending the file to: " + host
>
> >  try:
> >    try:
> >            # Default port is 443.
> >            # key_file is the name of a PEM formatted file that contains your
> >  private key.
> >            # cert_file is a PEM formatted certificate chain file.
> >            connection = httplib.HTTPSConnection(host, int(port), key_file,
> >  cert_file)
> >            connection.request('POST', path, parameters, head)
> >            response = connection.getresponse()
> >            print response.status, response.reason
> >    except httplib.error, (value,message):
> >            print value + ':' + message
> >  finally:
> >    connection.close()
>
> >  I was wondering if this is due to the server having a invalid server
> >  cert?
>
> I'd say judging from the traceback you messed up key_file or cert_file
> somehow.
>
> Try using the openssl binary on them (read the man page to see how!)
> to check them out.
>
> >  If I go to this server in my browser, I get a "This server tried to
> >  identify itself with invalid information".  Is there a way to
> >  ignore this issue with Python?  Can I setup a trust store and add
> >  this server to the trust store?
>
> Invalid how?  Self signed certificate? Domain mismatch? Expired certificate?
>
> --
> Nick Craig-Wood  --http://www.craig-wood.com/nick

Nick,

Thanks for the help on this.  I will check my steps on openssl again
and see if I messed up.  What I tried to do was:
1.  Save my PKI cert to disk.  It was saved as a P12 file
2.  Use openssl to convert it to the needed .pem file type
3.  Saved the CA that my cert was signed by as a .crt file

These are the 2 files that I was using for key_file and
 * cert_file -> CA
 * key_file -> my PKI cert converted to a .pem file

"Invalid how?  Self signed certificate? Domain mismatch? Expired
certificate?"  It is a server name mismatch.

For everyone that wants to discuss why we shouldn't do this, great but
I can't change the fact that I need to do this.  I can't use http or
even get a correct cert at this time.  This is a quick a dirty project
to demonstrate capability.  I need something more than slide show
briefs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: where do I put resources (images, audio files) when I wrote Python program?

2009-07-28 Thread Dave Angel

Gabriel Genellina wrote:

For those read-only resources I'd use pkgutil.get_data (instead of
manually parsing __file__):

http://docs.python.org/library/pkgutil.html#pkgutil.get_data

It's easier to manage when someone later decide to install the package as
an egg file, or distribute it using py2exe. Quoting the documentation:

"""The function returns a binary string that is the contents of the
specified resource.

For packages located in the filesystem, which have already been imported,
this is the rough equivalent of:

d = os.path.dirname(sys.modules[package].__file__)
data = open(os.path.join(d, resource), 'rb').read()
return data
"""


Thanks Gabriel, I hadn't come across get_data() yet.

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


Re: ioctl on socket

2009-07-28 Thread Gabriel Genellina
En Tue, 28 Jul 2009 07:05:43 -0300, jacopo mondi   
escribió:

Gabriel Genellina wrote:

En Mon, 27 Jul 2009 16:35:51 -0300, jacopo mondi 
escribió:

Is there a reason why there is no ioctl interface for socket either  
then

for windows platform? It's technical issues or what else??


I don't completely understand your question. On Windows, you can use
socket.ioctl with sockets, and DeviceIoControl (from the pywin32  
package)
with other files. On Linux, you have fcntl.ioctl that works with any  
kind

of file.


Ok, thanks a lot, my question was because I didn't know about
fcntl.ioct, I thought that ioctl wrapping was implemented inside
socketmodule.c as 'bind', 'connect', 'accept' etc. are, and I was
disoriented because no documentation for socket usage on Linux nor the
code have references about ioctl, except for windows.


I see; socket.ioctl should menction fcntl.ioctl; I'll submit a  
documentation patch.


--
Gabriel Genellina

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


Re: The longest word

2009-07-28 Thread Hrvoje Niksic
Piet van Oostrum  writes:

>> NiklasRTZ  (N) wrote:
>
>>N> Thank you. This seems to work:
>>N> sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '),lambda a,b: len(a)-
>>N> len(b))[-1]
>>N> 'sdfsdfsdfsdf'
>
> simpler:
>
> sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '), key=len)[-1]

There is no need to sort the sequence to obtain the largest element.
The max function is designed to do exactly that, and also supports the
key argument:

>>> max("a AAA aa a  sdfsdfsdfsdf vv".split(' '), key=len)
'sdfsdfsdfsdf'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am trying to compile python 2.6.2 on my Mac

2009-07-28 Thread Tommy Nordgren


On Jul 26, 2009, at 10:37 AM, Chris Rebert wrote:


On Sun, Jul 26, 2009 at 1:12 AM, Jessica R
Smith wrote:

Hello,
I am trying to compile Python 2.6.2 on my Mac which has os/x 10.5.7

I downloaded python 2.6.2 from here:
 - http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tar.bz2

I unpacked it.

I ran these shell commands:
 - ./configure --prefix=/pt/p
 - make

Near the end of the make output I see this message:

. Failed to find the necessary bits to build these modules:
. _bsddb gdbm   linuxaudiodev
. ossaudiodevreadline   spwd
. sunaudiodev
. To find the necessary bits, look in setup.py in detect_modules()  
for

the module's name.

I looked in setup.py in detect_modules()

It is not clear to me how to proceed.

I think that I want the module: "readline"

I doubt I need the other modules like linuxaudiodev, etc.

If you have any clues or opinions on how I can build the module
"readline",
please feel free to share.


You need to install the GNU Readline library
(http://tiswww.case.edu/php/chet/readline/rltop.html), which the
module depends on.


A better solution would be to configure the modules in question to use
the libreadline.dylib library already installed on every Mac OS X  
computer.

You might consider installing Python through MacPorts or Fink instead,
as they automate the compilation and installation process and take
care of dependencies (such as GNU Readline) for you:
http://www.macports.org/
http://www.finkproject.org/

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


---
See the amazing new SF reel: Invasion of the man eating cucumbers from  
outer space.
On congratulations for a fantastic parody, the producer replies :  
"What parody?"


Tommy Nordgren
[email protected]




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


Re: Looking for a dream language: sounds like Python to me.

2009-07-28 Thread ray
On Jul 27, 10:39 am, David Cournapeau  wrote:
> On Tue, Jul 28, 2009 at 12:28 AM, Dotan Cohen wrote:
> >> It is neither efficient or inefficient: it is just a distribution
> >> tool, to deploy python software in a form familiar to most windows
> >> users. It does not make it any faster than running the software under
> >> a python prompt.
>
> >> As much as I like python for scientific programming, I would say
> >> python is pretty far from the stated requirements in the posted blog
> >> post. It is difficult to deploy software written with python (much
> >> better than the alternatives, though), and it is slow if you can't
> >> leverage numpy/scipy (where vectorization does not apply).
>
> >> It remains to be seen whether it will be true in practice, but
> >> something like F#, with its integration in VS 2010, seems much closer
> >> IMHO. It is compiled, high level language, and backed by the biggest
> >> software vendor in the world.
>
> > The blog post is not looking to distribute his code, but he would like
> > it to be cross platform for his own reasons. VB is not cross platform.
>
> I understand his "efficient binary as Ansi C" partially as a
> deployment requirement, and independent of cross-platform issues. As a
> scientist, being able to share my software with colleagues is a non
> trivial matter. Python does not make this easy today.
>
> F# has nothing to do with VB: F# is a ML-language inspired from OCAML,
> and run on top of the CLR. It can thus leverage the huge .net
> framework (lack of non numerical API is one of the biggest matlab
> hindrance, and comparatively big advantage of python + numpy/scipy),
> and benefits from the much more efficient implementation compared to
> python (under the currently CPython implementation at least).
>
> Some recent F# versions are compatible with mono, making it compatible
> on most platforms that matter today for research (but of course, you
> lose the IDE integration outside windows).
>
> David- Hide quoted text -
>
> - Show quoted text -
I wish . . .

For comparisons, Mathcad has the symbolic notation appropriate for
mathematical communications.  I like features of Mathematica and Maple
but Mathcad provides for the user to 'stay' with mathematical
symbolism longer.  I prefer Matlab execution environment.  So I
develop concepts in Mathcad, prove them in Matlab and then compile to
through C where direct performance is required.  Maple and Matlab have
this type of relation.

Matlab, from The Mathworks, has a companion product called Simulink.
This allows the user to graphically build ‘algorithms’ in block form.
There is a similar Python function.

Each of these components would best be served if allowed to exist
independently but supported with transparent integration.  I would
like to develop in a stable user environment - a stable GUI.  And then
allow efficient algorithms behind the scenes.

By separating the functionality of the workspace, the user can be
given (or create at will) a GUI that suites her desires and provides
for the creativity and productivity she chooses.  The functionality
under the GUI should then be pluggable.  Developers can provide
solutions from many directions, compete for varying performance
requirements, enhance functional features technology changes, and
still not disturb the fragile user interface.

Allow the user the comfort of home.  Let them keep whatever GUI suits
them and provide for their deployment (if any) needs behind the
scenes.

Ray




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


Re: The longest word

2009-07-28 Thread NiklasRTZ
On Jul 28, 7:03 am, Hrvoje Niksic  wrote:
> Piet van Oostrum  writes:
>
> >> NiklasRTZ  (N) wrote:
>
> >>N> Thank you. This seems to work:
> >>N> sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '),lambda a,b: len(a)-
> >>N> len(b))[-1]
> >>N> 'sdfsdfsdfsdf'
>
> > simpler:
>
> > sorted("a AAA aa a  sdfsdfsdfsdf vv".split(' '), key=len)[-1]
>
> There is no need to sort the sequence to obtain the largest element.
> The max function is designed to do exactly that, and also supports the
> key argument:
>
> >>> max("a AAA aa a  sdfsdfsdfsdf vv".split(' '), key=len)
>
> 'sdfsdfsdfsdf'

Sincere thanks for strengthening python's superior flexibility. Same
function also works around an exploding index problem returning
results for longest word where otherwise a word with whitespace
crashes the index:
all().search(max(q.split(), key=len)).filter("modified >",
timeline).filter("published =", True).filter("modified <=",
bookmark ).order("-modified").fetch(PAGESIZE+1)
Line below crashes the index for words with whitespace (unknown
researchable, only occurs live, works with development)
all().search(q).filter("modified >", timeline).filter("published =",
True).filter("modified <=", bookmark ).order("-modified").fetch
(PAGESIZE+1)
best regards,
Niklas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bad certificate error

2009-07-28 Thread Steven D'Aprano
On Mon, 27 Jul 2009 23:16:39 -0300, Gabriel Genellina wrote:

> I don't see the point on "fixing" either the Python script or httplib to
> accomodate for an invalid server certificate... If it's just for
> internal testing, I'd use HTTP instead (at least until the certificate
> is fixed).

In real life, sometimes you need to drive with bad brakes on your car, 
walk down dark alleys in the bad part of town, climb a tree without a 
safety line, and use a hammer without wearing goggles. We can do all 
these things.

The OP has said that, for whatever reason, he needs to ignore a bad 
server certificate when connecting to HTTPS. Python is a language where 
developers are allowed to shoot themselves in the foot, so long as they 
do so in full knowledge of what they're doing.

So, putting aside all the millions of reasons why the OP shouldn't accept 
an invalid certificate, how can he accept an invalid certificate?



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


Re: bad certificate error

2009-07-28 Thread Nick Craig-Wood
jakecjacobson  wrote:
> > >  If I go to this server in my browser, I get a "This server tried to
> > >  identify itself with invalid information".  Is there a way to
> > >  ignore this issue with Python?  Can I setup a trust store and add
> > >  this server to the trust store?
> >
> > Invalid how?  Self signed certificate? Domain mismatch? Expired
> > certificate?
>
>  For everyone that wants to discuss why we shouldn't do this, great but
>  I can't change the fact that I need to do this.  I can't use http or
>  even get a correct cert at this time.  This is a quick a dirty project
>  to demonstrate capability.  I need something more than slide show
>  briefs.

I wasn't making a value judgement - I was trying to help!  If you can
get a bit more information out of the browser as to why the
certificate is invalid it may help your python code.

Real certificates cost real money.  Usually a correctly set up
self-signed certificate is fine for dev stuff.  I'm certainly too
cheap to by real certificates for dev or internal stuff!

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


index nested lists

2009-07-28 Thread Alex
hi at all,
 If I have this list:

>>> lista
['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]

if I want enumerate elements...I can see:

>>> for parola in lista:
print lista[i]
i = i + 1

ciao
1
['mela', 'pera', 'banana']
[1, 2, 3]
>>>

but, if I want to enumerate elements about nested lists ??, something
like:

ciao
1
mela
pera
banana
1
2
3

...How can I do ??

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


File and TagPy

2009-07-28 Thread redhot
Hello,
I have question, is it possible to read tag in tagpy module from file
stream?
For example I have earlier read file:
file = open('some.mp3', 'rb')

and next get tags from it?

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


FTP Offset larger than file.

2009-07-28 Thread Bakes
I am writing a python script that performs an identical function to
the 'tail' unix utility, except that it connects to its files over
FTP, rather than the local hard disk.

I am currently using this python script to generate an increasing
'logfile' of garbage.

> import time
> for i in range(1, 2):
>   time.sleep(0.2)
>   print i
>   f = open("data1.log","a")
>   f.write('%s: This logfile is being automatically generated to help 
> Bakes test his python ftptail. \n' % i)
>   f.close()

and use this script to actually download it.

>import time
>import os.path
>from ftplib import FTP
>
>#Empty the file
>filename = 'data1.log'
>file = open(filename, 'w')
>file.write('')
>file.close()
>
>def handleDownload(block):
>file.write(block)
>print ".",
>
># Create an instance of the FTP object
># Optionally, you could specify username and password:
>ftp=FTP(host, user, pass)
>
>directory = '/temp'
>ftp.cwd(directory)
>
>file = open(filename, 'a')
>
>for i in range(1,2):
>  size=os.path.getsize('data1.log')
>  ftp.retrbinary('RETR ' + filename, handleDownload, rest=size)
>
>file.close()
>
>print ftp.close()

Now, my problem is that I get a very strange error. What should be
happening is the script gets the size of the local file before
downloading all of the external file after that offset.

The error I get is:
ftplib.error_temp: 451-Restart offset 24576 is too large for file size
22852.
451 Restart offset reset to 0
which tells me that the local file is larger than the external file,
by about a kilobyte. Certainly, the local file is indeed that size, so
my local script is doing the right things. I do wonder what is going
wrong, can anyone enlighten me?
-- 
http://mail.python.org/mailman/listinfo/python-list


Internal Math Library of Numpy

2009-07-28 Thread Nanime Puloski
Does Numpy use Python's standard math library when calculating
elementary functions such as exp(x) and acos(x)? Also, what is the
internal library of Numpy and Python's standard math library? Is it
platform independent?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: index nested lists

2009-07-28 Thread Andreas Tawn
> hi at all,
>  If I have this list:
> 
> >>> lista
> ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
> 
> if I want enumerate elements...I can see:
> 
> >>> for parola in lista:
>   print lista[i]
>   i = i + 1
> 
> ciao
> 1
> ['mela', 'pera', 'banana']
> [1, 2, 3]
> >>>
> 
> but, if I want to enumerate elements about nested lists ??, something
> like:
> 
> ciao
> 1
> mela
> pera
> banana
> 1
> 2
> 3
> 
> ...How can I do ??
> 
> Alex
> --
> http://mail.python.org/mailman/listinfo/python-list

You could do something like this.

def printNestedList(lst):
if isinstance(lst, list):
for element in lst:
printNestedList(element)
else:
print lst

myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
printNestedList(myList)

>>>
ciao
1
mela
pera
banana
1
2
3

Cheers, Drea
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: index nested lists

2009-07-28 Thread Alex
On 28 Lug, 15:12, "Andreas Tawn"  wrote:
> > hi at all,
> >  If I have this list:
>
> > >>> lista
> > ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
>
> > if I want enumerate elements...I can see:
>
> > >>> for parola in lista:
> >    print lista[i]
> >    i = i + 1
>
> > ciao
> > 1
> > ['mela', 'pera', 'banana']
> > [1, 2, 3]
>
> > but, if I want to enumerate elements about nested lists ??, something
> > like:
>
> > ciao
> > 1
> > mela
> > pera
> > banana
> > 1
> > 2
> > 3
>
> > ...How can I do ??
>
> > Alex
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> You could do something like this.
>
> def printNestedList(lst):
>     if isinstance(lst, list):
>         for element in lst:
>             printNestedList(element)
>     else:
>         print lst
>
> myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
> printNestedList(myList)
>


thanks a lot !

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


python 3 and stringio.seek

2009-07-28 Thread Michele Petrazzo

Hi list,
I'm trying to port a my library to python 3, but I have a problem with a
the stringio.seek:
the method not accept anymore a value like pos=-6 mode=1, but the "old"
(2.X) version yes...

The error:
  File "/home/devel/Py3/lib/python3.0/io.py", line 2031, in seek
return self._seek(pos, whence)
IOError: Can't do nonzero cur-relative seeks


How solve this?

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


Re: Gracefully exiting CLI application

2009-07-28 Thread Nobody
On Mon, 27 Jul 2009 22:35:01 +0200, David wrote:

> I am writing a command line application, and I need to perform some
> cleaning on exit even if the process is killed. How can I do that with
> python?

Killed by what means?

Ctrl-C sends SIGINT which is converted to a KeyboardInterrupt exception.
This can be caught, or if it's allowed to terminate the process, any exit
handlers registered via atexit.register() will be used.

For other signals, you can install a handler with signal.signal(). This
can call sys.exit() or raise an exception (e.g. KeyboardInterrupt).

OTOH, if the process is terminated by SIGKILL, there's nothing you can do
about it. And although it's possible to trap SIGSEGV, you shouldn't assume
that the Python interpreter is still functional at this point.

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


Re: index nested lists

2009-07-28 Thread Jean-Michel Pichavant

Alex wrote:

On 28 Lug, 15:12, "Andreas Tawn"  wrote:
  

hi at all,
 If I have this list:
  

lista


['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
  
if I want enumerate elements...I can see:
  

for parola in lista:


   print lista[i]
   i = i + 1
  
ciao

1
['mela', 'pera', 'banana']
[1, 2, 3]
  
but, if I want to enumerate elements about nested lists ??, something

like:
  
ciao

1
mela
pera
banana
1
2
3
  
...How can I do ??
  
Alex

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

You could do something like this.

def printNestedList(lst):
if isinstance(lst, list):
for element in lst:
printNestedList(element)
else:
print lst

myList = ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]]
printNestedList(myList)





thanks a lot !

Alex
  
One hidden suggestion in Andreas answer is to write your code in 
english, if you can :o)


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


Re: bad certificate error

2009-07-28 Thread Jean-Paul Calderone

On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson 
 wrote:

[snip]

"Invalid how?  Self signed certificate? Domain mismatch? Expired
certificate?"  It is a server name mismatch.


Python 2.4 is not capable of allowing you to customize this verification
behavior.  It is hard coded to let OpenSSL make the decision about whether
to accept the certificate or not.

Either M2Crypto or pyOpenSSL will let you ignore verification errors.  The
new ssl module in Python 2.6 may also as well.

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


Re: bad certificate error

2009-07-28 Thread jakecjacobson
On Jul 28, 9:48 am, Jean-Paul Calderone  wrote:
> On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson 
>  wrote:
> > [snip]
>
> >"Invalid how?  Self signed certificate? Domain mismatch? Expired
> >certificate?"  It is a server name mismatch.
>
> Python 2.4 is not capable of allowing you to customize this verification
> behavior.  It is hard coded to let OpenSSL make the decision about whether
> to accept the certificate or not.
>
> Either M2Crypto or pyOpenSSL will let you ignore verification errors.  The
> new ssl module in Python 2.6 may also as well.
>
> Jean-Paul

Thanks, I will look into these suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Questions about unicodedata in python 2.6.2

2009-07-28 Thread Weidong
I am trying to build python 2.6.2 from the source by following the
instructions in README that comes with the source.  The configure and
make steps are fine, but there is an error in "make install" step.
This "make install" attempts to build a lot of lib, and it complains
about the lack of "unicodedata" shared object,

I looked at the source tree and the build result, unicodedata.so does
not exist.  I further notice that in Modules/Setup.dist, the line for
unicodedata.c is commented out by default.  So I uncomment it, and
experiment with rebuilding everything.

This time, with or without re-configure, the "make" step failed with a
link-time error when linking for libpython2.6.a due to "undefined
reference to 'initunicodedata'.  This symbol is defined in
unicodedata.c, but unicodedata.o is not used in linking for
libpython2.6.a, hence the error.  So this is a problem in the
generated Makefile.

Does anyone know what special things I have to do to avoid such
error?  Is there any known problems in the configure/make files in the
python 2.6.2 source code that require special patch?

Is unicodedata.c really needed in python 2.6.2?  If it is needed, why
it is commented out by default in Modules/Setup.dist?  If it is not
needed, why "make install" attempts to use it in compiling the
libraries?  Why those libraries are not designed to be compiled in the
make step, but in the install step?

Thanks for your help!

- Weidong


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


Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Weidong
On Jul 28, 9:54 am, Weidong  wrote:
> I am trying to build python 2.6.2 from the source by following the
> instructions in README that comes with the source.  The configure and
> make steps are fine, but there is an error in "make install" step.
> This "make install" attempts to build a lot of lib, and it complains
> about the lack of "unicodedata" shared object,
>
> I looked at the source tree and the build result, unicodedata.so does
> not exist.  I further notice that in Modules/Setup.dist, the line for
> unicodedata.c is commented out by default.  So I uncomment it, and
> experiment with rebuilding everything.
>
> This time, with or without re-configure, the "make" step failed with a
> link-time error when linking for libpython2.6.a due to "undefined
> reference to 'initunicodedata'.  This symbol is defined in
> unicodedata.c, but unicodedata.o is not used in linking for
> libpython2.6.a, hence the error.  So this is a problem in the
> generated Makefile.
>
> Does anyone know what special things I have to do to avoid such
> error?  Is there any known problems in the configure/make files in the
> python 2.6.2 source code that require special patch?
>
> Is unicodedata.c really needed in python 2.6.2?  If it is needed, why
> it is commented out by default in Modules/Setup.dist?  If it is not
> needed, why "make install" attempts to use it in compiling the
> libraries?  Why those libraries are not designed to be compiled in the
> make step, but in the install step?
>
> Thanks for your help!
>
> - Weidong

To add some info: This experiment was done on Linux, Ubuntu 8.x.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: len() should always return something

2009-07-28 Thread Luis Zarrabeitia
On Friday 24 July 2009 11:58:36 am Phillip M. Feldman wrote:
> I've been converting Matlab codes to Python.  In Matlab, a scalar is just a
> one-by-one matrix and has a length of 1.  This convention seems no less
> arbitrary to me than Python's convention that the concept of length is not
> applicable to ints and floats.

Are you sure it isn't? (as opposed to being tainted by matlab?).

Almost everywhere, a scalar and a tuple are different things. How many 
elements are "inside" the number 7? If you assume that 7 is a matrix, why 
should it be a two-dimensional matrix? Why not a vector, or a three 
dimensional matrix instead? (I don't use matlab, but in octave, size(7) 
returns [1,1], not [1] or [1,1,1,1]).

That seems even more arbitrary to me. Of course, in a language like Matlab, 
that assumes that everything is a matrix, it makes sense for scalars to be 
mapped to a useful matrices. But that assumption is not natural.

Even pure math makes a difference between scalars and vectors. Matrix x Matrix 
multiplication is not always defined (even when the second matrix contains 
exactly one element), while Matrix x Scalar always is. (Octave, btw, will 
demote a two-dimensional 1x1 matrix to a scalar for Matrix multiplication, 
which may hide errors)

If you are converting from matlab, I'd say you have biggest things to worry 
about. As you said, you can just replace the len function (even safer may be 
to do [1]). Assignment, for instance, is /very/ different.

> If there is only a single measurement, it is reasonable to allow the calling 
> program to pass a scalar without wrapping it up into a list or array.

I try to avoid those automatic conversions, on the long run, I believe that 
most of them make the code more confusing for the caller. If you feel that 
you must allow that, my suggestion would be to create a method that will 
ensure that what you receive is a list (or whatever) and coerce its argument 
if not, and call that one at the beginning of your methods.

Regards,

[1] this will define len for any object, not only int and floats.
===
def size(x):
try:
return len(x)
except TypeError:
return 1,1
===

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FTP Offset larger than file.

2009-07-28 Thread Hrvoje Niksic
Bakes  writes:

> The error I get is:
> ftplib.error_temp: 451-Restart offset 24576 is too large for file size
> 22852.
> 451 Restart offset reset to 0
> which tells me that the local file is larger than the external file,
> by about a kilobyte. Certainly, the local file is indeed that size, so
> my local script is doing the right things. I do wonder what is going
> wrong, can anyone enlighten me?

I'd say you failed to take buffering into account.  You write into a
buffered file, yet you use os.path.getsize() to find out the current
file size.  If the data is not yet flushed, you keep re-reading the same
stuff from the remote file, and writing it out.  Once the buffer is
flushed, your file will contain more data than was retrieved from the
remote side, and eventually this will result in the error you see.

As a quick fix, you can add a file.flush() line after the
file.write(...) line, and the problem should go away.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Jul 28)

2009-07-28 Thread Gabriel Genellina
QOTW:  "But there's another principle at work here that's less well known, and
that was first articulated to me by Robert Dewar: You can remove linear
factors by profiling, but it's much harder to undo bad algorithmic decisions. 
In particular, whether a program runs in O(n) or O(n^2) sometimes depends on
decisions that have to be frozen fairly early in the design." - Andrew Koenig


Comparing the performance of the same algorithm using many compilers:
CPython, psyco, Cython, ShedSkin, Unladen Swallow, Java, C and D:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8d793c46903cc0b6/

MRAB has written a new implementation of re module with many new
features, and he's looking for feedback:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/16c139b0a52ab023/

Importing two modules with the same name from different directories:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3cb83a30e1b2c202/

Cleanly exiting an application, even if it gets killed by a signal:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d60b8e0d93aeaaf9/

How can a child thread notify a parent thread of its status?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1d7f55716aacedc/

How to attach a docstring to global constants/variables?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac54186ad873036a/

In Python -unlike other languages- it does not make sense to treat
numbers (scalars) as vectors of length 1:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3ef498c906bd7e2d/

isinstance may take a tuple of types as its second argument: why a
tuple, and not a list, or a set?
http://mail.python.org/pipermail/python-list/2009-July/721205.html

How to overcome the normal 2GB allocation limit of Windows XP, 32bits:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/59851df6e54f9ef0/

Distinguishing active generators from exhausted ones:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9ff179e8cb5e9bc/

Peter Otten must be, undoubtedly, Sherlock Holmes reincarnated:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/838177c8a37d2b7c/

And Piet van Oostrum is not much behind him:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1f8627413cd3c4e/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiasts":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a

Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Christian Heimes
Weidong schrieb:
> I am trying to build python 2.6.2 from the source by following the
> instructions in README that comes with the source.  The configure and
> make steps are fine, but there is an error in "make install" step.
> This "make install" attempts to build a lot of lib, and it complains
> about the lack of "unicodedata" shared object,

unicodedata is usually build as a shared library and not linked into the
Python core. How did you configure Python? The usual prodecure is:

   ./configure
   make
   sudo make install

On Unix the preferred option for ./configure is "--enable-unicode=ucs4".

Christian

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


Re: FTP Offset larger than file.

2009-07-28 Thread Bakes
On 28 July, 15:01, Hrvoje Niksic  wrote:
> Bakes  writes:
> > The error I get is:
> > ftplib.error_temp: 451-Restart offset 24576 is too large for file size
> > 22852.
> > 451 Restart offset reset to 0
> > which tells me that the local file is larger than the external file,
> > by about a kilobyte. Certainly, the local file is indeed that size, so
> > my local script is doing the right things. I do wonder what is going
> > wrong, can anyone enlighten me?
>
> I'd say you failed to take buffering into account.  You write into a
> buffered file, yet you use os.path.getsize() to find out the current
> file size.  If the data is not yet flushed, you keep re-reading the same
> stuff from the remote file, and writing it out.  Once the buffer is
> flushed, your file will contain more data than was retrieved from the
> remote side, and eventually this will result in the error you see.
>
> As a quick fix, you can add a file.flush() line after the
> file.write(...) line, and the problem should go away.

Thank you very much, that worked perfectly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help understanding the decisions *behind* python?

2009-07-28 Thread Luis Zarrabeitia
On Friday 24 July 2009 11:07:30 am Inky 788 wrote:
> On Jul 23, 3:42 am, Hendrik van Rooyen 
> > if you think it is contrived, then please consider how you would
> > keep track of say the colour of a pixel on a screen at position
> > (x,y) - this is about the simplest "natural" tuple format and
> > example.
>
> My guess is that this is probably the way most people do it:
[...]
> def make_array_of_pixels(num_columns, num_rows):
[...]

If you need to hold /every/ pixel on the screen, it makes sense to have a 
bidimentional array of points and colors. But if you need to hold a 
non-rectangular subset, or even a subset that doesn't need to be rectangular, 
you can either use dicts, or ... do what you did. Most people will use the 
less contrived version of:

screen = {}
screen[1,2] = (rand(), rand(), rand())

(btw, in your make_a_pixel function, unless you want to make the pixels 
updatable in place, you should also be using a tuple).

Sparse datasets are extremely common, and dicts are a good way to 
[temporarily] store them.

As someone mentioned before, dictionaries are essential to python. Don't go 
out of your way to avoid them, unless you have a /reason/ to do it.

Btw,

def get_color(point):
return screen[point]

is way more readable (and less obscure) than

def get_color(point):
return rows_of_pixels[point[0]][point[1]]

Regards,
-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: initializing with empty list as default causes freaky problems

2009-07-28 Thread Luis Alberto Zarrabeitia Gomez


Quoting Reckoner :

> Hi,
> 
> Observe the following:
> 
> In [202]: class Foo():
>.: def __init__(self,h=[]):
>.: self.h=h
[...]
> In [207]: f.h.append(10)
> 
> In [208]: f.h
> Out[208]: [10]
> 
> In [209]: g.h
> Out[209]: [10]
> 
> The question is: why is g.h updated when I append to f.h?  Shouldn't
> g.h stay []?

What you are seeing is basically the same that happens here: 

===
In [1]: def f(l=[]):
   ...: l.append(1)
   ...: print l
   ...: 

In [2]: f()
[1]

In [3]: f()
[1, 1]

In [4]: f()
[1, 1, 1]
===

The problem is that the default value "[]" is evaluated only once, at function
creation time, and not at invocation. Thus, every call to the function shares
the same default object. That is consistent with python's function type: the
"def" construct just creates a function object and initializes it with the code,
argument list and default values. That means that the default value are part of
the function object itself, regardless of when/if it is called:

===
In [5]: f.func_defaults
Out[5]: ([1, 1, 1],)
===

The recommended way of dealing with this case (mutable default arguments) is:

def f(l = None):
if l is None:
l = []
# the code goes here.

(in your case, your g.__init__ and f.__init__ methods share the same
Foo.__init__ function, and thus, share the same default value [])

That is a very common python gotcha, and I think it is well documented in the
standard doc (but I can't find it right now, sorry). Unfortunately, it doesn't
become intuitive until you've spent a while understanding python's execution
model (and then you suddenly realize that it just makes sense).

[And now I wonder... how other languages do it? I've spent so much time with
python that reevaluating the default argument on invocation feels clumsy, but
I'm obviously tainted now...]

Regards,

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie



-- 
Participe en Universidad 2010, del 8 al 12 de febrero de 2010
La Habana, Cuba 
http://www.universidad2010.cu

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


Re: FTP Offset larger than file.

2009-07-28 Thread Bakes
On 28 July, 15:18, Bakes  wrote:
> On 28 July, 15:01, Hrvoje Niksic  wrote:
>
>
>
> > Bakes  writes:
> > > The error I get is:
> > > ftplib.error_temp: 451-Restart offset 24576 is too large for file size
> > > 22852.
> > > 451 Restart offset reset to 0
> > > which tells me that the local file is larger than the external file,
> > > by about a kilobyte. Certainly, the local file is indeed that size, so
> > > my local script is doing the right things. I do wonder what is going
> > > wrong, can anyone enlighten me?
>
> > I'd say you failed to take buffering into account.  You write into a
> > buffered file, yet you use os.path.getsize() to find out the current
> > file size.  If the data is not yet flushed, you keep re-reading the same
> > stuff from the remote file, and writing it out.  Once the buffer is
> > flushed, your file will contain more data than was retrieved from the
> > remote side, and eventually this will result in the error you see.
>
> > As a quick fix, you can add a file.flush() line after the
> > file.write(...) line, and the problem should go away.
>
> Thank you very much, that worked perfectly.

Actually, no it didn't. That fix works seamlessly in Linux, but gave
the same error in a Windows environment. Is that expected?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a dream language: sounds like Python to me.

2009-07-28 Thread Stef Mientki



Matlab, from The Mathworks, has a companion product called Simulink.
This allows the user to graphically build ‘algorithms’ in block form.
There is a similar Python function.
  

Where can I find a Python functionality like simulink  ?

thanks,
Stef Mientki



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


Re: Internal Math Library of Numpy

2009-07-28 Thread David Cournapeau
On Tue, Jul 28, 2009 at 10:09 PM, Nanime Puloski wrote:
> Does Numpy use Python's standard math library when calculating
> elementary functions such as exp(x) and acos(x)?

It depends on the dtype: for fundamental types (float, int, etc...),
the underlying implementation is whatever the (C) math library
provides. If the functionality is not there, we have our own custom
implementation (but exp and acos happen to be mandatory - if they are
not detected, the build fail).

> Also, what is the
> internal library of Numpy and Python's standard math library? Is it
> platform independent?

I don't know for python, but for numpy, we have our own math library
on top of whatever the platform provides (which is not much on
windows, for example). There is an ongoing effort in numpy to provides
a portable, pure C (independent of the python runtime) math library.
The goal is to have a portable C99 math library, and more later
hopefully.

cheers,

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


Re: New implementation of re module

2009-07-28 Thread MRAB

Aahz wrote:

In article ,
MRAB   wrote:

I've been working on a new implementation of the re module. The details
are at http://bugs.python.org/issue2636, specifically from
http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for
Python 2.6 on Windows if you want to try it out.


How does it handle the re module's unit tests?


Basically, it passes all those tests I expect it to pass. :-)

It fails those where the intended behaviour has changed, such as re.sub
treating unmatched groups as empty strings, as requested in
http://bugs.python.org/issue1519638.
--
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread MRAB

Hendrik van Rooyen wrote:

On Monday 27 July 2009 16:49:25 Aahz wrote:

In article ,

Hendrik van Rooyen   wrote:

On Sunday 26 July 2009 21:26:46 David Robinow wrote:

 I'm a mediocre programmer. Does this mean I should switch to PHP?

I have searched, but I can find nothing about this mediocre language.

Could you tell us more?


:-P

(For anyone who is confused by Hendrik's humor, he is saying that David
was referring to a programming language named "mediocre".  English
grammar is confusing!)


This is true - I intended, when I started the post, to make a crack about
how he knew that he was mediocre - If there were some exam or test
that you have to pass or fail to be able to make the claim to mediocrity.
I was imagining a sort of devil's rating scale for programmers, that
could cause one to say things like:  "I am studying hard so that I can
get my mediocre certificate, and one day I hope to reach hacker rank".

And then the similarity to "I am a COBOL programmer" struck me, 
and I abandoned the ratings.



If you were a "COBOL" programmer, would you want to shout about it? :-)
--
http://mail.python.org/mailman/listinfo/python-list


need help using Tkinter

2009-07-28 Thread Manzur Ahmed
i wanted to ask you if one of you could help me to use Tkinter. i'm trying
to just create a simple GUI for which I have provided the code for below.

# Simple GUI
# Demonstrates creating a window

from Tkinter import *

# create the root window
root = Tk ()

# modify the window
root.title("Simple GUI")
root.geometry("200x100")

# kick off the window's event loop
root.mainloop()

i saved the file as both simple_gui.py and simple_gui.pyw. when i try to run
simple_gui.pyw i don't get anything and when i try to run simple_gui.py i
get the following:
Traceback (most recent call last):
File "C:\Python-Study\Chapter10\simple_gui.py", line 4, in 
ImportError: No module named Tkinter

i tried to google search this and there were some threads that were saying
to install tcl but that does not work. I did check the Lib directory under
the Python directory and I did not see a Tkinter module anywhere which I
think is the problem. Do you know how I would go about with getting this
module and if that is not the problem or if you think it might be caused by
something else, can you please give me some guidance? i even reinstalled
python 3.1 which i got from www.python.org.  i still do not see the Tkinter
module in the lib directory.  thank you for all your help.

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


Re: WSDL and XML generation

2009-07-28 Thread Gustavo Andrés Angulo
Hi you can generate the WSDl with soaplib [1], and you can view web.py or django
for this: 

for web.py -> http://webpy.org/cookbook/webservice

for django -> http://www.djangosnippets.org/snippets/979/


[1]=> http://trac.optio.webfactional.com/

> Hi all
> Newbie in Python, i am looking for some pointers (or better existing
> modules) to do the followings:
> 
> - generate (correct) XML messages from a WSDL file
> - make some modifications inside XML messages *before* sending them to
> the server hosting the Web services (described by previously
> mentionned WSDL file)
> - parse the answer.
> 
> Some ideas ?
> Thanks in advance
> Stephane
> -- 
> http://mail.python.org/mailman/listinfo/python-list


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help using Tkinter

2009-07-28 Thread MRAB

Manzur Ahmed wrote:
i wanted to ask you if one of you could help me to use Tkinter. i'm 
trying to just create a simple GUI for which I have provided the code 
for below.


# Simple GUI
# Demonstrates creating a window

from Tkinter import *

# create the root window
root = Tk ()

# modify the window
root.title("Simple GUI")
root.geometry("200x100")

# kick off the window's event loop
root.mainloop()

i saved the file as both simple_gui.py and simple_gui.pyw. when i try to 
run simple_gui.pyw i don't get anything and when i try to run 
simple_gui.py i get the following:

Traceback (most recent call last):
File "C:\Python-Study\Chapter10\simple_gui.py", line 4, in 
ImportError: No module named Tkinter

i tried to google search this and there were some threads that were 
saying to install tcl but that does not work. I did check the Lib 
directory under the Python directory and I did not see a Tkinter module 
anywhere which I think is the problem. Do you know how I would go about 
with getting this module and if that is not the problem or if you think 
it might be caused by something else, can you please give me some 
guidance? i even reinstalled python 3.1 which i got from www.python.org 
.  i still do not see the Tkinter module in the 
lib directory.  thank you for all your help.



There are some differences between Python 3.x and Python 2.x. In Python
3.1 the module is called "tkinter", not "Tkinter" (names are
case-sensitive).
--
http://mail.python.org/mailman/listinfo/python-list


Re: M2Crypto hangs on this URL

2009-07-28 Thread John Nagle

Martin P. Hellwig wrote:

John Nagle wrote:

John Nagle wrote:

John Nagle wrote:

There's something strange about this URL:

"https://sagar310.pontins.com/sraep/";

...
It looks to me like the SSL handshake is not done properly from the 
server side.


Compare the output of:
openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts 
-msg


With (for example):
openssl s_client -host www.google.com -port 443 -debug -showcerts -msg


  OpenSSL is clearly not happy with that site.  But it doesn't hang.

openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts  -msg

eventually prints

"Verify return code: 19 (self signed certificate in certificate chain)"
That's weird, because there's a Verisign certificate in the chain.
That site is somehow mishandling its certs.

My problem, though, is that M2Crypto 0.17 is hanging for hours to days
on those connections.

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


Re: FTP Offset larger than file.

2009-07-28 Thread Hrvoje Niksic
Bakes  writes:

>> > As a quick fix, you can add a file.flush() line after the
>> > file.write(...) line, and the problem should go away.
>>
>> Thank you very much, that worked perfectly.
>
> Actually, no it didn't. That fix works seamlessly in Linux, but gave
> the same error in a Windows environment. Is that expected?

Consider opening the file in binary mode, by passing the 'wb' and 'ab'
modes to open instead of 'w' and 'a' respectively.  On Windows, python
(and other languages) will convert '\n' to '\r\n' on write.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Weidong
On Jul 28, 10:17 am, Christian Heimes  wrote:
> unicodedatais usually build as a shared library and not linked into the
> Python core. How did you configure Python? The usual prodecure is:
>
>    ./configure
>    make
>    sudo make install
>
> On Unix the preferred option for ./configure is "--enable-unicode=ucs4".
>
> Christian

Thanks for your response!  I configured it in the same way as you
said, but without "--enable-unicode=ucs4".  The ocnfig.log shows that
checking for UCS-4 was failed.  So I assume that by default UCS-2 was
used.  There was no other problme in the "make" step.

The problem was in the "sudo make install" step, where there were
errors in building libraries / test libraries that need unicodedata.so
which did not exist.

I also tried to use "make -i" to let it complete the building to
ignore that error.  In the end, I still did not see unicodedata.so in
the build result.  It seems that the Makefile did not even try to
build unicodedata.so.

Maybe something went wrong in my configuration?

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


Re: Wrapping prstat on Solaris

2009-07-28 Thread ryles
On Jul 27, 10:26 am, [email protected] wrote:
> At work we currently use top to monitor ongoing system utilization on our
> Solaris systems.  As time has moved on though, use of top has become
> problematic.  Our admins want us to switch to prstat, Sun's top-like
> command.  It works fine however doesn't emit a timestamp at each display
> interval, so it's essentially impossible looking at a prstat output
> file to determine when the particular "screen" was emitted.
>
> If figured, "No problem.  I'll just write a little wrapper."  Alas, that is
> proving harder than I thought.  I can run prstat directing output to a file
> and it seems to blast out a block of lines every N seconds, but when run
> from inside a Python script I can't seem to make the damn thing not
> massively buffer its output.  Accordingly, my script doesn't really see the
> output as its emitted, so the timestamp line it prepends to a block of
> output is off.
>
> I'm currently using subprocess.Popen like so:
>
>     os.environ["TERM"] = "dumb"
>     cmd = "prstat -c %s" % " ".join(sys.argv[1:])
>     pipe = Popen(cmd, shell=True, bufsize=1, stdout=PIPE).stdout
>
> I've tried these other variants as well:
>
>   * prefacing the prstat command with unbuffer (the tcl/expect thingamabob)
>
>   * explicitly redirect the prstat output to /dev/stdout
>
>   * setting bufsize to 0
>
>   * used os.popen instead of Subprocess.Popen
>
> Nothing seems to help.  I always seem to see about 30 seconds of data at
> once (I'm currently using a 5-second interval and 10 lines of output).  I
> would have expected that prstat would simply flush stdout after each block
> of output.
>
> Any ideas about how to get prstat to cooperate better?
>
> Thanks,
>
> --
> Skip Montanaro - [email protected] -http://www.smontanaro.net/
>     That's more than a dress. That's an Audrey Hepburn movie. -- Jerry Maguire

Hey Skip,

You haven't told us how you are actually reading from prstat's output
pipe, which may be the cause. For instance, if you are doing

for line in pipe:
  print line
  ...

then this could cause your buffering issue.

Instead try using readline():

while True:
  line = pipe.readline()
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Python as active script

2009-07-28 Thread misterdi
I'm using Activestate python,
For older version of python, I know that we can register python as
active script by registering it through win32comext.axscript.client
pyscript.py
And to do that I need to change something in this pyscript.py before
running pyscript_rexec.py(http://fastq.com/~sckitching/Python/
win32_activeX_pyscript.htm),
but I can't find similar thing with python 2.6.2

I can't find the line that need to be changed.

Can someone kindly show me how to enable python26 as an active script
for IE?

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


Re: The longest word

2009-07-28 Thread ryles
On Jul 28, 7:55 am, NiklasRTZ  wrote:

> Sincere thanks for strengthening python's superior flexibility. Same
> function also works around an exploding index problem returning
> results for longest word where otherwise a word with whitespace
> crashes the index:

Babelfish?

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


Re: FTP Offset larger than file.

2009-07-28 Thread Dave Angel

Bakes wrote:

On 28 July, 15:18, Bakes  wrote:
  

On 28 July, 15:01, Hrvoje Niksic  wrote:





Bakes  writes:
  

The error I get is:
ftplib.error_temp: 451-Restart offset 24576 is too large for file size
22852.
451 Restart offset reset to 0
which tells me that the local file is larger than the external file,
by about a kilobyte. Certainly, the local file is indeed that size, so
my local script is doing the right things. I do wonder what is going
wrong, can anyone enlighten me?


I'd say you failed to take buffering into account.  You write into a
buffered file, yet you use os.path.getsize() to find out the current
file size.  If the data is not yet flushed, you keep re-reading the same
stuff from the remote file, and writing it out.  Once the buffer is
flushed, your file will contain more data than was retrieved from the
remote side, and eventually this will result in the error you see.
  
As a quick fix, you can add a file.flush() line after the

file.write(...) line, and the problem should go away.
  

Thank you very much, that worked perfectly.



Actually, no it didn't. That fix works seamlessly in Linux, but gave
the same error in a Windows environment. Is that expected?

  
This is a text file you're transferring.  And you didn't specify "wb".  
So the Windows size will be larger than the Unix size, since you're 
expanding the newline characters.


getsize() is looking at the size after newlines are expanded to 0d0a, 
while The remote file, presumably a Unix system likely has just has 0a.


I think you'd do best just keeping track of the bytes you've written.


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


Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Christian Heimes
Weidong wrote:
> Thanks for your response!  I configured it in the same way as you
> said, but without "--enable-unicode=ucs4".  The ocnfig.log shows that
> checking for UCS-4 was failed.  So I assume that by default UCS-2 was
> used.  There was no other problme in the "make" step.

Correct

> The problem was in the "sudo make install" step, where there were
> errors in building libraries / test libraries that need unicodedata.so
> which did not exist.

'make install' shouldn't compile any libraries if you run 'make' prior
to 'make install'. I suggest you start again with a clean build tree of
Python 2.6.2.

Christian

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


Re: New implementation of re module

2009-07-28 Thread Christopher Arndt
On 27 Jul., 21:27, Wolfgang Rohdewald  wrote:
> how do I compile _regex.c on Linux?

This simple setup.py file should do the trick:

from distutils.core import setup, Extension

setup(name='regex',
version='1.0',
py_modules = ['regex'],
ext_modules=[Extension('_regex', ['_regex.c'])],
)

Also, you need to copy "unicodedata_db.h" from the "Modules" directory
of the Python source tree to your working directory, since this file
apparently is not installed into the include directory of a Python
installation.

I get an error for Python 2.5 on Mac OS X 10.4 and Linux though. Seems
that the module is not compatible with Python 2.5.

_regex.c: In function 'getstring':
_regex.c:2425: error: invalid type argument of '->'
_regex.c: In function 'getstring':
_regex.c:2425: error: invalid type argument of '->'
lipo: can't figure out the architecture type of: /var/tmp//
ccT3oDXD.out
error: command 'gcc' failed with exit status 1

resp. on Linux:

_regex.c: In function 'getstring':
_regex.c:2425: warning: implicit declaration of function 'Py_TYPE'
_regex.c:2425: error: invalid type argument of '->'
_regex.c: In function 'get_match_replacement':
_regex.c:2900: warning: implicit declaration of function
'PyLong_AsSsize_t'
error: command 'gcc' failed with exit status 1

With the official Python 2.6 distribution for Mac OS X it works.

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


Re: New implementation of re module

2009-07-28 Thread MRAB

Christopher Arndt wrote:

On 27 Jul., 21:27, Wolfgang Rohdewald  wrote:

how do I compile _regex.c on Linux?


This simple setup.py file should do the trick:

from distutils.core import setup, Extension

setup(name='regex',
version='1.0',
py_modules = ['regex'],
ext_modules=[Extension('_regex', ['_regex.c'])],
)

Also, you need to copy "unicodedata_db.h" from the "Modules" directory
of the Python source tree to your working directory, since this file
apparently is not installed into the include directory of a Python
installation.

I get an error for Python 2.5 on Mac OS X 10.4 and Linux though. Seems
that the module is not compatible with Python 2.5.

_regex.c: In function 'getstring':
_regex.c:2425: error: invalid type argument of '->'
_regex.c: In function 'getstring':
_regex.c:2425: error: invalid type argument of '->'
lipo: can't figure out the architecture type of: /var/tmp//
ccT3oDXD.out
error: command 'gcc' failed with exit status 1

resp. on Linux:

_regex.c: In function 'getstring':
_regex.c:2425: warning: implicit declaration of function 'Py_TYPE'
_regex.c:2425: error: invalid type argument of '->'
_regex.c: In function 'get_match_replacement':
_regex.c:2900: warning: implicit declaration of function
'PyLong_AsSsize_t'
error: command 'gcc' failed with exit status 1

With the official Python 2.6 distribution for Mac OS X it works.


The source code is intended to replace the current 're' module in Python
2.7 (and I'll be porting it to Python 3.2), so I'm not that worried
about Python versions earlier than 2.6 for testing, although if there's
sufficient need then I could tweak the sources for 2.5.
--
http://mail.python.org/mailman/listinfo/python-list


Language detector for Python using en-gram.

2009-07-28 Thread varun
One of my friend suggested me to do a language detector for python.At
present the language detector in python is in uni-gram mode and i have
planned to do it in en-gram mode.Kindly give me your suggestion as i am
doing this as my final year project.


With Anticipation,

Varun V. Kumar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: M2Crypto hangs on this URL

2009-07-28 Thread Martin P. Hellwig

John Nagle wrote:

Martin P. Hellwig wrote:

John Nagle wrote:

John Nagle wrote:

John Nagle wrote:

There's something strange about this URL:

"https://sagar310.pontins.com/sraep/";

...
It looks to me like the SSL handshake is not done properly from the 
server side.


Compare the output of:
openssl s_client -host sagar310.pontins.com -port 443 -debug 
-showcerts -msg


With (for example):
openssl s_client -host www.google.com -port 443 -debug -showcerts -msg


  OpenSSL is clearly not happy with that site.  But it doesn't hang.

openssl s_client -host sagar310.pontins.com -port 443 -debug -showcerts  
-msg


eventually prints

"Verify return code: 19 (self signed certificate in certificate chain)"
That's weird, because there's a Verisign certificate in the chain.
That site is somehow mishandling its certs.

My problem, though, is that M2Crypto 0.17 is hanging for hours to days
on those connections.

John Nagle


Well it hanged when I tried it, however the site now does return 
something when using Firefox, so I assume somebody is doing some work 
there or the server decided to do something else.


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Gracefully exiting CLI application

2009-07-28 Thread David
Il Tue, 28 Jul 2009 14:31:56 +0100, Nobody ha scritto:

> Killed by what means?
> 
> Ctrl-C sends SIGINT which is converted to a KeyboardInterrupt exception.
> This can be caught, or if it's allowed to terminate the process, any exit
> handlers registered via atexit.register() will be used.
> 
> For other signals, you can install a handler with signal.signal(). This
> can call sys.exit() or raise an exception (e.g. KeyboardInterrupt).
> 
> OTOH, if the process is terminated by SIGKILL, there's nothing you can do
> about it. And although it's possible to trap SIGSEGV, you shouldn't assume
> that the Python interpreter is still functional at this point.

I'm really sorry guys, I forgot to mention that the platform is win32, where
there is minimal support to signals.

Anyway I've found a solution with win32api.SetConsoleCtrlHandler that
installs a event handler which traps all windows events, CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT included.

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


C function taking double pointer to a structure variable as OUTPUT parameter

2009-07-28 Thread fengmang_python
Hi, Everyone,
I am a newbie to both Swig and Python. I am trying to export a set of C APIs to 
Python. 
My C function is 
int getInfor( char* name, int height, int weight, Infor** infor) //where infor 
is an OUTPUT parameter
{
..
*infor = (Infor*)malloc(sizeof(Infor));
..
}
 
The declare of structure Infor is :
 typedef struct {
 char  name[20];
 int   height;
 int   weight;
} Infor
 
When wrote the below lines in the interface file named Extest.i
%module Extest
%{
#include "Extest.h"
%}
%typemap(out) Infor **OUTPUT {Infor **c}
%apply int *OUTPUT {int *c}
%include "Extest.h"
 
And then, How to write testing python file to call the function named 
getInfor()?
such as in test.py
 
infor = Extest.Infor()
res = Extest.getInfor("Test Name", 175, 80, infor)
 
when run upper's test.py, Error occured. The message is 
TypeError: in method 'getInfor', argument 4 of type 'Infor **'
 
How to write the test.py to transfer the  'Infor **' type's parameter?
After putting lot of trail and errors, I am writing this mail.
Could you please help me to write the test.py or swig interface file for the 
above function?
Thank you,
jemmy
Awaiting you-- 
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread Dimiter "malkia" Stanev

Xah Lee wrote:


PHP is functional.


PHP is functional, as in "it functions!". PHP is not functional, as in 
"it ain't functions!"

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


Re: Discovery IP in connection

2009-07-28 Thread Djames Suhanko
Thanks, all!
 I didn't tried to print addr. :-(
 sorry all. I'm learning python yet.
Thanks again !

On Mon, Jul 27, 2009 at 8:23 PM, Piet van Oostrum wrote:
>> Djames Suhanko  (DS) wrote:
>
>>DS> Hello,all!
>>DS>  I wrote a little programa that listening UDP packets. A can receive
>>DS> the messages, but I can't see the the origin IP.
>>DS>  How can I to  get the remote IP address in connection?
>
> What do you think the addr is for in
> data, addr = mySocket.recvfrom(100)?
>
>>DS> My source:
>
>>DS> #!/usr/bin/env python
>>DS> import socket
>>DS> mySocket = socket.socket ( socket.AF_INET, socket.SOCK_DGRAM )
>>DS> mySocket.bind ( ( '', 514 ) )
>
>>DS> data, addr = mySocket.recvfrom(100)
>>DS> print data
>
> --
> Piet van Oostrum 
> URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
> Private email: [email protected]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Djames Suhanko
LinuxUser 158.760
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bad certificate error

2009-07-28 Thread Piet van Oostrum
> jakecjacobson  (j) wrote:

>j> On Jul 28, 9:48 am, Jean-Paul Calderone  wrote:
>>> On Tue, 28 Jul 2009 03:35:55 -0700 (PDT), jakecjacobson 
>>>  wrote:
>>> > [snip]
>>> 
>>> >"Invalid how?  Self signed certificate? Domain mismatch? Expired
>>> >certificate?"  It is a server name mismatch.
>>> 
>>> Python 2.4 is not capable of allowing you to customize this verification
>>> behavior.  It is hard coded to let OpenSSL make the decision about whether
>>> to accept the certificate or not.
>>> 
>>> Either M2Crypto or pyOpenSSL will let you ignore verification errors.  The
>>> new ssl module in Python 2.6 may also as well.
>>> 
>>> Jean-Paul

>j> Thanks, I will look into these suggestions.


>j> # cert_file is a PEM formatted certificate chain file.
>j> connection = httplib.HTTPSConnection(host, int(port), key_file,
>j> cert_file)

What happens if you set cert_file to None? This would indicate that you
are not interested in the server's certificate.

By the way, is the cert_file you supply the certificate of the CA that
signed the server's cert (in contrast to yours)?
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Pyjamas 0.6pre2 Python Web Widget Set and Javascript Compiler

2009-07-28 Thread Luke Kenneth Casson Leighton
http://pyjs.org

this is a pre-release announcement, 0.6pre2, of the pyjamas widget set
and python-to-javascript compiler.  there are over 110 entries in the
CHANGELOG since the last stable release, 0.5p1, and so it was deemed
sensible to invite people to test this version before its next stable
release, 0.6.

pyjamas, being a port of GWT to python, comprises four main components:
* a stand-alone python-to-javascript compiler
* a desktop-based wrapper around python-xpcom or pywebkitgtk
* a browser "DOM" model wrapper interface
* a widget set similar to pygtk2 / pyqt4, based on DOM manipulation

significantly in the 0.6 series, pyjamas-desktop has been incorporated
into the build: "python Hello.py" will start a stand-alone app (just
as you would with pygtk2 or pyqt4) and "pyjsbuild Hello" will compile
the javascript version(s).

the combination means that pyjamas can run python applications -
unmodified - in all major web browsers, or on the desktop (using gecko
or webkit) in a similar fashion to adobe AIR.

in the javascript version: somewhere along the line, a massive
performance hit was introduced by accident. this has now been fixed.
however, random desperate attempts to improve performance, before the
mistake was corrected, mean that the pyjamas 0.6pre2
python-to-javascript compiler produces code that is stunningly quick.

also in the 0.6pre2 release, "strict" python options have now been
introduced, so that developers can expect much more support for the
standard python 2.5 / 2.6 language semantics.  the "-O" option
disables many of these features, bringing a quite significant speed
increase, by sacrificing python compatibility.  that's just the way it
has to be.

downloads can be found by following the links from http://pyjs.org -
sourceforge, code.google.com, pypi, all the usual places.

lastly - thank you to everyone who's helped with pyjamas: bernd,
bernd, jurgen, christian, kees, ondrej and many more, and especially
thank you to the people who helped out by pointing out bugs in the
0.6pre1 release, please keep it up!

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


instead of depending on data = array('h') .. write samples 1 by 1 to w = wave.open("wav.wav", "w")

2009-07-28 Thread '2+
it says
Wave_write.writeframes(data)
will that mean
"from array import array"
is a must?

this does the job:

import oil
import wave
from array import array

a = oil.Sa()

w = wave.open("current.wav", "w")
w.setnchannels(2)
w.setsampwidth(2)
w.setframerate(44100)

data = array('h')

for gas in range(44100 * 5):
a.breath()
r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
data.append(r)
data.append(l)

w.writeframes(data.tostring())
w.close()

don't like array becoming so huge so tested this and it was also okay:

for gas in range(44100 * 5):
a.breath()
data = array('h')
r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
data.append(r)
data.append(l)
w.writeframes(data.tostring())

but without array .. it becomes 15secs(3 times longer than was
intended to be) of wav file:

for gas in range(44100 * 5):
a.breath()
r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
w.writeframes(hex(r))
w.writeframes(hex(l))

should i just be happy with depennding on using array?
or is there a solution to make the last one work properly?

tia

-- 
SaRiGaMa's Oil Vending Orchestra
is podcasting:
http://sarigama.namaste.jp/podcast/rss.xml
and supplying oil.py for free:
http://oilpy.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


xlrd - insert column?

2009-07-28 Thread LeeRisq
Does xlrd have the capability to insert a column?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New implementation of re module

2009-07-28 Thread William Dode
On 28-07-2009, MRAB wrote:

> With the official Python 2.6 distribution for Mac OS X it works.
>> 
> The source code is intended to replace the current 're' module in Python
> 2.7 (and I'll be porting it to Python 3.2), so I'm not that worried
> about Python versions earlier than 2.6 for testing, although if there's
> sufficient need then I could tweak the sources for 2.5.

I understand now why i could'nt compile it !

So, i would like if it's not too much work for you.

-- 
William Dodé - http://flibuste.net
Informaticien Indépendant
-- 
http://mail.python.org/mailman/listinfo/python-list


Need help in passing a "-c command" argument to the interactive shell.

2009-07-28 Thread Bill
On my windows box I type => c:\x>python -c "import re"

The result is => c:\x>

In other words, the Python interactive shell doesn't even open. What
am I doing wrong?

I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on
argument passing, but to no avail.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extract images from PDF files

2009-07-28 Thread writeson
David,

Thanks for your reply, I'll take a look at pdftohtml and see if it
suits my needs.

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


Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-28 Thread Ben
On Jul 22, 1:04 pm, davidj411  wrote:

> i think "Piet van Oostrum" has resolved my issue.
> good eyes!

Well, he *is* Dutch...

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


"Deprecated sets module" with Python 2.6

2009-07-28 Thread Virgil Stokes
I would appreciate help on correcting a problem when trying to create an 
*.exe file using py2exe via GUI2exe with Python 2.6.2.


When using GUI2exe to create an *.exe I always get the following warning 
during the compile process:


C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
DeprecationWarning: the sets module is deprecated
import sets

and this results in the creation of an *.exe file that can not be executed.

On the other hand, if I use the same procedure (on the same Python code) 
with

Python 2.5, there are no warnings and the *.exe works fine.

The procedure used is that given in the example "Less simpler one" at

 http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin

Any suggestions, help, ... would be greatly appreciated.

Thanks,
--V.

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


Re: Need help in passing a "-c command" argument to the interactive shell.

2009-07-28 Thread Philip Semanchuk


On Jul 28, 2009, at 4:16 PM, Bill wrote:


On my windows box I type => c:\x>python -c "import re"

The result is => c:\x>

In other words, the Python interactive shell doesn't even open. What
am I doing wrong?


Nothing! =) The -c option tells Python to execute the commands in the  
quotes as a Python program. It's as if you wrote a Python program that  
contained only "import re" and then executed that program.


If you want to run the Python interpreter interactively, just type  
"python" (no quotes) at the command prompt and hit enter.




I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on
argument passing, but to no avail.


Yikes, that's the documentation for Python 1.5.2 which is nine years  
old! If that's the version you're running, then it's appropriate to  
read that documentation, but that's probably not the case.


"python --version" (again, no quotes) should tell you what version  
you're running.


HTH
Philip

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


Re: xlrd - insert column?

2009-07-28 Thread Tino Wildenhain

LeeRisq wrote:

Does xlrd have the capability to insert a column?


rd means ReaD, so there is nothing it could insert
something to. Of course once you have read the data
you can manipulate its structure how you like it.

The counterpart is xlwt and it can write excel files
however you like it.

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


Re: "Deprecated sets module" with Python 2.6

2009-07-28 Thread MRAB

Virgil Stokes wrote:
I would appreciate help on correcting a problem when trying to create an 
*.exe file using py2exe via GUI2exe with Python 2.6.2.


When using GUI2exe to create an *.exe I always get the following warning 
during the compile process:


C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
DeprecationWarning: the sets module is deprecated
import sets

and this results in the creation of an *.exe file that can not be executed.

On the other hand, if I use the same procedure (on the same Python code) 
with

Python 2.5, there are no warnings and the *.exe works fine.

The procedure used is that given in the example "Less simpler one" at

 http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin

Any suggestions, help, ... would be greatly appreciated.


The 'sets' module is deprecated in Python 2.6 because 'set' was added as
a new builtin class. I don't know why that would result in a .exe file
that can't be executed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need help in passing a "-c command" argument to the interactive shell.

2009-07-28 Thread Mark Lawrence

Bill wrote:

On my windows box I type => c:\x>python -c "import re"

The result is => c:\x>

In other words, the Python interactive shell doesn't even open. What
am I doing wrong?

I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on
argument passing, but to no avail.
You've told python to run the command "import re" which it's happily 
done before exiting.  Simply type python, then at the prompt (default 
>>>) type whatever commands you wish, e.g.


c:\Users\Mark\python\regex>python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit 
(Intel)] on

win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> help(re.compile)
Help on function compile in module re:

compile(pattern, flags=0)
Compile a regular expression pattern, returning a pattern object.

>>>

--
Kindest regards.

Mark Lawrence.

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


Re: need help using Tkinter

2009-07-28 Thread Mark Roseman
 MRAB  wrote:
> Manzur Ahmed wrote:
> > i wanted to ask you if one of you could help me to use Tkinter. i'm 
> > trying to just create a simple GUI for which I have provided the code 
> > for below.
> There are some differences between Python 3.x and Python 2.x. In Python
> 3.1 the module is called "tkinter", not "Tkinter" (names are
> case-sensitive).


Further to the above, you can find my Tkinter tutorial (which uses 
Python 3.x) at http://www.tkdocs.com -- I hope this will provide some 
help in getting up to speed.

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


Re: Override a method but inherit the docstring

2009-07-28 Thread Shai
On Jul 26, 6:55 pm, [email protected] (Aahz) wrote:
>
> Nice!  Maybe stick this on the Cookbook?

http://code.activestate.com/recipes/576862/

Thanks for the suggestion,

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


Re: New implementation of re module

2009-07-28 Thread Aahz
In article ,
MRAB   wrote:
>Aahz wrote:
>> In article ,
>> MRAB   wrote:
>>> I've been working on a new implementation of the re module. The details
>>> are at http://bugs.python.org/issue2636, specifically from
>>> http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for
>>> Python 2.6 on Windows if you want to try it out.
>> 
>> How does it handle the re module's unit tests?
>
>Basically, it passes all those tests I expect it to pass. :-)
>
>It fails those where the intended behaviour has changed, such as re.sub
>treating unmatched groups as empty strings, as requested in
>http://bugs.python.org/issue1519638.

Then you should definitely publish to PyPI and post a message to
c.l.py.announce to get more users.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread magicus
On Tue, 28 Jul 2009 16:11:02 +0100, MRAB 
wrote:

> Hendrik van Rooyen wrote:
>> On Monday 27 July 2009 16:49:25 Aahz wrote:
>>> In article ,
>>>
>>> Hendrik van Rooyen   wrote:
 On Sunday 26 July 2009 21:26:46 David Robinow wrote:
>  I'm a mediocre programmer. Does this mean I should switch to PHP?
 I have searched, but I can find nothing about this mediocre language.

 Could you tell us more?

>>> :-P
>>>
>>> (For anyone who is confused by Hendrik's humor, he is saying that
>>> David was referring to a programming language named "mediocre". 
>>> English grammar is confusing!)
>> 
>> This is true - I intended, when I started the post, to make a crack
>> about how he knew that he was mediocre - If there were some exam or
>> test that you have to pass or fail to be able to make the claim to
>> mediocrity. I was imagining a sort of devil's rating scale for
>> programmers, that could cause one to say things like:  "I am studying
>> hard so that I can get my mediocre certificate, and one day I hope to
>> reach hacker rank".
>> 
>> And then the similarity to "I am a COBOL programmer" struck me, and I
>> abandoned the ratings.
>> 
> If you were a "COBOL" programmer, would you want to shout about it? :-)

The last time I wrote anything in COBOL was sometime in the early 80s.
Somehow that makes me feel good, heh.

ciao,
f

-- 
“Using words to describe magic is like using a screwdriver to cut roast 
beef.”
-- Tom Robbins
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C function taking double pointer to a structure variable as OUTPUT parameter

2009-07-28 Thread Diez B. Roggisch

[email protected] schrieb:

Hi, Everyone,

I am a newbie to both Swig and Python. I am trying to export a set of C 
APIs to Python.


If you are really dealing with a plain C-api, don't bother using SWIG - 
use ctypes. It comes with python >=2.5, is availabe as extra module for 
earlier versions, and makes wrapping C-libs a breeze.


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


Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Weidong
On Jul 28, 12:37 pm, Christian Heimes  wrote:
> 'make install' shouldn't compile any libraries if you run 'make' prior
> to 'make install'. I suggest you start again with a clean build tree of
> Python 2.6.2.
>
> Christian

You are perfectly right.  I started everything again after a "make
distclean".  This time I configured it as follows:

./configure --enable-unicode=ucs2 --enable-shared

to make things explicit, although I guess that the defaults would be
the same even when "--enable-unicode=ucs2 --enable-shared" are not
specified (in my case where ucs4 is not available).  The Makefile
generated then contains meaningful flags in RUNSHARED which was absent
before.

With this configuration, "make" was fine, except it "only" has the
following problems:

Failed to find the necessary bits to build these modules:
bsddb185   gdbm   sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for
the module's name.

That was not surprised because I did not have those available on my
machine.

The unicodedata.so was also created in the "make" process, and "make
install" showed no problem.

"make test" showed the following problems:

test_aepack
test_aepack skipped -- No module named aepack
test_al
test_al skipped -- No module named al
test_anydbm
Exception bsddb.db.DBRunRecoveryError: DBRunRecoveryError(-30974,
'DB_RUNRECOVERY: Fatal error, run database recovery -- PANIC: fatal
region error detected; run recovery') in  ignored

I guess this is caused by the missing bsddb185.  However, the problem
is, "make test" seemed to be hanging at that fatal error.

Do you know how critical are those failed tests?

Thanks for your help!

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


Re: "Deprecated sets module" with Python 2.6

2009-07-28 Thread Diez B. Roggisch

Virgil Stokes schrieb:
I would appreciate help on correcting a problem when trying to create an 
*.exe file using py2exe via GUI2exe with Python 2.6.2.


When using GUI2exe to create an *.exe I always get the following warning 
during the compile process:


C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
DeprecationWarning: the sets module is deprecated
import sets

and this results in the creation of an *.exe file that can not be executed.

On the other hand, if I use the same procedure (on the same Python code) 
with

Python 2.5, there are no warnings and the *.exe works fine.

The procedure used is that given in the example "Less simpler one" at

 http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin

Any suggestions, help, ... would be greatly appreciated.


If you don't need your app running on python2.3 and earlier, just remove 
the sets-module and replace it with the builtin "set".


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


Re: FTP Offset larger than file.

2009-07-28 Thread Bakes
On Jul 28, 5:36 pm, Dave Angel  wrote:
> Bakes wrote:
> > On 28 July, 15:18, Bakes  wrote:
>
> >> On 28 July, 15:01, Hrvoje Niksic  wrote:
>
> >>> Bakes  writes:
>
>  The error I get is:
>  ftplib.error_temp: 451-Restart offset 24576 is too large for file size
>  22852.
>  451 Restart offset reset to 0
>  which tells me that the local file is larger than the external file,
>  by about a kilobyte. Certainly, the local file is indeed that size, so
>  my local script is doing the right things. I do wonder what is going
>  wrong, can anyone enlighten me?
>
> >>> I'd say you failed to take buffering into account.  You write into a
> >>> buffered file, yet you use os.path.getsize() to find out the current
> >>> file size.  If the data is not yet flushed, you keep re-reading the same
> >>> stuff from the remote file, and writing it out.  Once the buffer is
> >>> flushed, your file will contain more data than was retrieved from the
> >>> remote side, and eventually this will result in the error you see.
>
> >>> As a quick fix, you can add a file.flush() line after the
> >>> file.write(...) line, and the problem should go away.
>
> >> Thank you very much, that worked perfectly.
>
> > Actually, no it didn't. That fix works seamlessly in Linux, but gave
> > the same error in a Windows environment. Is that expected?
>
> This is a text file you're transferring.  And you didn't specify "wb".  
> So the Windows size will be larger than the Unix size, since you're
> expanding the newline characters.
>
> getsize() is looking at the size after newlines are expanded to 0d0a,
> while The remote file, presumably a Unix system likely has just has 0a.
>
> I think you'd do best just keeping track of the bytes you've written.
>
> DaveA

Thank you very much, that worked perfectly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Semaphore Techniques

2009-07-28 Thread John D Giotta
I'm looking to run a process with a limit of 3 instances, but each
execution is over a crontab interval. I've been investigating the
threading module and using daemons to limit active thread objects, but
I'm not very successful at grasping the documentation.

Is it possible to do what I'm trying to do and if so anyone know of a
useful example to get started?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread MRAB

magicus wrote:

On Tue, 28 Jul 2009 16:11:02 +0100, MRAB 
wrote:


Hendrik van Rooyen wrote:

On Monday 27 July 2009 16:49:25 Aahz wrote:

In article ,

Hendrik van Rooyen   wrote:

On Sunday 26 July 2009 21:26:46 David Robinow wrote:

 I'm a mediocre programmer. Does this mean I should switch to PHP?

I have searched, but I can find nothing about this mediocre language.

Could you tell us more?


:-P

(For anyone who is confused by Hendrik's humor, he is saying that
David was referring to a programming language named "mediocre". 
English grammar is confusing!)

This is true - I intended, when I started the post, to make a crack
about how he knew that he was mediocre - If there were some exam or
test that you have to pass or fail to be able to make the claim to
mediocrity. I was imagining a sort of devil's rating scale for
programmers, that could cause one to say things like:  "I am studying
hard so that I can get my mediocre certificate, and one day I hope to
reach hacker rank".

And then the similarity to "I am a COBOL programmer" struck me, and I
abandoned the ratings.


If you were a "COBOL" programmer, would you want to shout about it? :-)


The last time I wrote anything in COBOL was sometime in the early 80s.
Somehow that makes me feel good, heh.


COBOL: it feels good when you stop. :-)

(I was actually referring to the convention of all capitals representing
shouting.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread magicus
On Tue, 28 Jul 2009 23:22:29 +0100, MRAB 
wrote:

> magicus wrote:
>> On Tue, 28 Jul 2009 16:11:02 +0100, MRAB 
>> wrote:
>> 
>>> Hendrik van Rooyen wrote:
 On Monday 27 July 2009 16:49:25 Aahz wrote:
> In article ,
>
> Hendrik van Rooyen   wrote:
>> On Sunday 26 July 2009 21:26:46 David Robinow wrote:
>>>  I'm a mediocre programmer. Does this mean I should switch to PHP?
>> I have searched, but I can find nothing about this mediocre
>> language.
>>
>> Could you tell us more?
>>
> :-P
>
> (For anyone who is confused by Hendrik's humor, he is saying that
> David was referring to a programming language named "mediocre".
> English grammar is confusing!)
 This is true - I intended, when I started the post, to make a crack
 about how he knew that he was mediocre - If there were some exam or
 test that you have to pass or fail to be able to make the claim to
 mediocrity. I was imagining a sort of devil's rating scale for
 programmers, that could cause one to say things like:  "I am studying
 hard so that I can get my mediocre certificate, and one day I hope to
 reach hacker rank".

 And then the similarity to "I am a COBOL programmer" struck me, and I
 abandoned the ratings.

>>> If you were a "COBOL" programmer, would you want to shout about it?
>>> :-)
>> 
>> The last time I wrote anything in COBOL was sometime in the early 80s.
>> Somehow that makes me feel good, heh.
>> 
> COBOL: it feels good when you stop. :-)
> 

It certainly does!

> (I was actually referring to the convention of all capitals representing
> shouting.)

I rarely shout and I thought that to this day it was still referred to as 
COBOL. I am still glad that I never pursued a career in dealing w/ such a 
language.

ciao,
f

-- 
"What you resist, persists."
-- 
http://mail.python.org/mailman/listinfo/python-list


Questions on python 2.6.2 installed files

2009-07-28 Thread Weidong
I would like to build a python 2.6.2 for Linux that runs on arm-based
embeded devices.  After some experiment of building from the python
2.6.2 source, I notice that the installed files from "make install"
are much too big for an embedded system.  For example, the files it
installs to /usr/local/lib/python2.6/ dir is over 350MB.

>From the following installed files,

/usr/local/bin/python
/usr/local/lib/libpython2.6.so.1.0

I do not see they have any "direct" dependency on the files installed
in /usr/local/lib/python2.6 dir.  What are the use of those files in /
usr/local/lib/python2.6?  What is the consequence if I do not put them
on the embedded system?

Is there a good way to directly make an installation "package" (or
tarball) of python 2.6.2 from the build result?

Any advice on configuration to make the results smaller will be
greatly appreciated!

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


Re: New implementation of re module

2009-07-28 Thread Mark Lawrence

MRAB wrote:

Hi all,

I've been working on a new implementation of the re module. The details
are at http://bugs.python.org/issue2636, specifically from
http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for
Python 2.6 on Windows if you want to try it out.

I'm interested in how fast it is generally, compared with the current re
module, but especially when faced with those 'pathological' regular
expressions which seem to take a long time to finish, for example:

re.search(r"^(.+|D)*A$", "x" * 25 + "B")

which on my PC (1.8GHz) takes 18.98secs with the re module but <0.01secs 
with this new implementation.

I tried this on my 3GHz PC timings pretty much the same.

From here http://bugs.python.org/issue1721518 I knocked up this.

import time
import re
import regex

s = "Add.1, 2020 and Add.1, 2021-2023, 2025, 2028 and 2029 and Add.1) R"
r = "(?:\s|,|and|Add\S*?|Parts?|\([^\)]*\)|[IV\-\d]+)*$"
t0 = time.clock()
print regex.search(r, s)
t1 = time.clock()
print "time", t1 - t0

print "It's going to crash"
t0 = time.clock()
print re.search(r, s)
t1 = time.clock()
print "It hasn't crashed time", t1 - t0

Output shows a slight change in timing:).

<_regex.RE_Match object at 0x0243A1A0>
time 0.00279001940191
It's going to crash
<_sre.SRE_Match object at 0x024396B0>
It hasn't crashed time 98.4238155967



TIA


I also got the files bm_regex_effbot.py and bm_regex_v8.py from
http://code.google.com/p/unladen-swallow/source/browse/#svn/tests/performance 
and ran them, then reran them having substituted regex for re.  Output 
timings were roughly effbot re 0.14secs, effbot regex 1.16secs, v8 re 
0.17secs and v8 regex 0.67secs.


HTH.

--
Kindest regards.

Mark Lawrence.

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


Re: "Deprecated sets module" with Python 2.6

2009-07-28 Thread Steven D'Aprano
On Tue, 28 Jul 2009 22:28:09 +0200, Virgil Stokes wrote:

> When using GUI2exe to create an *.exe I always get the following warning
> during the compile process:
> 
>  C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
>  DeprecationWarning: the sets module is deprecated 
>  import sets

The best solution would be to change every call to sets.Set() to set(), 
and change the line:

import sets

to this:

try:
set
except NameError:
from sets import Set as set


If you use sets.ImmutableSet, you will need to change that to frozenset 
in the same way.

This assumes you don't need to support older versions of Python, before 
set() became a built-in.



-- 
Steven

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


Re: Semaphore Techniques

2009-07-28 Thread Christian Heimes
John D Giotta schrieb:
> I'm looking to run a process with a limit of 3 instances, but each
> execution is over a crontab interval. I've been investigating the
> threading module and using daemons to limit active thread objects, but
> I'm not very successful at grasping the documentation.
> 
> Is it possible to do what I'm trying to do and if so anyone know of a
> useful example to get started?

Since you are talking about crontab I assume that you are on an os that
supports pthreads. You problem can easily be solved with a named
semaphore (see sem_open(3) and sem_overview(7)). Unfortunately Python
doesn't expose named semaphores. The multiprocessing library uses named
semaphores but you can't set the name yourself.

You have to write your own C wrapper or search on pypi and through
Google. If you are going to write your own semaphore I highly recommend
Cython.

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


Re: Extract images from PDF files

2009-07-28 Thread Xavier Ho
I've got a non-Python solution if you have Acrobat 6 or up.

>From the menu, Advanced -> Document Processing -> Extract All Images...

If you need multiple PDFs done, Batch Processing would be a great start.

Then you can run another script to make the thumbnails, or use Photoshop.
Either way works!

Best regards,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: [email protected]
Website: http://xavierho.com/


On Wed, Jul 29, 2009 at 6:21 AM, writeson  wrote:

> David,
>
> Thanks for your reply, I'll take a look at pdftohtml and see if it
> suits my needs.
>
> Thanks!
> Doug
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semaphore Techniques

2009-07-28 Thread Philip Semanchuk


On Jul 28, 2009, at 7:19 PM, Christian Heimes wrote:


John D Giotta schrieb:

I'm looking to run a process with a limit of 3 instances, but each
execution is over a crontab interval. I've been investigating the
threading module and using daemons to limit active thread objects,  
but

I'm not very successful at grasping the documentation.

Is it possible to do what I'm trying to do and if so anyone know of a
useful example to get started?


Since you are talking about crontab I assume that you are on an os  
that

supports pthreads. You problem can easily be solved with a named
semaphore (see sem_open(3) and sem_overview(7)). Unfortunately Python
doesn't expose named semaphores. The multiprocessing library uses  
named

semaphores but you can't set the name yourself.

You have to write your own C wrapper or search on pypi and through
Google. If you are going to write your own semaphore I highly  
recommend

Cython.


My POSIX IPC extension permits manipulation of interprocess semaphores:
http://semanchuk.com/philip/posix_ipc/

There's also one for SysV IPC:
http://semanchuk.com/philip/sysv_ipc/

Enjoy
P

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


Re: Semaphore Techniques

2009-07-28 Thread David Bolen
John D Giotta  writes:

> I'm looking to run a process with a limit of 3 instances, but each
> execution is over a crontab interval. I've been investigating the
> threading module and using daemons to limit active thread objects, but
> I'm not very successful at grasping the documentation.
>
> Is it possible to do what I'm trying to do and if so anyone know of a
> useful example to get started?

Does it have to be built into the tool, or are you open to handling the
restriction right in the crontab entry?

For example, a crontab entry like:

  * * * * * test `pidof -x script.py | wc -w` -ge 4 || /script.py

should attempt to run script.py every minute (adjust period as
required) unless there are already four of them running.  And if pidof
isn't precise enough you can put anything in there that would
accurately check your processes (grep a ps listing or whatever).

This works because if the test expression is true it returns 0 which
terminates the logical or (||) expression.

There may be some variations based on cron implementation (the above
was tested against Vixie cron), but some similar mechanism should be
available.

If you wanted to build it into the tool, it can be tricky in terms of
managing shared state (the count) amongst purely sibling/cooperative
processes.  It's much easier to ensure no overlap (1 instance), but
once you want 'n' instances you need an accurate process-wide counter.
I'm not positive, but don't think Python's built-in semaphores or
shared memory objects are cross-process.  (Maybe something in
multiprocessing in recent Python versions would work, though they may
need the sharing processes to all have been executed from a parent
script)

I do believe there are some third party interfaces (posix_ipc,
shm/shm_wrapper) that would provide access to posix shared-process
objects.  A semaphore may still not work as I'm not sure you can
obtain the current count.  But you could probably do something with
a shared memory counter in conjunction with a mutex of some sort, as
long as you were careful to clean it up on exit.

Or, you could stick PIDs into the shared memory and count PIDs on
a new startup (double checking against running processes to help
protect against process failures without cleanup).

You could also use the filesystem - have a shared directory where each
process dumps its PID, after first counting how many other PIDs are in
the directory and exiting if too many.

Of course all of these (even with a PID check) are risky in the
presence of unexpected failures.  It would be worse with something
like C code, but it should be reasonably easy to ensure that your
script has cleanup code even on an unexpected termination, and it's
not that likely the Python interpreter itself would crash.  Then
again, something external could kill the process.  Ensuring accuracy
and cleanup of shared state can be non-trivial.

You don't mention if you can support a single master daemon, but if
you could, then it can get a little easier as it can maintain and
protect access to the state - you could have each worker process
maintain a socket connection of some sort with the master daemon so it
could detect when they terminate for the count, and it could just
reject such connections from new processes if too many are running
already.  Of course, if the master daemon goes away then nobody would
run, which may or may not be an acceptable failure mode.

All in all, unless you need the scripts to enforce this behavior even
in the presence of arbitrary use, I'd just use an appropriate crontab
entry and move on to other problems :-)

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


  1   2   >