Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-27 Thread John Nagle

Steven D'Aprano wrote:

On Sun, 26 Jul 2009 11:24:48 -0700, John Nagle wrote:


 An interesting issue is Python objects, which are always mutable.
A "dict" of Python objects is allowed, but doesn't consider the contents
of the objects, just their identity (address). Only built-in types are
immutable; one cannot create a class of immutable objects.


Yes you can, for some definition of "can":

http://northernplanets.blogspot.com/2007/01/immutable-instances-in-python.html


Admittedly pure Python objects are only "cooperatively immutable". 


   Right.  I've been thinking about this as a way of improving
concurrency handling.  The general idea is that objects shared
across threads would have to be either be immutable or synchronized.
Regular objects would be limited to a single thread.  It's a path
to multithread programs without a global lock.  Needs more work
to become a serious proposal.  (It may not be worth the trouble;
a few years ago we were hearing about how 64-core CPUs were going
to become mainstream, but instead, the industry is going in the
direction of the same compute power for less money and with
less power consumption.)

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


Problem in PyArg_ParseTuple on python 2.5.2 with AIX

2009-07-27 Thread abhi
Hi,
I am facing a problem using PyArg_ParseTuple() in my C-API
extension. Here is a small repro of the function:

static PyObject *parsetuple_test(PyObject *self, PyObject *args)
{
SQLUSMALLINT param_no = 0;
PyObject *py_obj = NULL;

if (!PyArg_ParseTuple(args, "Oi", &py_obj, ¶m_no)){

return NULL;
}
printf("%d\n", param_no);
return NULL;
}

This function works fine and prints the correct value passed
(param_no) when I test it on Linux or Windows. However, it always
prints 0 (initial value defined in function) when I run it on AIX.

I think the problem is with "Oi" argument, if I replace that with "OO"
and specifically convert it integer/sqlsmallint. It works fine on AIX,
but I want to use "i" and not "O".

Any ideas on what is the reason behind the problem and how to fix
this?

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


open a file in python

2009-07-27 Thread jayshree
pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()

Please tell me how to open a file placed in any directory or in same
directory.

After opening this file i want to use the contain (public key ) for
encryption





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


Re: web page retrieve problems

2009-07-27 Thread Alex
On Jul 26, 8:57 am, golu  wrote:
> the following function retrieves pages from the web and saves them in
> a specified dir. i want to extract the respective filenames from the
> urls e.g the page code.google.com shud be saved as code-google.htm  or
> something similar. can u suggest me a way to do it

Try with urllib.urlretrieve from standard lib:

urllib.urlretrieve(url[, filename[, reporthook[, data]]])¶
Copy a network object denoted by a URL to a local file, if necessary.
If the URL points to a local file, or a valid cached copy of the
object exists, the object is not copied. Return a tuple (filename,
headers) where filename is the local file name under which the object
can be found, and headers is whatever the info() method of the object
returned by urlopen() returned (for a remote object, possibly cached).
Exceptions are the same as for urlopen().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open a file in python

2009-07-27 Thread Kushal Kumaran
On Mon, Jul 27, 2009 at 12:58 PM, jayshree wrote:
> pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
>
> Please tell me how to open a file placed in any directory or in same
> directory.
>
> After opening this file i want to use the contain (public key ) for
> encryption
>

Does the code you've put into your message not read that file?  If you
get an exception, copy-paste in the traceback message you get into
your mail.

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


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

2009-07-27 Thread Piet van Oostrum
> Dotan Cohen  (DC) wrote:

>DC> Referring to this article:
>DC> 
>http://math-blog.com/2009/07/20/complex-algorithm-research-and-development-harder-than-many-think/

>DC> The author, who is specifically looking for math-related functions, writes:
>DC> """
>DC> The dream algorithm R&D tool would be similar to Matlab or Mathematica
>DC> but could be compiled to fast, efficient binaries similar to ANSI C
>DC> and would be available for all platforms. An integrated GUI builder
>DC> similar to Visual Basic and integrated network support would be
>DC> helpful.
>DC> """

>DC> It looks to me like he is looking for Python.

No fast, efficient binaries yet, and no integrated GUI builder.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2009-07-27 Thread 9372966370
(Re: urllib2.URLError:  error using
twill with python)  how can i change url/http://...
 -
Sent by a Cricket mobile device
 -
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2009-07-27 Thread 9372966370
(Re: urllib2.URLError:  error using
twill with python)
 -
Sent by a Cricket mobile device
 -
-- 
http://mail.python.org/mailman/listinfo/python-list


SEC doc parsing

2009-07-27 Thread Michael Boldin

I am looking for any parsing routines (written in python), for Security 
Exchange Commision (SEC) documents. These documents are on the SEC's EDGAR 
system  (at  ftp://ftp.sec.gov ) and I am especially interested in insider 
trading files known as Forms 3,4 and 5.

 

_
NEW mobile Hotmail. Optimized for YOUR phone.  Click here.
http://windowslive.com/Mobile?ocid=TXT_TAGLM_WL_CS_MB_new_hotmail_072009-- 
http://mail.python.org/mailman/listinfo/python-list


Re: invoke method on many instances

2009-07-27 Thread Aahz
In article ,
Gabriel Genellina  wrote:
>
>Ok, if you insist...
>
>NLMPI = Ni La Más Puta Idea.
>IHNFI = I Have No Fucking Idea.

Thanks!
-- 
Aahz (a...@pythoncraft.com)   <*> 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: how can a child thread notify a parent thread its status?

2009-07-27 Thread davidj411
could i see an example of this maybe?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-27 Thread greg

Bearophile wrote:


Was this link, shown by William, not enough?
http://hg.flibuste.net/libre/games/cheval/file/46797c3a5136/chevalx.pyx#l1


Yes, sorry, I posted too soon.

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


Re: Computation/E-mail Expert opinions?

2009-07-27 Thread Diez B. Roggisch

scribio_vide schrieb:

MAIL From: 
From: "tommy02" 
To: "MeAmI" 
Subject: I AM LOOKING FORWARD TO YOUR ANSWER ON THIS ISSUE
Date: Fri, 24 Jul 09 11:52:27 Pacific Daylight Time
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary= "
=_NextPart_000_008C_8F228C8E.684AAFEA"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2462.
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.

--=_NextPart_000_008C_8F228C8E.684AAFEA
Content-Type: text/plain
Content-Transfer-Encoding: base64






ZXRtYWlsLmNvbQ0KICAgIA==
--=_NextPart_000_008C_8F228C8E.684AAFEA--

Any ides why I this came to be in my inbox?


It is either an extremely dangerous virus - or an utterly harmless, but 
annoying base64-encoded spam-mail, given the subject.


None of the possibilities justifies a post to *three* newsgroups.

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


Re: How can I get the line number ?

2009-07-27 Thread kk
Maxim,

Thank you so much. I will try right now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding method from one class to another class or to instance of another class

2009-07-27 Thread marekw2143
Thanks for your responses. im_func is all I need. I considered
subclassing, wchih is more easy to extend, but I needed some quick way
to add a method to another class.

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


Re: Itext for Python

2009-07-27 Thread S.Selvam
On Sun, Jul 26, 2009 at 11:52 PM, Santhosh Kumar
wrote:

> Hi all,   One of my cousin  suggested me to do a IText
> PDF converter for python. Actually I heard that there is
> no separate IText converter either we have to go for jython or GCJ with
> wrapper. Instead of wrapping, my plan is to create a separate module with
> Python and I am thinking of doing this in as my final year project also.
> Kindly give me your suggestion.
>


As for as i know, no pure python module exists for iText PDF generator,
where iText seems to be a standard one for PDF related works.There are some
other modules for pdf work but might not be as standard as iText.Surely some
senior programmers  will suggest you better way to proceed further.


> With anticipation,
>
> SanthoshVKumar.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Yours,
S.Selvam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I generate dia diagrams from python source code?

2009-07-27 Thread Vesa Köppä

Qauzzix wrote:

Greetings.

Since I have been using dia to make my UML diagrams. I also found an
util named dia2code that generates python code from dia diagram. Now
that I have that option I really want to find a way to generate dia
diagram from existing code and/or maintain my diagrams.

I have been googling  like crazy trying to find a way but with no
luck. Anyone here know how to do this?

Peace,
 - Jakob Sv. Bjarnason


Hi.

There is this utility called autodia.
http://www.aarontrevena.co.uk/opensource/autodia/
I think it does what you want. It is written in perl.
It can read several languages and outputs dia diagrams.

BTW, I found it by going to dia2code homepage and then to
its links page. It is listed in there.

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


Re: Globalize all variables in function without knowing names.

2009-07-27 Thread Tom
> Dictionaries are fundamental to Python and very useful. Not learning
> about them before starting to write code is like not learning about the
> accelerator pedal before starting to drive a car.

Heh, I just looked at the actual tutorial for Dictionaries and I have
to say they are very useful. Basically just arrays with strings(or any
other data type, except lists) instead of numbers. I'll work on trying
to integrate them into my language code as, like you said, user
data... Then when a user requests a variable it just accessess the
dictionary, that should work. Thanks!
This is easier than I thought.

> Have you done the tutorial?

I did the first few sections, and then flipped back to it later on to
find out what I needed to know as I coded applications. A bad idea, in
retrospect, particilary as it slowed down my coding time alot.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-07-27 Thread Hendrik van Rooyen
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?

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


Re: missing 'xor' Boolean operator

2009-07-27 Thread Mark Dickinson
On Jul 27, 1:53 am, "Delaney, Timothy (Tim)" 
wrote:
> Mark Dickinson wrote:
> >> Since the 'and' and 'or' already return objects (and objects
> >> evaluate to true or false), then 'xor' should behave likewise, IMO.
> >> I expect that would be the case if it were ever added to the
> >> language.
>
> > I'm not so sure.  Did you ever wonder why the any() and all()
> > functions introduced in 2.5 return a boolean rather than returning
> > one of their arguments?  (I did, and I'm still not sure what the
> > answer is.)
>
> Consider the case of any() and all() operating on an empty iterable.
> What type should they return?
>
> It is impossible in the case of any() and all() to always return one of
> the elements due to this edge case.

Yes, of course; the alternative implementation I was thinking of
was the one that I implemented eons ago for my own pre-2.5 code,
where I defined any and all roughly as:

any([x1, x2, x3, ...]) <-> False or x1 or x2 or x3 or ...
all([x1, x2, x3, ...]) <-> True and x1 and x2 and x3 and ...

At the time this seemed like the obvious choice, so I was a bit
surprised when it was chosen to always return a bool instead in
the official versions.

Now that I'm older and wise^H^H^H^H, well, maybe just older, the
pure bool version seems cleaner and less error-prone, even if
it's mildly inconsistent with the behaviour of and and or.

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


Re: Problem in PyArg_ParseTuple on python 2.5.2 with AIX

2009-07-27 Thread John Machin
On Jul 27, 5:11 pm, abhi  wrote:
> Hi,
>     I am facing a problem using PyArg_ParseTuple() in my C-API
> extension. Here is a small repro of the function:
>
> static PyObject *parsetuple_test(PyObject *self, PyObject *args)
> {
>         SQLUSMALLINT param_no = 0;

Sorry, my crystal ball is on the fritz. What is SQLUSMALLINT on
Windows/Linux/AIX?
What does
printf("%d %d %d\n", sizeof(SQLUSMALLINT), sizeof(int), sizeof
(long));
give you on each platform?

>         PyObject *py_obj = NULL;
>
>         if (!PyArg_ParseTuple(args, "Oi", &py_obj, ¶m_no)){
>
>                 return NULL;
>         }
>         printf("%d\n", param_no);
>         return NULL;
>
> }
>
> This function works fine and prints the correct value passed
> (param_no) when I test it on Linux or Windows. However, it always
> prints 0 (initial value defined in function) when I run it on AIX.

Consider that 0 could have been plucked out of the air and has nothing
to do with the initial value of param_no. Try initialising it to
something distinctive, like 0xfedcba98. Use %08x format in the printf
rather than %d.


>
> I think the problem is with "Oi" argument, if I replace that with "OO"
> and specifically convert it integer/sqlsmallint. It works fine on AIX,
> but I want to use "i" and not "O".
>
> Any ideas on what is the reason behind the problem and how to fix
> this?

I jump-started the crystal ball from the over-head tram wire and saw
this: """SQLSMALLINT is 16 bits on all platforms, int/long is 32 bits
on all platforms, first 2 are little-endian, AIX is bigendian, the "i"
format expects SIGNED int /long, so param_no is getting (win:x,
linux:x, aix:0) and the next 16 bits in memory are getting trashed
with (win:0, linux:0, aix:x) (when x is your input smallish integer)
and luckily this trashing didn't cause a crash. You can receive the
result from the function in an int/long then have code to reject it if
it won't fit into a SQLUSMALLINT, and cast it otherwise. If you don't
care about overflow (NOT recommended), just use "H" format instead if
"i" format"""

Could be wrong, really shouldn't subject precision instruments to 415V
DC, only OPs :-)

N.B. to detect endianness : use print sys.byteorder

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


Re: open a file in python

2009-07-27 Thread jayshree
On Jul 27, 1:09 pm, Kushal Kumaran 
wrote:
> On Mon, Jul 27, 2009 at 12:58 PM, jayshree wrote:
> > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
>
> > Please tell me how to open a file placed in any directory or in same
> > directory.
>
> > After opening this file i want to use the contain (public key ) for
> > encryption
>
> Does the code you've put into your message not read that file?  If you
> get an exception, copy-paste in the traceback message you get into
> your mail.
>
> --
> kushal


try:
pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
except IOError:
print "Error: can\'t find file or read data"
else:
print "reading from file successfully"

>Still no error it gives .what to do?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-07-27 Thread Mohammad Tayseer
You can generate binaries using py2exe, and you can create UI using Tkinter 
(which is very easy) or wxPython (which have GUI builders)

 Mohammad Tayseer
http://spellcoder.com/blogs/tayseer






From: Piet van Oostrum 
To: python-list@python.org
Sent: Monday, July 27, 2009 11:18:20 AM
Subject: Re: Looking for a dream language: sounds like Python to me.

> Dotan Cohen  (DC) wrote:

>DC> Referring to this article:
>DC> 
>http://math-blog.com/2009/07/20/complex-algorithm-research-and-development-harder-than-many-think/

>DC> The author, who is specifically looking for math-related functions, writes:
>DC> """
>DC> The dream algorithm R&D tool would be similar to Matlab or Mathematica
>DC> but could be compiled to fast, efficient binaries similar to ANSI C
>DC> and would be available for all platforms. An integrated GUI builder
>DC> similar to Visual Basic and integrated network support would be
>DC> helpful.
>DC> """

>DC> It looks to me like he is looking for Python.

No fast, efficient binaries yet, and no integrated GUI builder.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list



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


Re: open a file in python

2009-07-27 Thread Diez B. Roggisch
jayshree wrote:

> On Jul 27, 1:09 pm, Kushal Kumaran 
> wrote:
>> On Mon, Jul 27, 2009 at 12:58 PM, jayshree
>> wrote:
>> > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
>>
>> > Please tell me how to open a file placed in any directory or in same
>> > directory.
>>
>> > After opening this file i want to use the contain (public key ) for
>> > encryption
>>
>> Does the code you've put into your message not read that file?  If you
>> get an exception, copy-paste in the traceback message you get into
>> your mail.
>>
>> --
>> kushal
> 
> 
> try:
> pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
> except IOError:
> print "Error: can\'t find file or read data"
> else:
> print "reading from file successfully"
> 
>>Still no error it gives .what to do?

Erm - so it doesn't give an error - which means you have successfully opened
a file, and read it's contents.

So what exactly is your problem?

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


Call function from another class

2009-07-27 Thread Lars
Hi
I'm trying to make an simple image viewer in wxPython and rotate an
image with a slider. The code at Pastebin is striped down at bit. The
class Frame(wx.Frame) is the main window, the function "def
CreateMenuBar" (l. 39) creates a menu, where the function "def onRotate
(self,event):" (l. 43) is called. The slider appear in at 2nd window,
class rotationSlider(wx.Frame).
My problem is what to do, when the Okay button is pressed in the
"rotationSlider" frame. How to get the slider value to my main window
and how to call a function to do the rotation. I tried something with
a global variable, but it would make no difference regarding the
function problem. Amongst the other things I've tried is to bind the
event of the 2nd/slider window closing (l. 46), but no.
Python code at Pastebin: http://pastebin.com/m7c24ec34

So some help on Classes and etc., would be appreciated.

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


_msi.Record object has no attribute 'GetString'

2009-07-27 Thread ++imanshu
The documentation (http://docs.python.org/library/msilib.html#record-
objects) for msilib mentions the GetString() method on Record objects.
However, the following snippet :-

db = msilib.OpenDatabase(os.path.join(root, file),
msilib.MSIDBOPEN_READONLY)
view = db.OpenView('SELECT * FROM Property')
view.Execute(None)
r = view.Fetch()
print dir(r)
print r.GetString(0)

gives me this error :-

c:\>python msi.py
['ClearData', 'GetFieldCount', 'SetInteger', 'SetStream', 'SetString',
__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__new__', __reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__']
Traceback (most recent call last):
  File "msi.py", line 18, in 
print r.GetString(0)
AttributeError: '_msi.Record' object has no attribute 'GetString'

Am I missing something?

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


Re: Call function from another class

2009-07-27 Thread Diez B. Roggisch
Lars wrote:

> Hi
> I'm trying to make an simple image viewer in wxPython and rotate an
> image with a slider. The code at Pastebin is striped down at bit. The
> class Frame(wx.Frame) is the main window, the function "def
> CreateMenuBar" (l. 39) creates a menu, where the function "def onRotate
> (self,event):" (l. 43) is called. The slider appear in at 2nd window,
> class rotationSlider(wx.Frame).
> My problem is what to do, when the Okay button is pressed in the
> "rotationSlider" frame. How to get the slider value to my main window
> and how to call a function to do the rotation. I tried something with
> a global variable, but it would make no difference regarding the
> function problem. Amongst the other things I've tried is to bind the
> event of the 2nd/slider window closing (l. 46), but no.
> Python code at Pastebin: http://pastebin.com/m7c24ec34
> 
> So some help on Classes and etc., would be appreciated.

If I'm not mistaken, in "doRotate" you should be able to refer to the
to-be-closed dialog via

self.frameRotate

Now if you change the "sliderUpdate"-code to store that angle instead of
just letting it fall out of scope, you could access that value through
frameRotate:

def sliderUpdate(self, event):
angle=self.slider.GetValue()
ROTATION_ANGLE=angle
self.angle = angle 
self.Destroy()



def doRotate(self,event):
"""Rotating image"""
print self.frameRotate.angle


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


Re: Problem in PyArg_ParseTuple on python 2.5.2 with AIX

2009-07-27 Thread abhi
On Jul 27, 2:25 pm, John Machin  wrote:
> On Jul 27, 5:11 pm, abhi  wrote:
>
> > Hi,
> >     I am facing a problem using PyArg_ParseTuple() in my C-API
> > extension. Here is a small repro of the function:
>
> > static PyObject *parsetuple_test(PyObject *self, PyObject *args)
> > {
> >         SQLUSMALLINT param_no = 0;
>
> Sorry, my crystal ball is on the fritz. What is SQLUSMALLINT on
> Windows/Linux/AIX?
> What does
>     printf("%d %d %d\n", sizeof(SQLUSMALLINT), sizeof(int), sizeof
> (long));
> give you on each platform?
>
> >         PyObject *py_obj = NULL;
>
> >         if (!PyArg_ParseTuple(args, "Oi", &py_obj, ¶m_no)){
>
> >                 return NULL;
> >         }
> >         printf("%d\n", param_no);
> >         return NULL;
>
> > }
>
> > This function works fine and prints the correct value passed
> > (param_no) when I test it on Linux or Windows. However, it always
> > prints 0 (initial value defined in function) when I run it on AIX.
>
> Consider that 0 could have been plucked out of the air and has nothing
> to do with the initial value of param_no. Try initialising it to
> something distinctive, like 0xfedcba98. Use %08x format in the printf
> rather than %d.
>
>
>
> > I think the problem is with "Oi" argument, if I replace that with "OO"
> > and specifically convert it integer/sqlsmallint. It works fine on AIX,
> > but I want to use "i" and not "O".
>
> > Any ideas on what is the reason behind the problem and how to fix
> > this?
>
> I jump-started the crystal ball from the over-head tram wire and saw
> this: """SQLSMALLINT is 16 bits on all platforms, int/long is 32 bits
> on all platforms, first 2 are little-endian, AIX is bigendian, the "i"
> format expects SIGNED int /long, so param_no is getting (win:x,
> linux:x, aix:0) and the next 16 bits in memory are getting trashed
> with (win:0, linux:0, aix:x) (when x is your input smallish integer)
> and luckily this trashing didn't cause a crash. You can receive the
> result from the function in an int/long then have code to reject it if
> it won't fit into a SQLUSMALLINT, and cast it otherwise. If you don't
> care about overflow (NOT recommended), just use "H" format instead if
> "i" format"""
>
> Could be wrong, really shouldn't subject precision instruments to 415V
> DC, only OPs :-)
>
> N.B. to detect endianness : use print sys.byteorder
>
> HTH,
> John

Hi,
Thanks for the response. If I don't use SQLUSMALLINT and use int
instead, then also I see the same problem.
static PyObject *parsetuple_test(PyObject *self, PyObject *args)
 {
int param_no = 0;


}
This also prints out 0 for AIX and actual value passed in other
platforms. If I initialize param_no with some other value (e.g. 90),
it prints out that value.

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


Re: RSA cryptography between Python and Java

2009-07-27 Thread Piet van Oostrum
> Paul Rubin  (PR) wrote:

>PR> Rob Knop  writes:
>>> Are there any python libraries that will take a public key in this
>>> format and do RSA encoding on it?

>PR> Try www.trevp.com/tlslite

I have looked into tlslite and found no easy way to do this. Maybe I
overlooked it. On the other hand with M2Crypto it isn't that hard.

However, M2Crypto wants to load keys in PEM format rather than the DER
format that the Java getEncoded() produces. It is not hard to convert
this to PEM format: just Base64 encode it and put a header and trailer
line around it. The conversion can be done with openssl or just on the
fly in the Python code.
Please note that the text to be encrypted must be smaller than the key
size (at least 11 bytes smaller). You shouldn't encrypt large data with
RSA anyway: it is too slow. Normally you would encrypt a session key
with RSA and encrypt the data with the session key using a symmetric
algorithms like AES.

Here is an example script:
If your OS doesn't have /dev/urandom you should probably seed OpenSSL's
PRNG to be more secure.

from M2Crypto import BIO, RSA

pubkey = open("pubkey.der", 'rb').read()

import base64
pubkey = base64.encodestring(pubkey)
pubkey = '-BEGIN PUBLIC KEY-\n' + pubkey + '-END PUBLIC KEY-'

bio = BIO.MemoryBuffer(pubkey)
rsa = RSA.load_pub_key_bio(bio)

plaintext = "This is my secret text."

codetext = rsa.public_encrypt(plaintext, RSA.pkcs1_padding)

with open("codetext", 'wb') as out:
out.write(codetext)

The following Java program decodes this with the corresponding private
key:

import java.security.*;
import javax.crypto.*;
import java.security.spec.*;
import java.security.interfaces.*;
import java.io.*;

class Decrypt {

public static void main(String[] args) {  

byte[] key = null;
try {
File file = new File("privkey.der");
FileInputStream keyfile = new FileInputStream(file);
key = new byte[(int)file.length()];
DataInputStream dis= new DataInputStream(keyfile);
dis.readFully(key);
dis.close();
}
catch(FileNotFoundException e)
{
System.out.println("Key file not found" + e);
}
catch (IOException e) {
System.out.println("Can't read key file" + e);
}

byte[] codetext = null;
try {
File file = new File("codetext");
FileInputStream codefile = new FileInputStream(file);
codetext = new byte[(int)file.length()];

DataInputStream dis = new DataInputStream(codefile);
dis.readFully(codetext);
dis.close();
}
catch(FileNotFoundException e)
{
System.out.println("Code file not found" + e);
}
catch (IOException e) {
System.out.println("Can't read code file" + e);
}

try {

KeyFactory keyFactory = KeyFactory.getInstance("RSA");

PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(key);
RSAPrivateKey rsakey = (RSAPrivateKey) 
keyFactory.generatePrivate(privSpec);

Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");

c.init(Cipher.DECRYPT_MODE, rsakey);
byte[] decrypted = c.doFinal(codetext);
System.out.println("Decrypted text:");
System.out.println(new String(decrypted));

}
catch (NoSuchAlgorithmException e) {
System.out.println("Wrong Algorithm " + e);
}   
catch (InvalidKeyException e) {
System.out.println("Invalid key " + e);
}   
catch (IllegalBlockSizeException e) {
System.out.println("Illegal block size" + e);
}   
catch (NoSuchPaddingException e) {
System.out.println("Illegal padding " + e);
}   
catch (BadPaddingException e) {
System.out.println("Bad padding " + e);
}   
catch (InvalidKeySpecException e) {
System.out.println("Invalid keyspec " + e);
}   
}
}

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Free hosting for open source Python projects

2009-07-27 Thread Sean Kemplay
Hi All,

If anyone is looking for somewhere to host their Python project /
modules etc. for free,  please get in touch with me.  There of course
are some restraints on disk space and bandwidth but they should be
sufficient for most projects.  Your project must be open source.

You will have access to both Django or Plone/Zope(shared).  No PHP etc
- this is a Python only host.

Unfortunately I can't host everyone but if I can't host your
particular project now, I may be able to at a later stage.

Please contact me at "postmaster (at) pythonicity.co.uk".  Our website
is located at www.pythonicity.co.uk if you want to see what we do.

Best Regards,
Sean Kemplay

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


Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-27 Thread William Dode
On 27-07-2009, Bearophile wrote:
> William Dode':
>> I updated the script (python, c and java) with your unrolled version
>> + somes litle thinks.
> [...]
>> c 1.85s
>> gcj 2.15s
>> java 2.8s
>> python2.5 + psyco 3.1s
>> unladen-2009Q2 145s (2m45)
>> python2.5 254s (4m14s)
>> python3.1 300s (5m)
>> ironpython1.1.1 680s (11m20)
>
> Sorry for being late, I was away.
>
> In your last C version this code is useless because the C compiler is
> able to perform such simple optimization by itself (but probably
> Python isn't able, so if you want the code to be the similar in all
> versions it may be better to keep it):

I wanted so, specialy if it doesn't change a lot of the result (the 
difference is so small that i cannot see it)...

...

> I have tried your latest C version using your compiler options, my
> MinGW based on GCC 4.3.2 produces a crash at runtime.

Maybe because of -msse2 ?

> Using LLVM-GCC
> it runs in 1.31 seconds. The D version is a bit less optimized than
> your last C versions, yet using DMD it runs in 1.08-1.10 seconds.
> Let's see if someone is able to write a C version faster than that D
> code :-)
>
> Have you have compiled/read my D version? In the D version you may
> have missed that I did use an extra trick: unsigned integers, so it
> needs just two tests to see if a number is in the 0-5, 0-5 square :-)

I didn't see, fine ! But the difference is also too small to see...

> Note that Pyd, the Python-D bridge, may work with the latest DMD
> version still (and it works if you use a bit older DMD compiler):
> http://pyd.dsource.org/

I completly don't know anything about D... When i see the result of 
psyco or shedskin, i'm affraid i'll not look somewhere else soon !

However, i'd like to see a lisp implementation of this...

bye

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


Re: mmap 2GB allocation limit on Win XP, 32-bits, Python 2.5.4

2009-07-27 Thread Dave Angel

(forwarding this message, as the reply was off-list)
Kim Hansen wrote:

2009/7/24 Dave Angel :
  

It's not a question of how much disk space there is, but how much virtual
space 32 bits can address.  2**32 is about 4 gig, and Windows XP reserves
about half of that for system use.  Presumably a 64 bit OS would have a much
larger limit.

Years ago I worked on Sun Sparc system which had much more limited shared
memory access, due to hardware limitations.  So 2gig seems pretty good to
me.

There is supposed to be a way to tell the Windows OS to only use 1 gb of
virtual space, leaving 3gb for application use.  But there are some
limitations, and I don't recall what they are.  I believe it has to be done
globally (probably in Boot.ini), rather than per process.  And some things
didn't work in that configuration.

DaveA




Hi Dave,

In the related post I did on the numpy discussions:

http://article.gmane.org/gmane.comp.python.numeric.general/31748

another user was kind enough to run my test program on both 32 bit and
64 bit machines. On the 64 bit machine, there was no such limit, very
much in line with what you wrote. Adding the /3GB option in boot.ini
did not increase the available memory as well. Apparently, Python
needs to have been compiled in a way, which makes it possible to take
advantage of that switch and that is either not the case or I did
something else wrong as well.

I acknowledge the explanation concerning the address space available.
Being an ignorant of the inner details of the implementation of mmap,
it seems like somewhat an "implementation detail" to me that such an
address wall is hit. There may be some good arguments from a
programming point of view and it may be a relative high limit as
compared to other systems but it is certainly at the low side for my
application: I work with data files typically 200 GB in size
consisting of datapackets each having a fixed size frame and a
variable size payload. To handle these large files, I generate an
"index" file consisting of just the frames (which has all the metadata
I need for finding the payloads I am interested in) and "pointers" to
where in the large data file each payload begins. This index file can
be up to 1 GB in size and at times I need to have access to two of
those at the same time (and then i hit the address wall). I would
really really like to be able to access these index files in a
read-only manner as an array of records on a file for which I use
numpy.memmap (which wraps mmap.mmap) such that I can pick a single
element, extract, e.g., every thousand value of a specific field in
the record using the convenient indexing available in Python/numpy.
Now it seems like I have to resort to making my own encapsulation
layer, which seeks to the relevant place in the file, reads sections
as bytestrings into recarrays, etc. Well, I must just get on with
it...

I think it would be worthwhile specifying this 32 bit OS limitation in
the documentation of mmap.mmap, as I doubt I am the only one being
surprised about this address space limitation.

Cheers,
Kim

  
I agree that some description of system limitations should be included 
in a system-specific document.  There probably is one, I haven't looked 
recently.  But I don't think it belongs in mmap documentation.


Perhaps you still don't recognize what the limit is.  32 bits can only 
address 4 gigabytes of things as first-class addresses.  So roughly the 
same limit that's on mmap is also on list, dict, bytearray, or anything 
else.  If you had 20 lists taking 100 meg each, you would fill up 
memory.  If you had 10 of them, you might have enough room for a 1gb 
mmap area.  And your code takes up some of that space, as well as the 
Python interpreter, the standard library, and all the data structures 
that are normally ignored by the application developer.


BTW,  there is one difference between mmap and most of the other 
allocations.  Most data is allocated out of the swapfile, while mmap is 
allocated from the specified file (unless you use -1 for fileno).  
Consequently, if the swapfile is already clogged with all the other 
running applications, you can still take your 1.8gb or whatever of your 
virtual space, when much less than that might be available for other 
kinds of allocations.


Executables and dlls are also (mostly) mapped into memory just the same 
as mmap.  So they tend not to take up much space from the swapfile.  In 
fact, with planning, a DLL needn't take up any swapfile space (well, a 
few K is always needed, realistically)..  But that's a linking issue for 
compiled languages.


DaveA

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


quickly looping over a 2D array?

2009-07-27 Thread Martin
Hi,

I am new to python and I was wondering if there was a way to speed up
the way I index 2D arrays when I need to check two arrays
simultaneously? My current implementations is (using numpy) something
like the following...

for i in range(numrows):
for j in range(numcols):

if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
j] * some_other_value
array_1[i, j] = some_new_value

Many Thanks,

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


Re: RSA cryptography between Python and Java

2009-07-27 Thread Michael Ströder
Piet van Oostrum wrote:
> Please note that the text to be encrypted must be smaller than the key
> size (at least 11 bytes smaller). You shouldn't encrypt large data with
> RSA anyway: it is too slow. Normally you would encrypt a session key
> with RSA and encrypt the data with the session key using a symmetric
> algorithms like AES.

I'd use CMS (AKA PKCS#7) for encrypted/signed data with X.509 certs. One
should not invent another message format.

Ciao, Michael.

-- 
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quickly looping over a 2D array?

2009-07-27 Thread Peter Otten
Martin wrote:

> I am new to python and I was wondering if there was a way to speed up
> the way I index 2D arrays when I need to check two arrays
> simultaneously? My current implementations is (using numpy) something
> like the following...
> 
> for i in range(numrows):
> for j in range(numcols):
> 
> if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
> j] * some_other_value
> array_1[i, j] = some_new_value

array_1[(array_1 == some_value) | (array_2 >= array_1 * some_other_value)] = 
some_new_value

maybe?

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


Re: Call function from another class

2009-07-27 Thread Lars
> If I'm not mistaken, in "doRotate" you should be able to refer to the
> to-be-closed dialog via
> self.frameRotate
>
> Now if you change the "sliderUpdate"-code to store that angle instead of
> just letting it fall out of scope, you could access that value through
> frameRotate:
>
> def sliderUpdate(self, event):
>         angle=self.slider.GetValue()
>         ROTATION_ANGLE=angle
>         self.angle = angle
>         self.Destroy()
>
> def doRotate(self,event):
>     """Rotating image"""
>     print self.frameRotate.angle

Thanks for replying. If Bind is used in "onRotate":
def onRotate(self,event):
   """Rotate image"""
   self.frameRotate = rotationSlider(parent=None, id=-1)
   self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
   self.frameRotate.Show()

Then i get:
Traceback (most recent call last):
  File "viewer_sep.py", line 136, in onRotate
self.Bind(wx.EVT_CLOSE,self.doRotate, self.frameRotate.Destroy)
  File "/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode/wx/
_core.py", line 3629, in Bind
id  = source.GetId()
AttributeError: 'function' object has no attribute 'GetId'

My experience with ID is setting it to "-1".  So I'm not sure if it is
a wrong use of Bind or an wxPython error.
/Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mmap 2GB allocation limit on Win XP, 32-bits, Python 2.5.4

2009-07-27 Thread Slaunger
On 27 Jul., 13:21, Dave Angel  wrote:
> (forwarding this message, as the reply was off-list)
>
>
>
> Kim Hansen wrote:
> > 2009/7/24 Dave Angel :
>
> >> It's not a question of how much disk space there is, but how much virtual
> >> space 32 bits can address.  2**32 is about 4 gig, and Windows XP reserves
> >> about half of that for system use.  Presumably a 64 bit OS would have a 
> >> much
> >> larger limit.
>
> >> Years ago I worked on Sun Sparc system which had much more limited shared
> >> memory access, due to hardware limitations.  So 2gig seems pretty good to
> >> me.
>
> >> There is supposed to be a way to tell the Windows OS to only use 1 gb of
> >> virtual space, leaving 3gb for application use.  But there are some
> >> limitations, and I don't recall what they are.  I believe it has to be done
> >> globally (probably in Boot.ini), rather than per process.  And some things
> >> didn't work in that configuration.
>
> >> DaveA
>
> > Hi Dave,
>
> > In the related post I did on the numpy discussions:
>
> >http://article.gmane.org/gmane.comp.python.numeric.general/31748
>
> > another user was kind enough to run my test program on both 32 bit and
> > 64 bit machines. On the 64 bit machine, there was no such limit, very
> > much in line with what you wrote. Adding the /3GB option in boot.ini
> > did not increase the available memory as well. Apparently, Python
> > needs to have been compiled in a way, which makes it possible to take
> > advantage of that switch and that is either not the case or I did
> > something else wrong as well.
>
> > I acknowledge the explanation concerning the address space available.
> > Being an ignorant of the inner details of the implementation of mmap,
> > it seems like somewhat an "implementation detail" to me that such an
> > address wall is hit. There may be some good arguments from a
> > programming point of view and it may be a relative high limit as
> > compared to other systems but it is certainly at the low side for my
> > application: I work with data files typically 200 GB in size
> > consisting of datapackets each having a fixed size frame and a
> > variable size payload. To handle these large files, I generate an
> > "index" file consisting of just the frames (which has all the metadata
> > I need for finding the payloads I am interested in) and "pointers" to
> > where in the large data file each payload begins. This index file can
> > be up to 1 GB in size and at times I need to have access to two of
> > those at the same time (and then i hit the address wall). I would
> > really really like to be able to access these index files in a
> > read-only manner as an array of records on a file for which I use
> > numpy.memmap (which wraps mmap.mmap) such that I can pick a single
> > element, extract, e.g., every thousand value of a specific field in
> > the record using the convenient indexing available in Python/numpy.
> > Now it seems like I have to resort to making my own encapsulation
> > layer, which seeks to the relevant place in the file, reads sections
> > as bytestrings into recarrays, etc. Well, I must just get on with
> > it...
>
> > I think it would be worthwhile specifying this 32 bit OS limitation in
> > the documentation of mmap.mmap, as I doubt I am the only one being
> > surprised about this address space limitation.
>
> > Cheers,
> > Kim
>
> I agree that some description of system limitations should be included
> in a system-specific document.  There probably is one, I haven't looked
> recently.  But I don't think it belongs in mmap documentation.
>
> Perhaps you still don't recognize what the limit is.  32 bits can only
> address 4 gigabytes of things as first-class addresses.  So roughly the
> same limit that's on mmap is also on list, dict, bytearray, or anything
> else.  If you had 20 lists taking 100 meg each, you would fill up
> memory.  If you had 10 of them, you might have enough room for a 1gb
> mmap area.  And your code takes up some of that space, as well as the
> Python interpreter, the standard library, and all the data structures
> that are normally ignored by the application developer.
>
> BTW,  there is one difference between mmap and most of the other
> allocations.  Most data is allocated out of the swapfile, while mmap is
> allocated from the specified file (unless you use -1 for fileno).  
> Consequently, if the swapfile is already clogged with all the other
> running applications, you can still take your 1.8gb or whatever of your
> virtual space, when much less than that might be available for other
> kinds of allocations.
>
> Executables and dlls are also (mostly) mapped into memory just the same
> as mmap.  So they tend not to take up much space from the swapfile.  In
> fact, with planning, a DLL needn't take up any swapfile space (well, a
> few K is always needed, realistically)..  But that's a linking issue for
> compiled languages.
>
> DaveA- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -

I do understand t

Re: open a file in python

2009-07-27 Thread Piet van Oostrum
> jayshree  (j) wrote:

>j> pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()

By the way, a PEM file is a text file, no reason to open it in binary
mode. Just replace the 'rb' with 'r' or leave it out.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: psyco V2

2009-07-27 Thread Eduardo Lenz
Em Qui 16 Jul 2009, às 19:48:18, Christian Tismer escreveu:
> Announcing Psyco V2 source release
> --
>
> This is the long awaited announcement of Psyco V2.
>
> Psyco V2 is a continuation of the well-known psyco project,
> which was called finished and was dis-continued by its author
> Armin Rigo in 2005, in favor of the PyPy project.
>
> This is a new project, using Psyco's code base with permission
> of Armin. Questions and complaints should go to me
> (tis...@stackless.com) or the mailing list
> (psyco-de...@lists.sourceforge.net);
> Armin is explicitly not in charge of (t)his project any longer!
>
> As one of the founders and an active member of the PyPy
> project, I was very happy to be invited to work on Psyco
> V2, by FATTOC, LLC. Psyco V2 tries to extend on the original Psyco
> approach "an extension module that just makes Python faster".
>
> Psyco is a just-in-time compiler that accelerates arbitrary
> Python code by specialization. We believe that Psyco's approach
> can be carried out much further than it was tried so far, when
> it's first version was abandoned.
>
> This first V2 release is source-only. There is no web-site, yet,
> and there are no binaries for download. These will be available
> in a few days on http://www.psyco.org .
>
> For the time being, please stick with subversion access,
> building the extension module from source code. The repository
> is here:
>
>  http://codespeak.net/svn/psyco/v2/dist
>
> Check-out the repository, and run the setup.py script,
> given that you have access to a C compiler.
>
> Psyco V2 will run on X86 based 32 bit Linux, 32 bit Windows,
> and Mac OS X. Psyco is not supporting 64 bit, yet. But it
> is well being considered.
>
> The current improvements are, shortly:
>
>- Support for Python 2.4, 2.5 and 2.6
>- a lot of new builtins
>- generators, fast and fully supported.
>
> More information is coming soon on http://www.psyco.org .
>
> This is the beginning of a series of new Psyco versions.
> Many more improvements are prepared and about to be published,
> soon, starting with the current version 2.0.0 .
>
> Stay tuned, this is just the beginning of psyco's re-birth!
>
> For questions about Psyco V2, please join the mailing list
>
>  psyco-de...@lists.sourceforge.net
>
> or contact me on IRC:
>
>  #psyco on irc.freenode.net .
>
> Psyco V2 is fundamentally supported by FATTOC, LLC.
> See http://www.fattoc.com .
>
> Without their continuous support, this work would not have
> been possible at all. I wish to express my deepest thanks
> to FATTOC, for allowing me to continue on Psyco with all the
> energy that this ambitious project needs, and will need.
>
> Further special thanks are going to
> Armin Rigo, John Benediktsson, David Salomon, Miki Tebeka,
> Raymond Hettinger, Fabrizio Milo, Michael Foord,
> Dinu Gherman, Stephan Diehl, Laura Creighton and Andrea Tismer,
> for all the support and discussions.
>
> Looking forward to a great future of Psyco!
>
> July 17, 2009
I know its not the proper list but

gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -DNDEBUG -
g -O3 -fPIC -Ic/i386 -Ic -I/usr/include/python2.6 -c c/mergepoints.c -o 
build/temp.linux-i686-2.6/c/mergepoints.o
c/mergepoints.c:250: error: ‘RAISE_VARARGS’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘JUMP_IF_FALSE’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘JUMP_IF_TRUE’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘DUP_TOPX’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘IMPORT_STAR’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘SLICE’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘STORE_SLICE’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘DELETE_SLICE’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘PRINT_EXPR’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘PRINT_ITEM’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘PRINT_ITEM_TO’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘PRINT_NEWLINE’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘PRINT_NEWLINE_TO’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘BUILD_CLASS’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘IMPORT_NAME’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘IMPORT_FROM’ undeclared here (not in a function)
c/mergepoints.c:250: error: ‘MAKE_FUNCTION’ undeclared here (not in a 
function)
c/mergepoints.c:250: error: ‘BUILD_SLICE’ undeclared here (not in a function)
error: command 'gcc' failed with exit status 1

any clue ?

[]'s
Eduardo

 Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940
 E-mail: l...@joinville.udesc.br  
 -

-- 
Esta mensagem foi verificada pelo sistema de antiv�rus e
 acredita-se estar livre de perigo.

-- 
http:

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

2009-07-27 Thread David Robinow
On 7/26/09, MRAB  wrote:
> David Robinow wrote:
> > > This doesn't mean they're on the same level - in fact, if you read
> carefully
> > > you'll see my original post said as much: python attracted average
> > > programmers; php attracted mediocre programmers and even some
> > > non-programmers, which means that php is clearly a lesser language than
> > > python.
> >  I'm a mediocre programmer. Does this mean I should switch to PHP?
> If you're a mediocre programmer who knows you're mediocre, but wants to
> improve and is willing to learn, then stick with Python. You'll get
> better. :-)
I doubt it. I remember when Guido moved to the U.S. and I've even used
stdwin. I've actually gotten worse over the years. Old age does that.
Nevertheless, I question the idea that a language that is easy to use
(I don't know if PHP qualifies) is somehow inferior.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: python-ldap-2.3.9

2009-07-27 Thread Michael Ströder
Find a new release of python-ldap:

  http://www.python-ldap.org/

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Ciao, Michael.

-- 
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com



Released 2.3.9 2009-07-26

Changes since 2.3.8:

Lib/
* All modules (ldap, ldif, dsml and ldapurl) have common version number now
* Non-exported function ldif.needs_base64() was abandoned and is now
  implemented as method LDIFWriter._needs_base64_encoding().
  This allows sub-classes of LDIFWriter to implement determining whether
  attribute values have to be base64-encoded in a different manner and is
  the same approach like in class dsml.DSMLWriter.
* LDAPUrlExtension._parse() now gracefully handles LDAP URL extensions
  without explicit exvalue as being set with implicit value None.

Modules/
* New LDAP option constant ldap.OPT_X_SASL_NOCANON supported
  in LDAPObject.get/set_option()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RSA cryptography between Python and Java

2009-07-27 Thread Piet van Oostrum
> Michael Ströder  (MS) wrote:

>MS> Piet van Oostrum wrote:
>>> Please note that the text to be encrypted must be smaller than the key
>>> size (at least 11 bytes smaller). You shouldn't encrypt large data with
>>> RSA anyway: it is too slow. Normally you would encrypt a session key
>>> with RSA and encrypt the data with the session key using a symmetric
>>> algorithms like AES.

>MS> I'd use CMS (AKA PKCS#7) for encrypted/signed data with X.509 certs. One
>MS> should not invent another message format.

Yes but the original question was not about X.509 certs. Just the RSA
public key. I don't know what the OP wants to do with it.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


wave.setparams((2, 2, 44100, 44100 * 2 * 10, "NONE", "not compressed")) became more than 30secs

2009-07-27 Thread '2+
thanx to rob .. who gave me an example of how to use the WAVE lib
now am on my way to use it as simple as i can

i wrote an oil.py the instance of which will behave like an oscillator
which constantly generates 7 different wave forms (non fixed)
i thought this code might produce 10secs of wave file but the result
was longer than 30secs
was testing if i could use the WAVE lib withount taking advantage of
StringIO
nor
struct
but maybe am doing totally wrong?

--8<---

import oil
import wave

a = oil.Sa()

w = wave.open("current.wav", "w")
w.setparams((2, 2, 44100, 44100 * 2 * 10, "NONE", "not compressed"))

for gas in range(44100 * 10):
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))
w.close()



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


Re: quickly looping over a 2D array?

2009-07-27 Thread Martin
On Jul 27, 12:42 pm, Peter Otten <__pete...@web.de> wrote:
> Martin wrote:
> > I am new to python and I was wondering if there was a way to speed up
> > the way I index 2D arrays when I need to check two arrays
> > simultaneously? My current implementations is (using numpy) something
> > like the following...
>
> > for i in range(numrows):
> > for j in range(numcols):
>
> > if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
> > j] * some_other_value
> > array_1[i, j] = some_new_value
>
> array_1[(array_1 == some_value) | (array_2 >= array_1 * some_other_value)] =
> some_new_value
>
> maybe?

So I tried...

band_1[(array_1 == 255) or (array_2 >= array_1 * factor)] = 0

which led to

ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

so not sure that works?
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert raw binary file to ascii

2009-07-27 Thread r2
I have a memory dump from a machine I am trying to analyze. I can view
the file in a hex editor to see text strings in the binary code. I
don't see a way to save these ascii representations of the binary, so
I went digging into Python to see if there were any modules to help.

I found one I think might do what I want it to do - the binascii
module. Can anyone describe to me how to convert a raw binary file to
an ascii file using this module. I've tried? Boy, I've tried.

Am I correct in assuming I can get the converted binary to ascii text
I see in a hex editor using this module? I'm new to this forensics
thing and it's quite possible I am mixing technical terms. I am not
new to Python, however. Thanks for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-27 Thread Benjamin Kaplan
On Sun, Jul 26, 2009 at 2:24 PM, John Nagle wrote:
> Beni Cherniavsky wrote:
>>
>> On Jul 22, 9:36 am, Hendrik van Rooyen 
>> wrote:
>>>
>>> On Tuesday 21 July 2009 15:49:59 Inky 788 wrote:
>>>
 My guess is that it was probably for optimization reasons long ago.
 I've never heard a *good* reason why Python needs both.
>>>
>>> The good reason is the immutability, which lets you use
>>> a tuple as a dict key.
>>
>> On Jul 22, 9:36 am, Hendrik van Rooyen 
>> wrote:
>>>
>>> On Tuesday 21 July 2009 15:49:59 Inky 788 wrote:
>>>
 My guess is that it was probably for optimization reasons long ago.
 I've never heard a *good* reason why Python needs both.
>>>
>>> The good reason is the immutability, which lets you use
>>> a tuple as a dict key.
>>>
>> The *technical* reason is immutability for dict keys.
>> Dict could allow mutable objects as keys by comparing *by value*,
>> making a copy on insertion and hashing the current value on lookup.
>> Prior art: the 2.3 sets module allows mutable Sets as elements in
>> Sets, by making ImmutableSet copies on insertion, and hashing Sets as
>> if they are temporarily immutable on lookup.
>>
>> This inspired PEP 351 and ambitious proposals to expand the approach
>> to all Python with a copy-on-write scheme.  But these ideas were
>> rejected, and the 2.4 builtin sets only allow frozenset elements.
>> Half the reason is technical: copy-on-write and harder than it sounds,
>> and without it you pay a performance price.
>>
>> But the deeper reason is style: immutable types are convenient!
>> The allow a pure-functional style of code, which can be simpler.
>> Of course, sometimes an imperative style is simpler.  Depends on the
>> problem.
>
>    An interesting issue is Python objects, which are always mutable.
> A "dict" of Python objects is allowed, but doesn't consider
> the contents of the objects, just their identity (address). Only
> built-in types are immutable; one cannot create a class of immutable
> objects.
> So things like "frozenset" had to be built into the language.
> A tuple is really a frozen list.  Arguably, frozen objects
> should have been a general concept.  Conceptually, they're
> simple - once "__init__" has run, there can be no more changes
> to fields of the object.
>
>    Compare the C++ approach, where you can have a "map" of
> any object that defines the "<" operator.  Python has
> "__cmp__" for objects, but built-in dictionaries don't use it.
> Of course, one could create a "map" class in Python that
> uses "__cmp__", which would allow dictionary-type operations
> on arbitrary objects.


Python dictionaries are hash maps so they use hashes, not comparisons,
to store objects. By default the hash is equal to the object's
identity but all you need to do to change it is define your own
__hash__ method. If you were to make a C++ hash map, it wouldn't use
comparisons either.


>
>    There are some interesting uses for immutable objects in
> multithreaded programs.  They can be shared between threads
> without locking.  If it weren't for the infamous Global
> Interpreter Lock, which basically limits Python programs to using
> one CPU at a time, Python would have to deal with locking
> in a more advanced way.  A system where immutable objects
> can be shared and passed between threads, and mutable objects
> must be "synchronized" (in the Java sense) to be shared would
> be useful.
>
>                                John Nagle
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Particle research opens door for new technology

2009-07-27 Thread Rashid Ali Soomro
Big uses for small particles will be explored at the annual Particle
Technology Research Centre Conference at The University of Western
Ontario July 9 and 10.more http://0nanotechnology0.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quickly looping over a 2D array?

2009-07-27 Thread Peter Otten
Martin wrote:

> On Jul 27, 12:42 pm, Peter Otten <__pete...@web.de> wrote:
>> Martin wrote:
>> > I am new to python and I was wondering if there was a way to speed up
>> > the way I index 2D arrays when I need to check two arrays
>> > simultaneously? My current implementations is (using numpy) something
>> > like the following...
>>
>> > for i in range(numrows):
>> > for j in range(numcols):
>>
>> > if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
>> > j] * some_other_value
>> > array_1[i, j] = some_new_value
>>
>> array_1[(array_1 == some_value) | (array_2 >= array_1 *
>> some_other_value)] = some_new_value
>>
>> maybe?
> 
> So I tried...
> 
> band_1[(array_1 == 255) or (array_2 >= array_1 * factor)] = 0
> 
> which led to
> 
> ValueError: The truth value of an array with more than one element is
> ambiguous. Use a.any() or a.all()
> 
> so not sure that works?

Copy and paste -- or replace "or" with "|".

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


Re: quickly looping over a 2D array?

2009-07-27 Thread Martin
On Jul 27, 1:46 pm, Peter Otten <__pete...@web.de> wrote:
> Martin wrote:
> > On Jul 27, 12:42 pm, Peter Otten <__pete...@web.de> wrote:
> >> Martin wrote:
> >> > I am new to python and I was wondering if there was a way to speed up
> >> > the way I index 2D arrays when I need to check two arrays
> >> > simultaneously? My current implementations is (using numpy) something
> >> > like the following...
>
> >> > for i in range(numrows):
> >> > for j in range(numcols):
>
> >> > if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
> >> > j] * some_other_value
> >> > array_1[i, j] = some_new_value
>
> >> array_1[(array_1 == some_value) | (array_2 >= array_1 *
> >> some_other_value)] = some_new_value
>
> >> maybe?
>
> > So I tried...
>
> > band_1[(array_1 == 255) or (array_2 >= array_1 * factor)] = 0
>
> > which led to
>
> > ValueError: The truth value of an array with more than one element is
> > ambiguous. Use a.any() or a.all()
>
> > so not sure that works?
>
> Copy and paste -- or replace "or" with "|".

apologies - I mistook that for a type for "or"

I now get the following error...

ValueError: shape mismatch: objects cannot be broadcast to a single
shape
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert raw binary file to ascii

2009-07-27 Thread Peter Otten
r2 wrote:

> I have a memory dump from a machine I am trying to analyze. I can view
> the file in a hex editor to see text strings in the binary code. I
> don't see a way to save these ascii representations of the binary, so
> I went digging into Python to see if there were any modules to help.
> 
> I found one I think might do what I want it to do - the binascii
> module. Can anyone describe to me how to convert a raw binary file to
> an ascii file using this module. I've tried? Boy, I've tried.

That won't work because a text editor doesn't need any help to convert the 
bytes into characters. If it expects ascii it just will be puzzled by bytes 
that are not valid ascii. Also, it will happily display byte sequences that 
are valid ascii, but that you as a user will see as gibberish because they 
were meant to be binary data by the program that wrote them.

> Am I correct in assuming I can get the converted binary to ascii text
> I see in a hex editor using this module? I'm new to this forensics
> thing and it's quite possible I am mixing technical terms. I am not
> new to Python, however. Thanks for your help.

Unix has the "strings" commandline tool to extract text from a binary.
Get hold of a copy of the MinGW tools if you are on windows.

Peter

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


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

2009-07-27 Thread Harry Ebbers
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: quickly looping over a 2D array?

2009-07-27 Thread Peter Otten
Martin wrote:

> On Jul 27, 1:46 pm, Peter Otten <__pete...@web.de> wrote:
>> Martin wrote:
>> > On Jul 27, 12:42 pm, Peter Otten <__pete...@web.de> wrote:
>> >> Martin wrote:
>> >> > I am new to python and I was wondering if there was a way to speed
>> >> > up the way I index 2D arrays when I need to check two arrays
>> >> > simultaneously? My current implementations is (using numpy)
>> >> > something like the following...
>>
>> >> > for i in range(numrows):
>> >> > for j in range(numcols):
>>
>> >> > if array_1[i, j] == some_value or array_2[i, j] >=
>> >> > array_1[i,
>> >> > j] * some_other_value
>> >> > array_1[i, j] = some_new_value
>>
>> >> array_1[(array_1 == some_value) | (array_2 >= array_1 *
>> >> some_other_value)] = some_new_value
>>
>> >> maybe?
>>
>> > So I tried...
>>
>> > band_1[(array_1 == 255) or (array_2 >= array_1 * factor)] = 0
>>
>> > which led to
>>
>> > ValueError: The truth value of an array with more than one element is
>> > ambiguous. Use a.any() or a.all()
>>
>> > so not sure that works?
>>
>> Copy and paste -- or replace "or" with "|".
> 
> apologies - I mistook that for a type for "or"
> 
> I now get the following error...
> 
> ValueError: shape mismatch: objects cannot be broadcast to a single
> shape

It seems array_1 and array_2 have a -- dada! -- different shape.
Assuming array_1 is the smaller one:

numrows, numcols = array_1.shape
array_1[(array_1 == some_value) | (array_2[:numrows,:numcols] >= array_1 * 
some_other_value)] = some_new_value

There may be other options, but I'm not a numpy expert.

Peter

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


Re: Distinguishing active generators from exhausted ones

2009-07-27 Thread Michal Kwiatkowski
On Jul 27, 1:56 am, a...@pythoncraft.com (Aahz) wrote:
> >> Upon a cursory look, after a generator 'gen' is exhausted (meaning
> >> gen.next() has raised StopIteration), it seems that gen.gi_frame will be
> >> None.
>
> >Only in Python 2.5 or higher though. I need to support Python 2.3 and
> >2.4 as well, sorry for not making that clear in the original post.
>
> Are you sure?  It appears to work in Python 2.4; I don't have time to
> check 2.3.

No, it does not work in Python 2.4. gi_frame can be None only in
Python 2.5 and higher.

Via "What’s New in Python 2.5" (http://docs.python.org/whatsnew/
2.5.html):

"""
Another even more esoteric effect of this change: previously, the
gi_frame attribute of a generator was always a frame object. It’s now
possible for gi_frame to be None once the generator has been
exhausted.
"""

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


Re: Problem in PyArg_ParseTuple on python 2.5.2 with AIX

2009-07-27 Thread John Machin
On Jul 27, 8:49 pm, abhi  wrote:
> On Jul 27, 2:25 pm, John Machin  wrote:
>
>
>
> > On Jul 27, 5:11 pm, abhi  wrote:
>
> > > Hi,
> > >     I am facing a problem using PyArg_ParseTuple() in my C-API
> > > extension. Here is a small repro of the function:
>
> > > static PyObject *parsetuple_test(PyObject *self, PyObject *args)
> > > {
> > >         SQLUSMALLINT param_no = 0;
>
> > Sorry, my crystal ball is on the fritz. What is SQLUSMALLINT on
> > Windows/Linux/AIX?
> > What does
> >     printf("%d %d %d\n", sizeof(SQLUSMALLINT), sizeof(int), sizeof
> > (long));
> > give you on each platform?

And the answer was: what?

>     Thanks for the response. If I don't use SQLUSMALLINT and use int
> instead, then also I see the same problem.
> static PyObject *parsetuple_test(PyObject *self, PyObject *args)
>  {
>         int param_no = 0;
> 
> }
>
> This also prints out 0 for AIX and actual value passed in other
> platforms. If I initialize param_no with some other value (e.g. 90),
> it prints out that value.

Please run the following on AIX with Python 2.5:
   import sys
   print sys.byteorder, sys.maxint
   print sys.version
and tell us the output.

Does the C compiler that you are using for the extension correspond
with whatever is mentioned in sys.version about the C compiler used to
compile Python 2.5?

C code: Please add/change as follows:
   int dummy1 = 0x;
   int param_no = 0x;
   int dummy2 = 0x;
...
   printf("%08x %08x %08x\n", dummy1, param_no, dummy2);
   printf("%d %d\n", sizeof(int), sizeof(long));

Try this on AIX (a) with no optimisation (b) whatever O level you have
been using.

Try it with (i) small positive input (i) integer > 65535

Take a copy of your extension and cut out everything that is not part
of executing this function i.e. apart from this function (with the
dummies and printfs) you should have only a few includes, a table
defining just 1 callable function, and the minimal module
initialisation code. Check that this cut down version works on Windows
and Linux and still fails on AIX. Then try it without the first ("O")
arg. If it still fails on AIX, lose the first arg. Publish the minimal
failing code, the instructions to build the .so, and a transcript of
the Python interactive session showing calling the function and the
results.

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


Re: quickly looping over a 2D array?

2009-07-27 Thread Martin
On Jul 27, 2:17 pm, Peter Otten <__pete...@web.de> wrote:
> Martin wrote:
> > On Jul 27, 1:46 pm, Peter Otten <__pete...@web.de> wrote:
> >> Martin wrote:
> >> > On Jul 27, 12:42 pm, Peter Otten <__pete...@web.de> wrote:
> >> >> Martin wrote:
> >> >> > I am new to python and I was wondering if there was a way to speed
> >> >> > up the way I index 2D arrays when I need to check two arrays
> >> >> > simultaneously? My current implementations is (using numpy)
> >> >> > something like the following...
>
> >> >> > for i in range(numrows):
> >> >> > for j in range(numcols):
>
> >> >> > if array_1[i, j] == some_value or array_2[i, j] >=
> >> >> > array_1[i,
> >> >> > j] * some_other_value
> >> >> > array_1[i, j] = some_new_value
>
> >> >> array_1[(array_1 == some_value) | (array_2 >= array_1 *
> >> >> some_other_value)] = some_new_value
>
> >> >> maybe?
>
> >> > So I tried...
>
> >> > band_1[(array_1 == 255) or (array_2 >= array_1 * factor)] = 0
>
> >> > which led to
>
> >> > ValueError: The truth value of an array with more than one element is
> >> > ambiguous. Use a.any() or a.all()
>
> >> > so not sure that works?
>
> >> Copy and paste -- or replace "or" with "|".
>
> > apologies - I mistook that for a type for "or"
>
> > I now get the following error...
>
> > ValueError: shape mismatch: objects cannot be broadcast to a single
> > shape
>
> It seems array_1 and array_2 have a -- dada! -- different shape.
> Assuming array_1 is the smaller one:
>
> numrows, numcols = array_1.shape
> array_1[(array_1 == some_value) | (array_2[:numrows,:numcols] >= array_1 *
> some_other_value)] = some_new_value
>
> There may be other options, but I'm not a numpy expert.
>
> Peter

My mistake - the incorrect size in the arrays was my error.

The statement works now, but it doesn't give the same results as my
original logic, strangely!?

in my logic:

data = np.zeros((numrows, numcols), dtype = np.uint8, order ='C')

for i in range(numrows):
for j in range(numcols):
if band3[i,j] == 255 or band3[i,j] >= band6[i,j] * factor:
data[i,j] = 0
else:
data[i,j] = 1

to do the same with what you suggested...

data = np.ones((numrows, numcols), dtype = np.uint8, order ='C')
data[(band3 == 255) | (band6 >= band3 * factor)] = 0

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


iText for Python

2009-07-27 Thread santhoshvkumar
Hi all,
   One of my cousin  suggested me to do a IText PDF converter
for python. Actually I heard that there is no separate IText converter
either we have to go for jython or GCJ with wrapper. Instead of
wrapping, my plan is to create a separate module with Python and I am
thinking of doing this in as my final year project also. Kindly give
me your suggestion.

With anticipation,

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


Re: Override a method but inherit the docstring

2009-07-27 Thread Jean-Michel Pichavant

Ben Finney wrote:

Howdy all,

The following is a common idiom::

class FooGonk(object):
def frobnicate(self):
""" Frobnicate this gonk. """
basic_implementation(self.wobble)

class BarGonk(FooGonk):
def frobnicate(self):
special_implementation(self.warble)

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.

Ideally there would be a way to specify that the docstring should be
inherited. The best I can come up with is::

class BarGonk(FooGonk):
def frobnicate(self):
special_implementation(self.warble)
frobnicate.__doc__ = FooGonk.frobnicate.__doc__

but that violates DRY (the association between BarGonk and FooGonk is
being repeated), puts the docstring assignment awkwardly after the end
of the method instead of at the beginning where docstrings normally go,
and reads poorly besides.

What is the most Pythonic, DRY-adherent, and preferably least-ugly
approach to override a method, but have the same docstring on both
methods?

  
I am using epydoc and if the docstring is present only in the baseclass 
method, it will repeat the docstring for the child methods. So 
basically, there's nothing to do.
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 ?


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


Re: Convert raw binary file to ascii

2009-07-27 Thread Grant Edwards
On 2009-07-27, r2  wrote:

> I have a memory dump from a machine I am trying to analyze. I can view
> the file in a hex editor to see text strings in the binary code. I
> don't see a way to save these ascii representations of the binary,

$ strings memdump.binary >memdump.strings

$ hexdump -C memdump.binary >memdump.hex+ascii

-- 
Grant Edwards   grante Yow! I'm ZIPPY the PINHEAD
  at   and I'm totally committed
   visi.comto the festive mode.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to comment constant values?

2009-07-27 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Mon, 27 Jul 2009 00:47:08 +0200, Diez B. Roggisch wrote:

  

Only modules, classes, and functions/methods can have docstrings
associated with them.
For anything else, you have to use comments; or you can mention them in
the docstrings of related things.
  

While this is technically true, writing docstrings to constants (module
or classlevel) works when one uses tools such as epydoc to generate
documentation.



I've never used epydoc, so I'm not sure what you mean. Presumably it uses 
source code analysis to detect:


CONSTANT = 42
"""This is a constant."""

even though the string is ignored by the compiler.

Is that correct?


  
Yes, and because it is perfectly ignored by the compiler there's no harm 
using this feature. I would add that even if you're not using epydoc, 
having a way top discriminate comments from documentation is 
recommended, their purpose are definitely not the same.


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


Re: python function for retrieving key and encryption

2009-07-27 Thread Piet van Oostrum
> jayshree  (j) wrote:

>j> import M2Crypto
>j> from M2Crypto import RSA,SSL
>j> def encrypt():
>j> pk = open('my_key.public.pem', 'rb').read()
>j> rsa = M2Crypto.RSA.load_pub_key(pk) #return a M2Crypto.RSA.RSA_pub
>j> object.
>j> plaintext = 4545479545655576767767686688782344
>j> msg = rsa.public_encrypt(plaintext,RSA.pkcs1_padding)
>j> print msg;
>j> encrypt()

>j> This is code i am refering.
>j> The Problem is coming with .pem file.

You never tell what the problem is. Which error message do you get? Why
can't you just copy the error messages in your post instead of letting
us guess what is happening?

There are indeed problems with the code above. One warning: If you are
going to write cryptographic code while you really don't understand the
subject enough there is a big chance that your programs will have
security problems.

One more question: Do you have now a valid my_key.public.pem file? And
is it in the same directory where you run this program?

Here are the problems in your code (and there may be more!)

  import M2Crypto
  from M2Crypto import RSA,SSL

You never use the imports from the line above so you can leave it out.
SSL isn't used at all, and RSA is used as M2Crypto.RSA so it uses the
first import. Cleanliness is next to godliness.

  def encrypt():
  pk = open('my_key.public.pem', 'rb').read()
  rsa = M2Crypto.RSA.load_pub_key(pk) #return a M2Crypto.RSA.RSA_pub object.

load_pub_key requires a file name, not the contents of the file.
So use rsa = M2Crypto.RSA.load_pub_key('my_key.public.pem') and leave
the open line out.

  plaintext = 4545479545655576767767686688782344

That's not text, it is a number. rsa.public_encrypt will not accept a
number. So you would have to use 
  plaintext = "4545479545655576767767686688782344"
or convert the number to a byte array.

  msg = rsa.public_encrypt(plaintext,RSA.pkcs1_padding)
  print msg;
  encrypt()

The above line should be shifted to the left. It is not part of the
function otherwise you get an endless recursion.
And to answer another question from stackoverflow.com: RSA.pkcs1_padding
is a good parameter, if the decryption side will also use it.

See also my posting on the subject `RSA cryptography between Python and Java'.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Wrapping prstat on Solaris

2009-07-27 Thread skip
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 - s...@pobox.com - http://www.smontanaro.net/
That's more than a dress. That's an Audrey Hepburn movie. -- Jerry Maguire
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iText for Python

2009-07-27 Thread Simon Brunning
2009/7/27 santhoshvkumar :
>           One of my cousin  suggested me to do a IText PDF converter
> for python. Actually I heard that there is no separate IText converter
> either we have to go for jython or GCJ with wrapper. Instead of
> wrapping, my plan is to create a separate module with Python and I am
> thinking of doing this in as my final year project also. Kindly give
> me your suggestion.

What would this give us that ReportLab does not? I wouldn't want to
see you spend a lot of time reinventing the wheel...

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


Re: Form/Template Fill-in the blanks

2009-07-27 Thread Aahz
In article <4b77a992-370d-4879-88a0-fdd6a23f7...@p10g2000prm.googlegroups.com>,
allan   wrote:
>
>My initial thought was to use:
>1. .ini files to declare the EDI configuration
>
>INI file configuration:
>* A "root" INI file indicates other INI files that define each segment
>of the EDI document.
>* Each segment INI defines the data elements of each segment and the
>behavior of the segment (one instance or multiple-instance as in a
>loop, sequence order, segment code, etc.)
>* Specify data elements as either constant, system function (like
>datetime), database field or object method (object being the
>segment's)
>* Load all the ini configuration into a "template" object. Each
>segment ini maps to its own segment object.

This sounds like something you want to use XML for.
-- 
Aahz (a...@pythoncraft.com)   <*> 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: Script runs manually, but cron fails

2009-07-27 Thread Bryan
On Jul 24, 2:11 pm, Bryan  wrote:
> I have a backup script that runs fine when I run it manually from the
> command line.  When I run it with cron, the script stops running at
> random points in the source code.
>
> The script calls rsync with the subprocess module, which in turn uses
> ssh to backup files from a box on my lan.  It also uses the atexit
> module to always run a certain piece of cleanup code when the script
> exits.  However, this piece of code is never called when I use cron to
> run the script, but a ps -A command also does not show the python
> process so I know the script is dead.  The log files generated by the
> script all show rsync as completing, but then the logging gets cutoff
> at random places when the script dies after that point.  I am not
> getting any email from cron complaining of an error either.
>
> The script runs fine in my bash shell, what could cron be doing to
> interfere?

This script works when I run it at home, and I think it is because I
don't use rsync's ability to backup over ssh.  The working script at
home simply backs up the local machine to a mounted external hard
drive.  So when I run a python script that calls rsync to work over
ssh, cron is screwing things up.  Can anyone recommend where I should
report this behavior?  Should I email the author of cron directly, I
don't see a group/address specifically for cron bugs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Itext for Python

2009-07-27 Thread Kushal Kumaran
On Mon, Jul 27, 2009 at 2:23 PM, S.Selvam wrote:
>
>
> On Sun, Jul 26, 2009 at 11:52 PM, Santhosh Kumar 
> wrote:
>>
>> Hi all,
>>            One of my cousin  suggested me to do a IText PDF converter for
>> python. Actually I heard that there is no separate IText converter either we
>> have to go for jython or GCJ with wrapper. Instead of wrapping, my plan is
>> to create a separate module with Python and I am thinking of doing this in
>> as my final year project also. Kindly give me your suggestion.
>
> As for as i know, no pure python module exists for iText PDF generator,
> where iText seems to be a standard one for PDF related works.There are some
> other modules for pdf work but might not be as standard as iText.Surely some
> senior programmers  will suggest you better way to proceed further.
>

AFAIK, iText is just a java library for generating PDF files.  You
could have a look at http://www.reportlab.org/rl_toolkit.html

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


Re: Script runs manually, but cron fails

2009-07-27 Thread J Kenneth King
Bryan  writes:

> I have a backup script that runs fine when I run it manually from the
> command line.  When I run it with cron, the script stops running at
> random points in the source code.
>
> The script calls rsync with the subprocess module, which in turn uses
> ssh to backup files from a box on my lan.  It also uses the atexit
> module to always run a certain piece of cleanup code when the script
> exits.  However, this piece of code is never called when I use cron to
> run the script, but a ps -A command also does not show the python
> process so I know the script is dead.  The log files generated by the
> script all show rsync as completing, but then the logging gets cutoff
> at random places when the script dies after that point.  I am not
> getting any email from cron complaining of an error either.
>
> The script runs fine in my bash shell, what could cron be doing to
> interfere?

Double check nothing is writing to stdout/stdin

Some cron's don't mind, but I always squelch output because some do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distinguishing active generators from exhausted ones

2009-07-27 Thread Aahz
In article <1c8ae01e-2e9c-497c-9f8d-408f56f9c...@g31g2000yqc.googlegroups.com>,
Michal Kwiatkowski   wrote:
>On Jul 27, 1:56 am, a...@pythoncraft.com (Aahz) wrote:
 Upon a cursory look, after a generator 'gen' is exhausted (meaning
 gen.next() has raised StopIteration), it seems that gen.gi_frame will be
 None.
>>>
>>>Only in Python 2.5 or higher though. I need to support Python 2.3 and
>>>2.4 as well, sorry for not making that clear in the original post.
>>
>> Are you sure?  It appears to work in Python 2.4; I don't have time to
>> check 2.3.
>
>No, it does not work in Python 2.4. gi_frame can be None only in
>Python 2.5 and higher.

You're right, I guess I must have made a boo-boo when I was switching
versions.
-- 
Aahz (a...@pythoncraft.com)   <*> 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: pyc files not automatically compiled on import

2009-07-27 Thread Aahz
In article ,
Baz Walter   wrote:
>
>i thought that python automatically compiled pyc files after a module is 
>successfully imported. what could prevent this happening?

Looks like you got your problem fixed, but for the record, not having
write permission on a directory also causes this.  It's even uglier when
the .pyc already exists but does not have write perms.
-- 
Aahz (a...@pythoncraft.com)   <*> 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-27 Thread Aahz
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!)
-- 
Aahz (a...@pythoncraft.com)   <*> 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: Looking for a dream language: sounds like Python to me.

2009-07-27 Thread Ethan Furman

[corrected top posting]

Mohammad Tayseer wrote:

*From:* Piet van Oostrum 
*To:* python-list@python.org
*Sent:* Monday, July 27, 2009 11:18:20 AM
*Subject:* Re: Looking for a dream language: sounds like Python to me.

 > Dotan Cohen mailto:dotanco...@gmail.com>> 
(DC) wrote:


 >DC> Referring to this article:
DC> 

http://math-blog.com/2009/07/20/complex-algorithm-research-and-development-harder-than-many-think/

 >DC> The author, who is specifically looking for math-related 
functions, writes:

 >DC> """
 >DC> The dream algorithm R&D tool would be similar to Matlab or Mathematica
 >DC> but could be compiled to fast, efficient binaries similar to ANSI C
 >DC> and would be available for all platforms. An integrated GUI builder
 >DC> similar to Visual Basic and integrated network support would be
 >DC> helpful.
 >DC> """

 >DC> It looks to me like he is looking for Python.

No fast, efficient binaries yet, and no integrated GUI builder.
--
Piet van Oostrum mailto:p...@cs.uu.nl>>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org 
--
http://mail.python.org/mailman/listinfo/python-list


> You can generate binaries using py2exe, and you can create UI using
> Tkinter (which is very easy) or wxPython (which have GUI builders)
>
> Mohammad Tayseer
> http://spellcoder.com/blogs/tayseer

Creating binaries is not the same as creating /fast, efficient/ 
binaries.  Py2Exe bundles it all together, but does not make it any faster.


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


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

2009-07-27 Thread Dotan Cohen
> Creating binaries is not the same as creating /fast, efficient/ binaries.
>  Py2Exe bundles it all together, but does not make it any faster.
>

How inefficient is py2exe. I was under the impression that it's really
not that bad.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quickly looping over a 2D array?

2009-07-27 Thread Peter Otten
Martin wrote:

> The statement works now, but it doesn't give the same results as my
> original logic, strangely!?
> 
> in my logic:
> 
> data = np.zeros((numrows, numcols), dtype = np.uint8, order ='C')
> 
> for i in range(numrows):
> for j in range(numcols):
> if band3[i,j] == 255 or band3[i,j] >= band6[i,j] * factor:
> data[i,j] = 0
> else:
> data[i,j] = 1
> 
> to do the same with what you suggested...
> 
> data = np.ones((numrows, numcols), dtype = np.uint8, order ='C')
> data[(band3 == 255) | (band6 >= band3 * factor)] = 0

Did you swap band3 and band6? If that's the case, it is an error you should 
be able to find yourself.

Please be a bit more careful.

Also, it is good practice to write a few test cases where you have 
precalculated the result. How would you otherwise know which version is 
correct? Writing a third one to break the tie?

Peter


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


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

2009-07-27 Thread David Smith
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!)

LOL ... I'm an American and that wasn't all that clear :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-07-27 Thread Jean-Paul Calderone

On Mon, 27 Jul 2009 18:12:09 +0300, Dotan Cohen  wrote:

Creating binaries is not the same as creating /fast, efficient/ binaries.
 Py2Exe bundles it all together, but does not make it any faster.



How inefficient is py2exe. I was under the impression that it's really
not that bad.



py2exe doesn't really change the performance characteristics of a Python
application at all - for better or for worse.

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


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

2009-07-27 Thread David Cournapeau
On Tue, Jul 28, 2009 at 12:12 AM, Dotan Cohen wrote:
>> Creating binaries is not the same as creating /fast, efficient/ binaries.
>>  Py2Exe bundles it all together, but does not make it any faster.
>>
>
> How inefficient is py2exe.

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.

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


CRLF Newlines and libc

2009-07-27 Thread Eric
I am working on the subprocess.Popen module for Google Summer of Code.
Right now, I am having difficulty trying to work out how to deal with
my '\n' newlines being converted to '\r\n' newlines when reading from
a pipe on windows; see this blog post (http://subdev.blogspot.com/
2009/07/stdout.html) and this chain on Python-Dev (http://
mail.python.org/pipermail/python-dev/2009-July/090720.html).

Right now, unless there is way to disable the newline conversions, I
am thinking I will just have to document the caveat and call it a day.
Is there a better way to handle this?

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


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

2009-07-27 Thread Grant Edwards
On 2009-07-27, Dotan Cohen  wrote:
>> Creating binaries is not the same as creating /fast, efficient/ binaries.
>> ??Py2Exe bundles it all together, but does not make it any faster.
>
> How inefficient is py2exe.

[Assuming that was a question.]

py2exe just bundles up the files needed to run the program.
The result runs pretty much the same as it did when it was
"unbundled".  By default, py2exe combines some stuff in a zip
file, so that might slow down startup by a tiny amount. If
you don't like that, you can tell py2exe not to "zip" things
up, and then the program runs pretty much identically as did
the unbundled version.

> I was under the impression that it's really not that bad.

py2exe doesn't really have any impact on the program's
perfromance.  It's still the same Python VM running the same
bytecode using the same library files.

-- 
Grant Edwards   grante Yow! I'm totally DESPONDENT
  at   over the LIBYAN situation
   visi.comand the price of CHICKEN
   ...
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-07-27 Thread Dotan Cohen
> 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.


-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-07-27 Thread David Cournapeau
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions.TypeError an integer is required

2009-07-27 Thread jakecjacobson
On Jul 24, 3:11 pm, Steven D'Aprano  wrote:
> On Fri, 24 Jul 2009 11:24:58 -0700, jakecjacobson wrote:
> > I am trying to do a post to a REST API over HTTPS and requires the
> > script to pass a cert to the server.  I am getting "exceptions.TypeError
> > an integer is required" error and can't find the reason.  I commenting
> > out the lines of code, it is happening on the connection.request() line.
> >  Here is the problem code.  Would love some help if possible.
>
> Please post the traceback that you get.
>
> My guess is that you are passing a string instead of an integer, probably
> for the port.
>
> [...]
>
> >    except:
> >            print sys.exc_type, sys.exc_value
>
> As a general rule, a bare except of that fashion is bad practice. Unless
> you can explain why it is normally bad practice, *and* why your case is
> an exception (no pun intended) to the rule "never use bare except
> clauses", I suggest you either:
>
> * replace "except:" with "except Exception:" instead.
>
> * better still, re-write the entire try block as:
>
>     try:
>         [code goes here]
>     finally:
>         connection.close()
>
> and use the Python error-reporting mechanism instead of defeating it.
>
> --
> Steven

Steven,

You are quite correct in your statements.  My goal was not to make
great code but something that I could quickly test.  My assumption was
that the httplib.HTTPSConnection() would do the cast to int for me.
As soon as I cast it to an int, I was able to get past that issue.

Still not able to post because I am getting a bad cert error.

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


bad certificate error

2009-07-27 Thread jakecjacobson
Hi,

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?  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?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quickly looping over a 2D array?

2009-07-27 Thread Martin
On Jul 27, 4:12 pm, Peter Otten <__pete...@web.de> wrote:
> Martin wrote:
> > The statement works now, but it doesn't give the same results as my
> > original logic, strangely!?
>
> > in my logic:
>
> > data = np.zeros((numrows, numcols), dtype = np.uint8, order ='C')
>
> > for i in range(numrows):
> > for j in range(numcols):
> > if band3[i,j] == 255 or band3[i,j] >= band6[i,j] * factor:
> > data[i,j] = 0
> > else:
> > data[i,j] = 1
>
> > to do the same with what you suggested...
>
> > data = np.ones((numrows, numcols), dtype = np.uint8, order ='C')
> > data[(band3 == 255) | (band6 >= band3 * factor)] = 0
>
> Did you swap band3 and band6? If that's the case, it is an error you should
> be able to find yourself.
>
> Please be a bit more careful.
>
> Also, it is good practice to write a few test cases where you have
> precalculated the result. How would you otherwise know which version is
> correct? Writing a third one to break the tie?
>
> Peter

apologies... it was the way I typed it up, I wasn't copying and
pasting from my text editor!
Thanks Peter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [python-win32] subprocess and stdout

2009-07-27 Thread Dave Angel
(This message was top-posted, and sent off-list.  So I'm copying it back 
to the list, with my response at the end)


Chris Chapman wrote:

Thanks Dave.  You know after trying your suggestion on the command prompt it 
doesn't as a matter of fact.  Not sure why I didn't just try that in windows to 
begin with.  Guess I got stuck more on the python issue then it being the other 
program.

There is an option for it to create an HTML log file, but it's formatted sort 
of strangely.  I'm really not looking to parse through it just for a summary 
like that presented on the terminal.  I'm not sure if you know but I'm guessing 
parsing the HTML would be a lot easier the trying to capture the console output 
from the buffer, huh?  Thanks again for the help.

Chris

  

Date: Mon, 27 Jul 2009 08:28:51 -0400
From: da...@ieee.org
To: oxydol...@hotmail.com
CC: python-wi...@python.org
Subject: Re: [python-win32] subprocess and stdout

Christopher Chapman wrote:


I'm trying to write a "module" to a larger program.  This module eventually
needs to reference a config file with setup information in it, but I'm not
there yet.  I'm using the subprocess module to run an external antivirus
program and trying to get the output written to a log file, but I keep
getting a weird return.  My code is listed below.  I'm a noob to Python so
I'm not sure if this is a windows specific issue or not, but I'm programming
on windows and more then likely what I'm working on won't be on anything
other then a windows machine.  I'm also writing my code for 3.1 if that
makes any difference.

# Pass target path to scanners command line and write output to a file
# Currently "scan" only targets the McAfee Command Line Scanner
print() 
print ("Begining scan of " + target)

print()
scan = "scan /all " + target
s = subprocess.Popen(scan,
 stdout=subprocess.PIPE)
out = s.communicate()[0]
chgout = str(out)
s.wait()
scanlog.write(chgout)
scanlog.close
"
If I change my stdout in s subprocess to None then everything gets written
to the terminal as if I had just run the program straight from the command
line, but when I try piping it to my file "scanlog" then literally the only
return I get in the file is '' or two single quotes.  I've even tried piping
the output and then printing it instead of writing it to a file and I get
the same result.  I've experimented with standard windows command line
commands and using the same syntax was able to pipe directory listings and
other things to my file.  Any ideas what I'm missing here?  Thanks in
advance

Chris Chapman


  
  
I suspect it's because of the way the antivirus program is written.  I 
can't be sure what you tried at the command prompt, but have you tried this:


c:\>scan /all > scanlog.txt


If this does not capture to the file, then scan.exe isn't written in the 
way you're expecting.  There are several ways to write directly to a 
console that do not redirect or pipe.


You might also look to see whether scan has any other commandline 
options.  One of them might be to create a log file.


DaveA



  


I wouldn't know where to begin trying to capture output that another 
process sends to its console window.  While I'm sure it's possible, I do 
suspect that parsing the html would be easier.  Remember that even if it 
looks ugly, it is generated by program, and it's quite possible that you 
could throw away the fluff and end up with a simple summary.  There are 
libraries to make this easier, but I've never used them.  If it's valid 
xhtml, which is by definition valid xml, you might find it useful to use 
elementree.  But most html is buggy, and parsing that takes a more 
tolerant parser.


DaveA

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


Re: quickly looping over a 2D array?

2009-07-27 Thread Robert Kern

On 2009-07-27 06:24, Martin wrote:

Hi,

I am new to python and I was wondering if there was a way to speed up
the way I index 2D arrays when I need to check two arrays
simultaneously? My current implementations is (using numpy) something
like the following...

for i in range(numrows):
 for j in range(numcols):

 if array_1[i, j] == some_value or array_2[i, j]>= array_1[i,
j] * some_other_value
 array_1[i, j] = some_new_value


Peter has given you good answers, but you will probably want to ask future numpy 
questions on the numpy mailing list.


  http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


New implementation of re module

2009-07-27 Thread MRAB

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.


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


Using easy_install, reduncant?

2009-07-27 Thread ray
I am working on a Trac installation.  I am new to Python.  To install
packages, it is suggested to use setuptools.  I have not understood
the directions.

I execute ez_install.py.

Then I attempt to execute easy_install.py setuptools-0.6c9-py2.6.egg.
There response that setuptools is already the active version in easy-
install.pth.  Then:
Installing easy_install.exe script to C:\Python26\Scripts error:  C:
\Python26\Scripts\Easy_install.exe: Permission denied.

I have compared the file entries before and after this attempt and
there are no new files.  Is there any problems here?  What did I miss?

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


Re: Using easy_install, reduncant?

2009-07-27 Thread John Nagle

ray wrote:

I am working on a Trac installation.  I am new to Python.  To install
packages, it is suggested to use setuptools.  I have not understood
the directions.

I execute ez_install.py.

Then I attempt to execute easy_install.py setuptools-0.6c9-py2.6.egg.
There response that setuptools is already the active version in easy-
install.pth.  Then:
Installing easy_install.exe script to C:\Python26\Scripts error:  C:
\Python26\Scripts\Easy_install.exe: Permission denied.


   "Easy Install" usually isn't "easy".  If it works, it's great.
Most of the time, it doesn't.  It's not very good at finding all the
files it needs to update.  Hence problems like the above.

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


Re: Using easy_install, reduncant?

2009-07-27 Thread Diez B. Roggisch
John Nagle wrote:

> ray wrote:
>> I am working on a Trac installation.  I am new to Python.  To install
>> packages, it is suggested to use setuptools.  I have not understood
>> the directions.
>> 
>> I execute ez_install.py.
>> 
>> Then I attempt to execute easy_install.py setuptools-0.6c9-py2.6.egg.
>> There response that setuptools is already the active version in easy-
>> install.pth.  Then:
>> Installing easy_install.exe script to C:\Python26\Scripts error:  C:
>> \Python26\Scripts\Easy_install.exe: Permission denied.
> 
> "Easy Install" usually isn't "easy".  If it works, it's great.
> Most of the time, it doesn't.  It's not very good at finding all the
> files it needs to update.  Hence problems like the above.

Which is the usual BS from you. It works most of the times as advertised,
and in the concrete case the OP misunderstood what ez_setup.py does
(already installing setuptools), and thus the complaint about "already
active version". Which btw is just a warning, and setuptools would
continue, but as the OP works on Windows which prohibits a running
executable to be replaced, it fails. Again, not setuptools fault.

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


M2Crypto hangs on this URL

2009-07-27 Thread John Nagle

There's something strange about this URL:

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

It hangs Firefox 2; there's no short timeout, the web page just gets
stuck in initial load for about ten minutes.  Then
"The connection to sagar310.pontins.com was interrupted while the page was 
loading."

It hangs M2Crypto 0.17 on both Linux and Windows, for at least 4 hours.

What does the new SSL implementation do?  (Haven't tried that yet;
waiting for MySQL support for Python 3.x before converting web apps.)

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


ioctl on socket

2009-07-27 Thread jacopo mondi
Is there a reason why there is no ioctl interface for socket either then
for windows platform? It's technical issues or what else??

thank in advance
jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert raw binary file to ascii

2009-07-27 Thread r2
On Jul 27, 9:06 am, Peter Otten <__pete...@web.de> wrote:
> r2 wrote:
> > I have a memory dump from a machine I am trying to analyze. I can view
> > the file in a hex editor to see text strings in the binary code. I
> > don't see a way to save these ascii representations of the binary, so
> > I went digging into Python to see if there were any modules to help.
>
> > I found one I think might do what I want it to do - the binascii
> > module. Can anyone describe to me how to convert a raw binary file to
> > an ascii file using this module. I've tried? Boy, I've tried.
>
> That won't work because a text editor doesn't need any help to convert the
> bytes into characters. If it expects ascii it just will be puzzled by bytes
> that are not valid ascii. Also, it will happily display byte sequences that
> are valid ascii, but that you as a user will see as gibberish because they
> were meant to be binary data by the program that wrote them.
>
> > Am I correct in assuming I can get the converted binary to ascii text
> > I see in a hex editor using this module? I'm new to this forensics
> > thing and it's quite possible I am mixing technical terms. I am not
> > new to Python, however. Thanks for your help.
>
> Unix has the "strings" commandline tool to extract text from a binary.
> Get hold of a copy of the MinGW tools if you are on windows.
>
> Peter

Okay. Thanks for the guidance. I have a machine with Linux, so I
should be able to do what you describe above. Could Python extract the
strings from the binary as well? Just wondering.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert raw binary file to ascii

2009-07-27 Thread r2
On Jul 27, 10:11 am, Grant Edwards  wrote:
> On 2009-07-27, r2  wrote:
>
> > I have a memory dump from a machine I am trying to analyze. I can view
> > the file in a hex editor to see text strings in the binary code. I
> > don't see a way to save these ascii representations of the binary,
>
> $ strings memdump.binary >memdump.strings
>
> $ hexdump -C memdump.binary >memdump.hex+ascii
>
> --
> Grant Edwards                   grante             Yow! I'm ZIPPY the PINHEAD
>                                   at               and I'm totally committed
>                                visi.com            to the festive mode.

Grant,

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


initializing with empty list as default causes freaky problems

2009-07-27 Thread Reckoner
Hi,

Observe the following:

In [202]: class Foo():
   .: def __init__(self,h=[]):
   .: self.h=h
   .:
   .:

In [203]: f=Foo()

In [204]: g=Foo()

In [205]: g.h
Out[205]: []

In [206]: f.h
Out[206]: []

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 am I missing here?

I'm using Python 2.5.1.

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


Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread MRAB

Reckoner wrote:

Hi,
X-Antispam: NO; Spamcatcher 5.2.1. Score 50

Observe the following:

In [202]: class Foo():
   .: def __init__(self,h=[]):
   .: self.h=h
   .:
   .:

In [203]: f=Foo()

In [204]: g=Foo()

In [205]: g.h
Out[205]: []

In [206]: f.h
Out[206]: []

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 am I missing here?

I'm using Python 2.5.1.


Default arguments are evaluated once and then shared, so don't use them
with mutable objects like lists. Do this instead:

class Foo():
def __init__(self, h=None):
if h is None:
self.h = []
else:
self.h = h
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert raw binary file to ascii

2009-07-27 Thread Peter Otten
r2 wrote:

> On Jul 27, 9:06 am, Peter Otten <__pete...@web.de> wrote:
>> r2 wrote:
>> > I have a memory dump from a machine I am trying to analyze. I can view
>> > the file in a hex editor to see text strings in the binary code. I
>> > don't see a way to save these ascii representations of the binary, so
>> > I went digging into Python to see if there were any modules to help.
>>
>> > I found one I think might do what I want it to do - the binascii
>> > module. Can anyone describe to me how to convert a raw binary file to
>> > an ascii file using this module. I've tried? Boy, I've tried.
>>
>> That won't work because a text editor doesn't need any help to convert
>> the bytes into characters. If it expects ascii it just will be puzzled by
>> bytes that are not valid ascii. Also, it will happily display byte
>> sequences that are valid ascii, but that you as a user will see as
>> gibberish because they were meant to be binary data by the program that
>> wrote them.
>>
>> > Am I correct in assuming I can get the converted binary to ascii text
>> > I see in a hex editor using this module? I'm new to this forensics
>> > thing and it's quite possible I am mixing technical terms. I am not
>> > new to Python, however. Thanks for your help.
>>
>> Unix has the "strings" commandline tool to extract text from a binary.
>> Get hold of a copy of the MinGW tools if you are on windows.
>>
>> Peter
> 
> Okay. Thanks for the guidance. I have a machine with Linux, so I
> should be able to do what you describe above. Could Python extract the
> strings from the binary as well? Just wondering.

As a special service for you here is a naive implementation to build upon:

#!/usr/bin/env python
import sys

wanted_chars = ["\0"]*256
for i in range(32, 127):
wanted_chars[i] = chr(i)
wanted_chars[ord("\t")] = "\t"
wanted_chars = "".join(wanted_chars)

THRESHOLD = 4

for s in sys.stdin.read().translate(wanted_chars).split("\0"):
if len(s) >= THRESHOLD:
print s

Peter

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


Re: M2Crypto hangs on this URL

2009-07-27 Thread John Nagle

John Nagle wrote:

There's something strange about this URL:

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

It hangs Firefox 2; there's no short timeout, the web page just gets
stuck in initial load for about ten minutes.  Then
"The connection to sagar310.pontins.com was interrupted while the page 
was loading."


It hangs M2Crypto 0.17 on both Linux and Windows, for at least 4 hours.


Correction: Linux is still hung at 5 hours, but Windows timed out
after about 15 minutes.

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


Re: CRLF Newlines and libc

2009-07-27 Thread Gabriel Genellina

En Mon, 27 Jul 2009 12:21:29 -0300, Eric  escribió:


I am working on the subprocess.Popen module for Google Summer of Code.
Right now, I am having difficulty trying to work out how to deal with
my '\n' newlines being converted to '\r\n' newlines when reading from
a pipe on windows; see this blog post (http://subdev.blogspot.com/
2009/07/stdout.html) and this chain on Python-Dev (http://
mail.python.org/pipermail/python-dev/2009-July/090720.html).

Right now, unless there is way to disable the newline conversions, I
am thinking I will just have to document the caveat and call it a day.
Is there a better way to handle this?


It isn't clear to me what exactly your problem is. What are you reading,  
using which functions, how did you open the file? On the writing side, how  
did you open the file, which functions are used to write?


The Windows API functions like CreateFile, ReadFile, WriteFile... don't  
perform any kind of '\n' conversion, neither reading nor writing. On the  
other hand, the C library does differentiate between files opened in text  
mode or binary mode (this comes from the ANSI C standard, it's not Windows  
specific). The default is "text" mode (unless you add "b" to the fopen  
call, or O_BINARY to the open call). In that mode, '\n' is translated to  
'\r\n' on writing, and '\r\n' is translated to '\n' on reading.
Python files are implemented on top of the C library (on 2.x) so they  
inherit that behaviour.
Console programs written in C and using printf/fwrite/write to stdout  
share that behaviour too (standard handles are opened in text mode by  
default).


Note that """'\n' newlines being converted to '\r\n' newlines when  
reading""" cannot happen -- if you see '\r\n' when reading, it's because

a) you're reading the file in binary mode, and
b) the file was written in text mode.

b) is true for process output redirected to a pipe, so you'll have to fix  
a). How to do that, depends on what exactly you're doing.


--
Gabriel Genellina

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


Re: bad certificate error

2009-07-27 Thread Gabriel Genellina
En Mon, 27 Jul 2009 12:57:40 -0300, jakecjacobson  
 escribió:



I was wondering if this is due to the server having a invalid server
cert?  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?


I don't see the point in trusting someone that you know is telling lies  
about itself.


--
Gabriel Genellina

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


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

2009-07-27 Thread Piotrek
Hello,

I write a Python program. It will contain some images (in .png format), some
audio files (as .ogg) etc. Now I think where should my installer put these
files and how should I access them. What is the normal Python way of doing
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?

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


Re: bad certificate error

2009-07-27 Thread jakecjacobson
On Jul 27, 2:23 pm, "Gabriel Genellina" 
wrote:
> En Mon, 27 Jul 2009 12:57:40 -0300, jakecjacobson  
>  escribió:
>
> > I was wondering if this is due to the server having a invalid server
> > cert?  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?
>
> I don't see the point in trusting someone that you know is telling lies  
> about itself.
>
> --
> Gabriel Genellina

It is a test box that the team I am on runs.  That is why I would
trust it.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >