Re: Simple eval

2007-11-19 Thread Gabriel Genellina
En Sun, 18 Nov 2007 22:24:39 -0300, greg <[EMAIL PROTECTED]>  
escribi�:

> Importing the names from tokenize that you use repeatedly
> should save some time, too.
>from tokenize import STRING, NUMBER
>
> If you were willing to indulge in some default-argument abuse, you
> could also do
>
>def atom(next, token, STRING = tokenize.STRING, NUMBER =  
> tokenize.NUMBER):
>  ...
>
> A more disciplined way would be to wrap it in a closure:
>
>def make_atom():
>  from tokenize import STRING, NUMBER
>  def atom(next, token):
>...
>  return atom

...but unfortunately it's the slowest alternative, so wouldn't count as a  
speed optimization.

I would investigate a mixed approach: using a parser to ensure the  
expression is "safe", then calling eval.

-- 
Gabriel Genellina

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

Finding lowest value in dictionary of objects, how?

2007-11-19 Thread davenet
Hi,

I'm new to Python and working on a school assignment.

I have setup a dictionary where the keys point to an object. Each
object has two member variables. I need to find the smallest value
contained in this group of objects.

The objects are defined as follows:

class Block:
   def __init__(self,addr):
  self.addr = addr
  self.age = 0

My dictionary is defined as:
   blocks = {}

I have added 1000 (will hold more after I get this working) objects. I
need to find the lowest age in the dictionary. If there is more than
one age that is lowest (like if several of them are '1', etc), then I
can just pick randomly any that equal the lowest value. I don't care
which one I get.

I saw the following code here but I don't know how to use this sample
to get at the values I need in the blocks object.

def key_of_lowest(self,addr)
   lowest = min(self.blocks.values())
   return [k for k in self.blocks if self.blocks[k]==val][0]

This one returns the lowest value Object, but not the lowest value of
age in all the Objects of the table.

I hope someone can help me figure out the syntax for what I'm trying
to do.

Thanks in advance.

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


Re: Python too complex ?!?!?!

2007-11-19 Thread Kay Schluehr
On 17 Nov., 14:46, Brian <[EMAIL PROTECTED]> wrote:

> Had a unsettling conversation with a CS instructor that
> teaches at local high schools and the community
> college. This person is a long-term Linux/C/Python
> programmer, but he claims that the install, config, and
> library models for C# have proved to be less
> problematic than Python. So both his courses (intro,
> data structs, algorithms) are taught in C#.

I don't understand this complaint. How does your instructor installs
libraries for C#? When he uses Linux for teaching purposes I assume
his students have little problems typing some shell commands and when
he uses Windows his students might feel comfortable double clicking on
a Windows installer - most likely containing prepackaged binaries.
What have I missed?

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


Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Marc 'BlackJack' Rintsch
On Mon, 19 Nov 2007 00:18:33 -0800, davenet wrote:

> The objects are defined as follows:
> 
> class Block:
>def __init__(self,addr):
>   self.addr = addr
>   self.age = 0
> 
> My dictionary is defined as:
>blocks = {}
> 
> I have added 1000 (will hold more after I get this working) objects. I
> need to find the lowest age in the dictionary. If there is more than
> one age that is lowest (like if several of them are '1', etc), then I
> can just pick randomly any that equal the lowest value. I don't care
> which one I get.
> 
> I saw the following code here but I don't know how to use this sample
> to get at the values I need in the blocks object.
> 
> def key_of_lowest(self,addr)
>lowest = min(self.blocks.values())
>return [k for k in self.blocks if self.blocks[k]==val][0]
> 
> This one returns the lowest value Object, but not the lowest value of
> age in all the Objects of the table.

In the example `min()` finds the object with the lowest `id()`.  To change
that you can implement the `__cmp__()` method on your `Block` objects.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Ben Finney
davenet <[EMAIL PROTECTED]> writes:

> I'm new to Python and working on a school assignment.

Thank you for being honest about this.

You should carefully read the policies on plagiarism for your
school. In general, the student is expected to use the resources of
their course material, the lecturer and tutor, and their own
creativity to come up with the answers — *not* ask on the internet.

-- 
 \ "I must have a prodigious quantity of mind; it takes me as much |
  `\  as a week sometimes to make it up."  -- Mark Twain, _The |
_o__)Innocents Abroad_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Steven D'Aprano
On Mon, 19 Nov 2007 00:18:33 -0800, davenet wrote:

> Hi,
> 
> I'm new to Python and working on a school assignment.

Thank you for your honesty.


> I have setup a dictionary where the keys point to an object. Each object
> has two member variables. I need to find the smallest value contained in
> this group of objects.
> 
> The objects are defined as follows:
> 
> class Block:
>def __init__(self,addr):
>   self.addr = addr
>   self.age = 0
> 
> My dictionary is defined as:
>blocks = {}


One possible approach is to define your Block data-type so that it 
defines less-than and greater-than comparisons. Then you can just ask 
Python to find the minimum Block by passing a list (not a dictionary) of 
Blocks to the function min().

 
> I have added 1000 (will hold more after I get this working) objects. I
> need to find the lowest age in the dictionary. If there is more than one
> age that is lowest (like if several of them are '1', etc), then I can
> just pick randomly any that equal the lowest value. I don't care which
> one I get.

Question: you don't explain how you have added them to the dict. A dict 
has a key and a value. What are the keys, and what are the values?

 
> I saw the following code here but I don't know how to use this sample to
> get at the values I need in the blocks object.
> 
> def key_of_lowest(self,addr)
>lowest = min(self.blocks.values())
>return [k for k in self.blocks if self.blocks[k]==val][0]
> 
> This one returns the lowest value Object, but not the lowest value of
> age in all the Objects of the table.

That code doesn't make much sense. It looks like a method rather than a 
function (the argument "self" is the giveaway). What is self.blocks and 
what is val?


> I hope someone can help me figure out the syntax for what I'm trying to
> do.

The first step you should do is write down how YOU would solve the 
problem.

"Let's see now... if I had a list of objects, and I wanted to find the 
smallest one, I would look at the first object, and compare it to all the 
other objects. If it was smaller than or equal to every other object in 
the list, I've found the smallest object and I'm finished!

If not, I'd take the second object, and compare it to all the other 
objects. If it is smaller than or equal to everything else, I've found 
the smallest object, and I'm finished.

If not, I would do the same for the third, and fourth, and fifth, and so 
forth, until I've found the smallest object."

Now start converting it to Python, step by step:

# Start with English instructions:
with each item in the list of objects:
if item is smaller than all the other items:
item is the smallest, and we're done


# Turn it into a function:
function find the smallest(list of objects):
with each item in the list of objects:
if item is smaller than all the other items:
item is the smallest, and we're done


# Now start using Python syntax:
def find_smallest(list_of_objects):
for item in list_of_objects:
if item is smaller than all the other items:
return item


# And continue:
def find_smallest(list_of_objects):
for item in list_of_objects:
for x in list_of_objects:
if item <= x:
return item



What I've done there is re-write the min() function in one of the 
slowest, most inefficient ways possible. If you try doing it by hand, 
you'll quickly see it's VERY inefficient. The better ways should be 
obvious once you actually do it. Then go through the process of writing 
it as Python code.



Hope this helps,


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


Re: Simple eval

2007-11-19 Thread Steven D'Aprano
On Sun, 18 Nov 2007 21:46:49 -0800, MonkeeSage wrote:

> As I see it, just as a matter of common sense, there will be no way to
> match the performance of the backend eval() with any interpreted code.
> At best, performance-wise, a preprocessor for the built-in eval() would
> be in order, filtering out the "unsafe" cases and passing the rest
> through. But what do I know, I could be dead wrong. :)


In general, there are two approaches to security.

The first is "Anything not explicitly permitted is forbidden".

The second is "Anything not explicitly forbidden is permitted".


The first is used when you actually want security. The second is when you 
are only pretending to care about security.

Valuing convenience and ease of use over security is a reasonable thing 
to do, but only so long as you know that you are putting security second 
and are prepared to face the consequences. I for one don't surround 
myself with a team of crack British ex-SAS officers as body guards, but 
that's because I'm prepared to run the risk of Russian ex-KGB special 
forces attacking.

On the other hand... I do lock my house. Rather than providing a list of 
people not allowed into the house, only those with a key are permitted.


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


Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Steven D'Aprano
On Mon, 19 Nov 2007 20:00:27 +1100, Ben Finney wrote:

> You should carefully read the policies on plagiarism for your school. In
> general, the student is expected to use the resources of their course
> material, the lecturer and tutor, and their own creativity to come up
> with the answers — *not* ask on the internet.

Plagiarism does not mean asking people for help. Nor does it mean using 
resources other than the official course material. 

It means passing off other people's work as your own.

Even in the sad, debased, commercialized world of the 21st century 
university, learning outside of the class is not yet forbidden.



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

computer language python in 2007

2007-11-19 Thread balu
computer language python in 2007
http://www.bidvertiser.com/
http://bigchurch.com/go/g906803-pmem
http://indianfriendfinder.com/go/g906803-pmem
-- 
http://mail.python.org/mailman/listinfo/python-list


computer language from american lang.

2007-11-19 Thread balu
computer language from american lang.
http://www.bidvertiser.com/
http://bigchurch.com/go/g906803-pmem
http://indianfriendfinder.com/go/g906803-pmem

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


Re: Python too complex ?!?!?!

2007-11-19 Thread alain
On Nov 19, 9:44 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 17 Nov., 14:46, Brian <[EMAIL PROTECTED]> wrote:
>
> > Had a unsettling conversation with a CS instructor that
> > teaches at local high schools and the community
> > college. This person is a long-term Linux/C/Python
> > programmer, but he claims that the install, config, and
> > library models for C# have proved to be less
> > problematic than Python. So both his courses (intro,
> > data structs, algorithms) are taught in C#.
>
> I don't understand this complaint. How does your instructor installs
> libraries for C#? When he uses Linux for teaching purposes I assume
> his students have little problems typing some shell commands and when
> he uses Windows his students might feel comfortable double clicking on
> a Windows installer - most likely containing prepackaged binaries.
> What have I missed?
>
> Kay

I think i understand his complaint.
Have you ever tried to install a package making use of easy_install?
If you have, then you understand this is a real pain in the ass,
especially if your internet access requires proxy authentication.
The world was easy before easy_install !

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


Re: how can i return a image in mod python ?

2007-11-19 Thread Abandoned
On Nov 18, 10:27 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Nov 18, 6:46 am, Abandoned <[EMAIL PROTECTED]> wrote:
>
> > Hi..
> > I want to show the pictures with mod python directly.
>
> > def showimage(req):
> > some process...
> > open /var/www/a.jpg and print
>
> > for example if i open:
> > domain.com/a.py/showimage
> > It must show meimagedirectly (no redirect or html)
>
> > How can i do it ?
> > I'm sorry for my bad english.
> > Kind Regards
>
> How about:
>
> def showimage(req):
> req.content_type="image/jpeg" # Change to youimagetype
> req.sendfile("/path/to/image.jpg")
>returnapache.OK
>
> HTH
>
> BTW mod_python has its own list :)
>
> --
> Arnaud

Thank you but i have a another problem.

def showimage(req):
from PIL import Image
im=Image.open("c:\image-2.jpg")
im.thumbnail((800,600), Image.ANTIALIAS)
req.sendfile(im)

give me some error.
How can i return this image witdhout save ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging.SocketHandler connections

2007-11-19 Thread oj
On Nov 16, 2:31 pm, Vinay Sajip <[EMAIL PROTECTED]> wrote:
> On Nov 15, 3:23 pm, oj <[EMAIL PROTECTED]> wrote:
>
>
>
> > However, initially, I had tried it with a server that closed the
> > connection after receiving each record, and the SocketHandler doesn't
> > seem to behave as advertised.
>
> > My test script was simply this:
>
> [snip]
> > The SocketHandler documentation says that it will re-establish the
> > connection if it has been closed. After a bit of digging, I found a
> > patch had been submitted and accepted that made it back off
> > exponentially. However, this should be time based. Even if I make my
> > sleep here 30 seconds, my server still only receives messages 0, 3, 6
> > and 9.
>
> > I'm concerned that if a connection is lost at some point, I will
> > always lose at least 2 log messages.
>
> > Is there some reason for this that I am not aware of? Have I
> > misunderstood something, or is this a bug?
>
> Not sure yet - can you please post your test server code? Feel free to
> add it as a bug on bugs.python.org, with the code attached, and I'll
> look into it. Include "logging" in the subject/summary line.
>
> Thanks,
>
> Vinay Sajip


Here is the server code. Pretty much directly copied from the example,
aside from not having the the handler loop forever, and queing the
records instead of dealing with the directly.

After further investigation, running the client with a long timeout,
without the server, so that every connection will fail, produces
results much closer to what I would expect. Connections attempted for
each message initially, but not for all of the later messages as the
retry time increases.

The point is kinda moot now, since I guess not closing the connection
is the 'right way' to do this, but I'm still interested in why I see
this behaviour when the server closes the connection.

#!/usr/bin/python

import thread
import cPickle
import logging
import logging.handlers
import SocketServer
import select
import struct
import sys
import time

port = 12345

queue = []
queue_lock = thread.allocate_lock()

class LogRecordStreamHandler(SocketServer.StreamRequestHandler):

def handle(self):
chunk = self.connection.recv(4)

if len(chunk) < 4:
print "failed to get 4 bytes in first read"
return

slen = struct.unpack(">L", chunk)[0]
chunk = self.connection.recv(slen)

while len(chunk) < slen:
chunk = chunk + self.connection.recv(slen -
len(chunk))

obj = self.unPickle(chunk)
record = logging.makeLogRecord(obj)

queue_lock.acquire()
queue.insert(0, record)
queue_lock.release()

def unPickle(self, data):
return cPickle.loads(data)

class LogRecordSocketReceiver(SocketServer.ThreadingTCPServer):

def __init__(self, host='localhost',
port=port, handler=LogRecordStreamHandler):
SocketServer.ThreadingTCPServer.__init__(self, (host,
port), handler)
self.abort = 0
self.timeout = 1
self.logname = None

def serve_until_stopped(self):
abort = 0
while not abort:
rd, wr, ex =
select.select([self.socket.fileno()],
[], [],
self.timeout)
if rd:
self.handle_request()
abort = self.abort

def listen():

server = LogRecordSocketReceiver()
server.serve_until_stopped()

def main():
global queue, queue_lock

logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(sys.stdout))

while True:
record = None
locked = queue_lock.acquire(0)

if locked:
if len(queue):
record = queue.pop()

queue_lock.release()

if record:
logger.handle(record)

else:
time.sleep(1)

if __name__ == '__main__':

thread.start_new_thread(listen, ())
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression

2007-11-19 Thread gardsted
The retarded cousin - that's me!

I keep getting confused by the caret - sometimes it works - sometimes it's 
better with backslash-n
Yes - retarded cousin, I guess.

The file format is a config-track for a multitrack recording software, which i 
need to automate a bit.
I can start it from the command line and have it create a remix (using various 
vst and other effects)
Sometimes, however, we may have deleted the 'guitar.wav' and thus have to leave
out that track from the config-file or the rendering won't work.

Since it seems 'whitespace matters' in the file I have the following code to 
get me a tag:
I cost me a broken cup and coffee all over the the kitchen tiles - temper!

I still don't understand why I have to use \n instead of ^ af the start of 
TAGCONTENTS and TAGEND.
But I can live with it!

Thank you for your kind and humorous help!
kind retards
jorgen / de mente
www.myspace.com/dementedk


import re

TESTTXT=open('003autoreaper.rpp').read() # whole file now

def getLevel(levl):
 rex = re.compile(
 r'(?m)'# multiline
 r'(?P^ {%d}[<])' # the < character
 r'(?P[a-zA-Z0-9_]*)'  # the tagname
 r'(?P[\S \t]*?$)' # the rest of the 
tagstart line
 r'(?P(\n {%d}[^>][\S \t]*$){0,})' # all the data 
coming before the >
 r'(?P\n {%d}>[\S \t]*$)' %(levl,levl,levl) # the > character
 )
 return rex

for i in getLevel(2).finditer(TESTTXT):
 myMatch = i.groupdict()
 print i.group('TAGNAME'),i.start('TAGSTART'), i.end('TAGEND')
 #print i.groups()
 if myMatch['TAGNAME'] == 'TRACK':
 #print i.groups()
 for j in getLevel(6).finditer(TESTTXT,i.start('TAGSTART'), 
i.end('TAGEND')):
 myMatch2 = j.groupdict()
 #print j.groups()
 print j.group('TAGNAME'),j.start('TAGSTART'), j.end('TAGEND')
 if myMatch2['TAGNAME'] == 'SOURCE':
 for m in myMatch2:
 print m, myMatch2[m]

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


return image in mod python

2007-11-19 Thread Abandoned
Hi i have a problem.

def showimage(req):
from PIL import Image
im=Image.open("c:\image-2.jpg")
im.thumbnail((800,600), Image.ANTIALIAS)
req.sendfile(im)



give me some error.
How can i return this image witdhout save ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return image in mod python

2007-11-19 Thread Diez B. Roggisch
Abandoned wrote:

> Hi i have a problem.
> 
> def showimage(req):
> from PIL import Image
> im=Image.open("c:\image-2.jpg")
> im.thumbnail((800,600), Image.ANTIALIAS)
> req.sendfile(im)
> 
> 
> 
> give me some error.

Really? I don't see any error. So there can't be one.

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


Re: What is python?????

2007-11-19 Thread James Stroud
rzed wrote:
> Cope <[EMAIL PROTECTED]> wrote in news:7ab5b781-3c6c-
> [EMAIL PROTECTED]:
> 
>> please tell me what is python.This group is so crowded.
>>
> 
> I see nobody has chosen to answer your question seriously. I'll 
> give you an answer, but it is probably not to the question you are 
> asking, either.
> 
> Python is not one thing.
> 
> Python is the name of a computer language, which you can determine 
> easily through Google or Wikipedia or other means. That's what 
> comp(uter).lang(uage).python is here for, nominally.
> 
> Python is also a package of programs that implement the language 
> and create a Python runtime environment. The most common 
> implementation is of a virtual machine that runs Python bytecodes, 
> though other variations run Java or .NET bytecodes.
> 
> And Python is also a set of packages that provide utilities and 
> features that allow users of the packages to do useful things on 
> their computers without unnecessary fuss and bother. Some of these 
> utilities come with a basic Python installation (code name: 
> "batteries included"), while others are available elsewhere, often 
> from the Python Package Index (codename: "cheese shop"), but from 
> other sources as well. 
> 
> Some people conflate these meanings of "Python", which can lead to 
> confusion at times. Much of the crowdedness of the group has to do 
> with discussion related to the batteries-included features and to 
> the other packages written to run in the Python environment.
> 
> Hope that helps.
> 

You're having a conversation with a spambot.

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is python?????

2007-11-19 Thread Diez B. Roggisch
> You're having a conversation with a spambot.

Spam - certainly. But bot - no. Unless there have been some really
remarkable improvements in KI lately.

It's amazing that recently so many spam is written by some guys actually
_reading_ this group. I presume they somehow want to create credibility in
their postings by provoking real threads that then at some point contain
the actual information.

Can't beat Turing if the other side actually _is_ human...

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


Re: newbie Q: sequence membership

2007-11-19 Thread John Machin
> 
> On Nov 17, 4:35 am, John Machin <[EMAIL PROTECTED]> wrote:
>> Worse: Consider z = ['A1', 'Z9']. It's highly likely that when x ==
>> 'A1', "x is_in z" is True -- because an unguaranteed implementation-
>> dependent caper caches or "interns" some values, so that x and z[0]
>> are the same object. Try explaining that to the novices!!
>>
> I am not a programmer so I feel odd commenting about language design
> decisions. When my Prof. introduced python the first question that
> popped into mind was that since "x=9; y=9; print x is y and x == y"
> prints "True" is there a way to change the value of 9? He said that
> was silly but after class showed me that statements "True = []" work
> but suggested it was harmless and not quite a bug.
> 
> So if I am permitted to think of integers as immutable objects with
> predefined labels (i.e. the integers used in the text of the program
> code) that cannot de or re referenced then what a similar treatment of
> characters will look like seams to be an arbitary (a design) decition.

You are permitted to think as you will :-) However an integer object in 
general has no predefined label. It may have multiple names, or no name 
at all.

a = 4567; b = a; assert b is a

a = 2000; b = 1000 + 1000 # can assert b == a, can't assert b is a

You are approaching this from the wrong end. Briefly: Everything about 
== works as expected. It is quite possible for a == b to be true but a 
is b to be false. This is a non-arbitrary design decision. One fact that 
I didn't tell you: Integers in range(-1, 101) are interned in the 
CPython implementation, similar to the string interning that you 
mentioned. For your wishes to come true, *every* value would have to be 
interned. This is impractical.

> 
> In this vein it seams reasonable to expect 'a'[0] and 'ba'[1] to refer
> to the same object. 

> If one follows the convention used with integers
> (9 and 9 refer to the same object) then 'ab' and 'ab' would be the
> same. An equally reasonable assumption would be that 'ab' and 'ab' are
> two different sequences and so not equal (I do not see the problem
> here).
> 
> Actually this is what you said is left up to the implementation. '=='
> seams to add a lot of power but I am not sure where or how (except as
> a shortcut in the very special case of strings). Pardon the babble.

Look at it this way: "==" (same value) is what one normally needs. The 
utility of "is" (same object) is much smaller.

> 
> 
> On Nov 17, 4:35 am, John Machin <[EMAIL PROTECTED]> wrote:
>> Do you have a use case for that?
>>
> I have a list of lists and want to see if another list is a member of
> it. The content of the lists and the way they are related to each
> other changes from program to program.

I meant "What practical use do you have for two mutually recursive 
cursive lists?".
-- 
http://mail.python.org/mailman/listinfo/python-list


securing a python execution environment...

2007-11-19 Thread Chris Withers
Hi All,

I'm trying to build a secure execution environment for bits of python 
for two reasons:

- to allow users of the system to write scripts in python without 
circumventing the application's security model

- to allow the system to have an environment where security is handled 
without having to do explicit checks in every piece of example code.

This second point is better demonstrated by an example:

Bad:

 >>> from security import check,AccessDenied
 >>> if check(someobj,'someattr'):
 >>>   print someattr
 >>> else:
 >>>   raise AccessDenied("can't access 'someattr')
Traceback (most recent call last):
   File "", line ?, in ?
AccessDenied: can't access 'someattr'

Good:

 >>> someobj.someattr
Traceback (most recent call last):
   File "", line ?, in ?
AccessDenied: can't access 'someattr'

Now, I think I can get a lot of this from Zope 3's security proxy 
objects, however I need to find a way to limit the importing of modules 
to, for example, prevent people importing the method that unwraps the 
proxy objects ;-)

Have other people bumped into this problem?
What solutions do people recommend?

cheers,

Chris

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


Re: What is python?????

2007-11-19 Thread Chris Withers
Diez B. Roggisch wrote:
> It's amazing that recently so many spam is written by some guys actually
> _reading_ this group. I presume they somehow want to create credibility in
> their postings by provoking real threads that then at some point contain
> the actual information.

I wonder why this group/list isn't moderated in such a way that posts by 
new members are moderated at first until they're seen to be human. (and 
non-spamming humans to boot ;-) )

I admin a few low volume lists and it's proved very close to 100% 
successful in killing off the spam problem :-)

cheers,

Chris

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


struct,long on 64-bit machine

2007-11-19 Thread Neal Becker
What's wrong with this?
type(struct.unpack('l','\00'*8)[0])


Why I am getting 'int' when I asked for 'long'?

This is on python-2.5.1-15.fc8.x86_64

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


Re: securing a python execution environment...

2007-11-19 Thread Laszlo Nagy
Chris Withers wrote:
> Hi All,
>
> I'm trying to build a secure execution environment for bits of python 
> for two reasons:
>
> - to allow users of the system to write scripts in python without 
> circumventing the application's security model
>
> - to allow the system to have an environment where security is handled 
> without having to do explicit checks in every piece of example code.
>
> This second point is better demonstrated by an example:
>
> Bad:
>
>  >>> from security import check,AccessDenied
>  >>> if check(someobj,'someattr'):
>  >>>   print someattr
>  >>> else:
>  >>>   raise AccessDenied("can't access 'someattr')
> Traceback (most recent call last):
>File "", line ?, in ?
> AccessDenied: can't access 'someattr'
>
> Good:
>
>  >>> someobj.someattr
> Traceback (most recent call last):
>File "", line ?, in ?
> AccessDenied: can't access 'someattr'
>
> Now, I think I can get a lot of this from Zope 3's security proxy 
> objects, however I need to find a way to limit the importing of modules 
> to, for example, prevent people importing the method that unwraps the 
> proxy objects ;-)
>
> Have other people bumped into this problem?
> What solutions do people recommend?
>   
Once upon a time, there has been a module called "bastillon" (am I 
right?) and "rexec" (restricted execution environment) but they were not 
really secure. It was a long time ago. Python is very flexible, and 
interpreted and it is hard to prevent the users from importing modules. 
They can do nasty things. For example, open a file and eval() it etc. It 
is almost impossible to setup an environment in pure Python, that 
restricts them to do certain things. Python is too flexible for that, 
and "bad" users are too ingenious.

I would say, the only reliable solution is to use a virtual machine. For 
example, use chroot, jail (under FreeBSD) or wmware, and install only 
the allowed modules on that virtual computer. Install firewall rules to 
prevent the user from connecting to any host, use a write-protected 
disk, have them use nobody:nogroup etc. And finally, open one port where 
they can connect to your protected internal server that will check 
permissions and do the actual job for them. In other words, let the 
operating system restrict the resources. Well, this is what I would do, 
maybe I'm wrong. I have never had to do this.

Best,

   Laszlo

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


Re: struct,long on 64-bit machine

2007-11-19 Thread Robin Becker
Neal Becker wrote:
> What's wrong with this?
> type(struct.unpack('l','\00'*8)[0])
> 
> 
> Why I am getting 'int' when I asked for 'long'?
> 
> This is on python-2.5.1-15.fc8.x86_64
> 
On my AMD 64 I think int is 64 bits


$ python -c "import sys; print sys.maxint"
9223372036854775807

-- 
Robin Becker

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


Re: struct,long on 64-bit machine

2007-11-19 Thread Hrvoje Niksic
Neal Becker <[EMAIL PROTECTED]> writes:

> What's wrong with this?
> type(struct.unpack('l','\00'*8)[0])
> 
>
> Why I am getting 'int' when I asked for 'long'?

C longs are converted to Python integers; see the table on
http://docs.python.org/lib/module-struct.html.  If you really need the
Python long, use long(...).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding methods - two questions

2007-11-19 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> 
>>> Question 1:
>>>
>>> Given that the user of the API can choose to override foo() or not, how
>>> can I control the signature that they use?
>> While technically possible (using inspect.getargspec), trying to make
>> your code idiot-proof is a lost fight and a pure waste of time.
> 
> 
> Worse: it's actually counter-productive!
> 
> The whole idea of being able to subclass a class means that the user 
> should be able to override foo() *including* the signature. 

If you see subclassing as subtyping, the signatures should always stay 
fully compatibles.

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

Re: overriding methods - two questions

2007-11-19 Thread Bruno Desthuilliers
George Sakkis a écrit :
> On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
> 
>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
 Question 1:
 Given that the user of the API can choose to override foo() or not, how
 can I control the signature that they use?
>>> While technically possible (using inspect.getargspec), trying to make
>>> your code idiot-proof is a lost fight and a pure waste of time.
>> Worse: it's actually counter-productive!
>>
>> The whole idea of being able to subclass a class means that the user
>> should be able to override foo() *including* the signature. Why do you
>> want to stop them?
> 
> Primarily because of this: 
> http://en.wikipedia.org/wiki/Liskov_substitution_principle.
> 
>> Let me give a practical example:
>>
>> (snip misleading example involving __init__)
> 
> Constructors are in general different from other regular methods
> because you refer explicitly to the class name when creating an
> instance;

Not necessarily. There are (quite a few) cases where you don't know 
which "concrete" class you're instanciating...

> that is, the client writes "f = ContinuedFraction(...)" or
> "f = RegularCF(...)" so it's not necessary to have the same signature
> in __init__. 

import platform
cls = platform.get_the_class()
obj = cls('yadda', 42)

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


Re: securing a python execution environment...

2007-11-19 Thread Alberto Berti

maybe using import hooks?

http://www.python.org/dev/peps/pep-0302/

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


ANN: eGenix mxODBC and mxODBC Zope DA on AIX 5.3 (and later)

2007-11-19 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com mxODBC Database Interface

  eGenix.com mxODBC Zope Database Adapter

   for AIX 5.3 and later


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-on-AIX53-POWER5-GA.html



eGenix mxODBC Distribution

The eGenix mxODBC Distribution is a Python database interface add-on
distribution for our eGenix mx Base Distribution. It comes with mxODBC,
our universal ODBC database interface for Python.

Customers who have purchased licenses for other platforms and wish to
move their installation to AIX 5.3 (or later), can do so without having
to buy a new license. The licenses will continue to work on the AIX
platform.

Users of mxODBC 2.0 will have to purchase new licenses from our online
shop in order to upgrade to mxODBC 3.0.

You can request 30-day evaluation licenses on the product page.

Downloads
-

Please visit the eGenix mxODBC Distribution page for downloads,
instructions on installation and documentation of the packages.

http://www.egenix.com/products/python/mxODBC/

Note that in order to use the eGenix mxODBC Distribution you need to
install the eGenix mx Base Distribution first.



eGenix mxODBC Zope DA


eGenix mxODBC Zope DA is our database interface for Zope and Plone. It
is based on the mxODBC interface.

Customers who have purchased licenses for other platforms and wish to
move their installation to AIX 5.3 (or later), can do so without having
to buy a new license. The licenses will continue to work on the AIX
platform.

You can request 30-day evaluation licenses on the product page.

Downloads
-

Please visit the eGenix mxODBC Zope DA product page for downloads,
instructions on installation and documentation of the packages.

http://www.egenix.com/products/zope/mxODBCZopeDA/



More Information

For more information on our products, licensing and download
instructions, please write to [EMAIL PROTECTED]

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

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


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


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


Re: What is python?????

2007-11-19 Thread rzed
James Stroud <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> 
> You're having a conversation with a spambot.

Actually, my intent was to address the question that was asked. 
Much of the genuine conversation in the group really does intermix 
the various senses of "Python", sometimes in ways that confuse the 
issues actually being discussed. People ask for changes to the 
language syntax when what they are really after can be addressed 
by additions or changes to libraries. Or they believe Python 
should have such-and-such a feature when the feature is available 
through external packages. Or their suggested changes to 
accommodate their desired feature would require fundamental and 
incompatible changes to the compiler.

The way I think of the language Python is as a clean, small 
enabler of functionality. The prepackaged Python distro supplies 
some of that functionality (the included batteries), and the 
environment Python makes far more available. Under that view, 
changes to the language should be the sort that allow the 
functionality to proceed cleanly. That is, there should be a 
Pythonic way to approach databases, windowing, interprocess 
communication and so on. The packages that perform the function 
should be interchangeable as far as the language is concerned. I 
don't believe everyone here would agree with this view, possibly. 

Regardless of the origin of the question, though, it is one worth 
discussing, which is why I responded to the post. Do we all really 
have the same view of what Python actually is? Or what it could 
be?

-- 
rzed


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


Re: implement random selection in Python

2007-11-19 Thread Neil Cerutti
On 2007-11-17, Bruza <[EMAIL PROTECTED]> wrote:
> OOPS. I pressed the Send too fast.
>
> The problem w/ Boris's solution is that after repeated calling
> of randomPick(3,items), 'Jane' is not the most "frequent
> appearing" member in all the out list of 3 member lists...

How does this solution fair against your spec?

def sample_bp(seq, probabilities, k):
""" Return k distinct random items from seq, with probabilities specified
as weighted integers in a list.

>>> random.seed(0)

>>> sample_bp(['a', 'b'], [1, 5], 2)
['b', 'a']

>>> sample_bp(['a', 'b', 'c'], [1, 5, 2], 3)
['b', 'a', 'c']

"""

if k > len(seq):
raise ValueError('sample size greater than population')
probs = build_probs(probabilities)
rv = []
while k > 0:
j = random_prob(probs)
rv.append(probs[j][2])
remove_prob(probs, j)
k -= 1
return [seq[i] for i in rv]

def build_probs(probabilities):
""" Receives a list of integers, and returns list of ranges and original
indices.

>>> build_probs([8, 10, 7])
[(0, 8, 0), (8, 18, 1), (18, 25, 2)]
>>> build_probs([1, 5, 8, 2, 3, 7])
[(0, 1, 0), (1, 6, 1), (6, 14, 2), (14, 16, 3), (16, 19, 4), (19, 26, 5)]


"""
k = 0
probs = []
for i, p in enumerate(probabilities):
if p < 0:
raise ValueError('negative probability')
probs.append((k, k+p, i))
k = k+p
return probs

def random_prob(probs):
""" Return the index of a weighted random element of prob.

>>> random.seed(0)

>>> for x in xrange(20):
... print random_prob(build_probs([1, 5, 8, 2, 3, 7])),
5 5 2 2 2 2 5 2 2 3 5 2 2 5 4 2 5 5 5 5

>>> random_prob([(0, 15, 0)])
0

"""
i = random.randrange(probs[-1][1])
# Binary search for the element whose range contains i
hi = len(probs)
lo = 0
while lo < hi:
mid = (lo+hi)//2
begin, end, _ = probs[mid]
if i >= begin and i < end: return mid
elif i >= end: lo = mid+1
else: hi = mid

def remove_prob(probs, i):
""" Remove element j from the probability list, adjusting ranges as needed.

>>> prob = [(0, 12, 0), (12, 15, 1), (15, 25, 2)]
>>> remove_prob(prob, 1)
>>> prob
[(0, 12, 0), (12, 22, 2)]

"""
begin, end, _ = probs[i]
diff = end - begin
j = i+1
while j < len(probs):
begin, end, index = probs[j]
probs[j] = (begin-diff, end-diff, index)
j += 1
del probs[i]

This was the most simple-minded approach I could think of, so it
might serve as a reference against a more efficient approach.
Although thorough testing of such a bizarre function boggles my
mind.

I toyed with sorting the probability list from greatest to
lowest, which would make a linear search fast, but unfortunately
it would slow down removing probabilities.

-- 
Neil Cerutti
I make love to pressure. --Stephen Jackson
-- 
http://mail.python.org/mailman/listinfo/python-list


guess file type in python

2007-11-19 Thread Japan Shah
 

 



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

Re: securing a python execution environment...

2007-11-19 Thread Laszlo Nagy
Alberto Berti wrote:
> maybe using import hooks?
>
> http://www.python.org/dev/peps/pep-0302/
>
>   
I don't think so. Anyone can hook the import statement. And this is just 
one reason. Some objects are built in. For example, file(). How can you 
restrict file creation? I believe that there is no safe restricted 
environment, implemented in pure python.

Best,


   Laszlo

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


Re: securing a python execution environment...

2007-11-19 Thread Chris Withers
Laszlo Nagy wrote:
> Once upon a time, there has been a module called "bastillon" (am I 
> right?) and "rexec" (restricted execution environment) but they were not 
> really secure. It was a long time ago. Python is very flexible, and 
> interpreted and it is hard to prevent the users from importing modules. 

Indeed. I think Zope's security proxies solve a lot of the problem as 
they are a C extension to python and so can't be circumvented ;-)

> They can do nasty things. For example, open a file and eval() it etc. 

Yes, there are plenty of builtins that need to be blocked out and plenty 
of things that need to be blocked from being imported, but I know it is 
possible ;-)

(see Zope's "Script (Python)" objects, I'm just hoping for a cleaner, 
simpler solution...)

cheers,

Chris

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


Re: What is python?????

2007-11-19 Thread Wildemar Wildenburger
Cope wrote:
> within 10 months over 1 mn joined the network. everything available on
> its viewbar. But it can be download only onXP and Vista for security.
> 
> Cope
> www.spam.spam/spam/SPAM
> www.spam-spam.spam

See, Diez was right.

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


Re: return image in mod python

2007-11-19 Thread Abandoned
On Nov 19, 12:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Abandoned wrote:
> > Hi i have a problem.
>
> > def showimage(req):
> > from PIL import Image
> > im=Image.open("c:\image-2.jpg")
> > im.thumbnail((800,600), Image.ANTIALIAS)
> > req.sendfile(im)
>
> > give me some error.
>
> Really? I don't see any error. So there can't be one.
>
> Diez

It gives me this error:
req.sendfile(im)

TypeError: argument 1 must be string, not instance

Sendfile uses as:
req.sendfile("C:/img.jpg")
But i don't know how can i return when i use PIL before return ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: securing a python execution environment...

2007-11-19 Thread Chris Withers
Alberto Berti wrote:
> maybe using import hooks?
> 
> http://www.python.org/dev/peps/pep-0302/

Well, as Lazlo reminded me, there are also plenty of builtins that are 
problematic... although hopefully providing a limited set of contents 
for the global and local namespaces could solve that?

But, regardless of those, how do you prevent someone "undoing" the 
hooks, regardless of which ones you use?

cheers,

Chris

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


Re: securing a python execution environment...

2007-11-19 Thread Giles Brown
On 19 Nov, 11:16, Chris Withers <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm trying to build a secure execution environment for bits of python
> for two reasons:
>
> - to allow users of the system to write scripts in python without
> circumventing the application's security model
>
> - to allow the system to have an environment where security is handled
> without having to do explicit checks in every piece of example code.
>
> This second point is better demonstrated by an example:
>
> Bad:
>
>  >>> from security import check,AccessDenied
>  >>> if check(someobj,'someattr'):
>  >>>   print someattr
>  >>> else:
>  >>>   raise AccessDenied("can't access 'someattr')
> Traceback (most recent call last):
>File "", line ?, in ?
> AccessDenied: can't access 'someattr'
>
> Good:
>
>  >>> someobj.someattr
> Traceback (most recent call last):
>File "", line ?, in ?
> AccessDenied: can't access 'someattr'
>
> Now, I think I can get a lot of this from Zope 3's security proxy
> objects, however I need to find a way to limit the importing of modules
> to, for example, prevent people importing the method that unwraps the
> proxy objects ;-)
>
> Have other people bumped into this problem?
> What solutions do people recommend?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Zope & Python Consulting
> -http://www.simplistix.co.uk

Maybe this is of interest?
http://codespeak.net/pypy/dist/pypy/doc/sandbox.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: securing a python execution environment...

2007-11-19 Thread Paul Boddie
On 19 Nov, 12:16, Chris Withers <[EMAIL PROTECTED]> wrote:
>
> I'm trying to build a secure execution environment for bits of python
> for two reasons:

[...]

> Have other people bumped into this problem?
> What solutions do people recommend?

It might be worth looking at these pages for some suggestions:

http://wiki.python.org/moin/SandboxedPython
http://wiki.python.org/moin/How_can_I_run_an_untrusted_Python_script_safely_%28i%2ee%2e_Sandbox%29

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


Re: overriding methods - two questions

2007-11-19 Thread J. Clifford Dyer
On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote regarding 
Re: overriding methods - two questions:
> 
> Steven D'Aprano a ?crit :
> > On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> > 
> >>> Question 1:
> >>>
> >>> Given that the user of the API can choose to override foo() or not, how
> >>> can I control the signature that they use?
> >> While technically possible (using inspect.getargspec), trying to make
> >> your code idiot-proof is a lost fight and a pure waste of time.
> > 
> > 
> > Worse: it's actually counter-productive!
> > 
> > The whole idea of being able to subclass a class means that the user 
> > should be able to override foo() *including* the signature. 
> 
> If you see subclassing as subtyping, the signatures should always stay 
> fully compatibles.
> 

Isn't that more what Zope-type interfaces are for than inheritance?  I'm 
uncertain here, but I'm not persuaded that changing signature is bad.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interfaces.

2007-11-19 Thread Scott SA
On 11/17/07, Duncan Booth ([EMAIL PROTECTED]) wrote:

>Bjoern Schliessmann <[EMAIL PROTECTED]> wrote:
>
>> Benjamin wrote:
>>> Python is has duck typing. "If it quacks like a duke, it's duck."
>> 
>> How do dukes quack, exactly? :)
>
>They quack with a North-eastern Scottish accent of course.
>
>The following excerpt from "Scots: Practical Approaches" should make it 
>clear:
>
>> A. From Scotland the What?, by Buff Hardie, Stephen Robertson and
>> George Donald (Gordon Wright, 1987) 
>> 
>> In this comic monologue from 1982, the owner of a toy shop in
>> Ballater, near Aberdeen telephones the Princess of Wales to ask what
>> her son would like for Christmas. 
>> 
>> Noo, fit wid he like for his Christmas, the loon? Fit aboot a pair o‚
>> fitba beets? Beets. Beets. B-O-O-T-S, beets. Weel, I ken that, but
../snip/...
>> D-U-C-K, duke. A quack quack duke. Like Donald Duke. Donald Duke. He‚s
>> a freen‚ o‚ Mickey Moose...Moose...M-O-U-S-E, Moose! God, div ye nae
>> understan‚ English, lassie? 

I think me sister wah bit be onae eese. 
Is ears nae long enuff ta be a rrhabbitt, an ah latter nae care fer cheese.

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

Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread davenet
On Nov 19, 1:00 am, Ben Finney <[EMAIL PROTECTED]>
wrote:
> davenet <[EMAIL PROTECTED]> writes:
> > I'm new to Python and working on a school assignment.
>
> Thank you for being honest about this.
>
> You should carefully read the policies on plagiarism for your
> school. In general, the student is expected to use the resources of
> their course material, the lecturer and tutor, and their own
> creativity to come up with the answers -- *not* ask on the internet.
>
> --
>  \ "I must have a prodigious quantity of mind; it takes me as much |
>   `\  as a week sometimes to make it up."  -- Mark Twain, _The |
> _o__)Innocents Abroad_ |
> Ben Finney

First of all, this is not a Python class I'm taking in college, it's
an operating systems class. Second, we're learning about memory levels
and this assignment was given to us with parts written in Python but
we could have used any other language to implement the solution.
Third, I've never used Python before so I'm not familiar with all the
features available in the language. Hence, I came here to ask so I
could spend time implementing the actual assignment instead of trying
to figure out how Python works.

Thanks to everyone else who tried to point me in the right direction.

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


Re: Python too complex ?!?!?!

2007-11-19 Thread kyosohma
On Nov 17, 7:46 am, Brian <[EMAIL PROTECTED]> wrote:
> Had a unsettling conversation with a CS instructor that
> teaches at local high schools and the community
> college. This person is a long-term Linux/C/Python
> programmer, but he claims that the install, config, and
> library models for C# have proved to be less
> problematic than Python. So both his courses (intro,
> data structs, algorithms) are taught in C#.
>
> I am a low-end (3-year) journeyman Pythonista, and I
> was attracted to the language because of its
> simplicity. And I have come to enjoy the richness of
> available libraries.
>
> Many of the good people of this NG may be 'too close'
> to answer, but has Python, as a general devel platform,
> lost its simplicity ? Is library install too complex
> and unreliable ? Will my dog go to heaven ?

If this professor was only using Windows for his environment, then I
might be able to understand his argument better. There are many more
external modules for Python that don't have Windows installers than
there are with binaries. And I've had more than my fair share of
broken setup.py files.

On the other hand, if all that is needed are the standard libraries,
than it's a breeze to install Python since they're all included.

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


Re: Book: Python Power!: The Comprehensive Guide

2007-11-19 Thread kyosohma
On Nov 18, 12:17 am, John Salerno <[EMAIL PROTECTED]> wrote:
> Anyone know anything about this book? I've read a few intro Python books
> already, but I'm always interested in reading more to reinforce the
> language. No reviews on Amazon yet so I'm not sure if it's good or not.
>
> Thanks.

It's a mostly good book. I found the author to be slightly arrogant as
he would dismiss certain features of Python on occasion and there were
a couple of "huh!?" moments where he contradicted what seems (to me)
to be common Python idioms.

But there's a lot to like too. There's a real app or two at the end
and it covers using cgi in Python better than any of the other Python
books I've read.

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


Re: overriding methods - two questions

2007-11-19 Thread George Sakkis
On Nov 19, 7:44 am, Bruno Desthuilliers  wrote:
> George Sakkis a écrit :
>
>
>
> > On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > cybersource.com.au> wrote:
>
> >> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>  Question 1:
>  Given that the user of the API can choose to override foo() or not, how
>  can I control the signature that they use?
> >>> While technically possible (using inspect.getargspec), trying to make
> >>> your code idiot-proof is a lost fight and a pure waste of time.
> >> Worse: it's actually counter-productive!
>
> >> The whole idea of being able to subclass a class means that the user
> >> should be able to override foo() *including* the signature. Why do you
> >> want to stop them?
>
> > Primarily because of 
> > this:http://en.wikipedia.org/wiki/Liskov_substitution_principle.
>
> >> Let me give a practical example:
>
> >> (snip misleading example involving __init__)
>
> > Constructors are in general different from other regular methods
> > because you refer explicitly to the class name when creating an
> > instance;
>
> Not necessarily. There are (quite a few) cases where you don't know
> which "concrete" class you're instanciating...
>
> > that is, the client writes "f = ContinuedFraction(...)" or
> > "f = RegularCF(...)" so it's not necessary to have the same signature
> > in __init__.
>
> import platform
> cls = platform.get_the_class()
> obj = cls('yadda', 42)

That's why I qualified my statement with "in general" ;-) Besides,
this emphasizes even further the need for consistent (though not
necessarily identical) signatures in all (public) methods, which was
my point anyway.

George

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


Re: guess file type in python

2007-11-19 Thread Matt Nordhoff
Japan Shah wrote:
>  
> 
>  
> 
>
> 

mimetypes module?
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return image in mod python

2007-11-19 Thread Diez B. Roggisch
Abandoned wrote:

> On Nov 19, 12:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> Abandoned wrote:
>> > Hi i have a problem.
>>
>> > def showimage(req):
>> > from PIL import Image
>> > im=Image.open("c:\image-2.jpg")
>> > im.thumbnail((800,600), Image.ANTIALIAS)
>> > req.sendfile(im)
>>
>> > give me some error.
>>
>> Really? I don't see any error. So there can't be one.
>>
>> Diez
> 
> It gives me this error:
> req.sendfile(im)
> 
> TypeError: argument 1 must be string, not instance
> 
> Sendfile uses as:
> req.sendfile("C:/img.jpg")
> But i don't know how can i return when i use PIL before return ?

Then don't use sendfile. I don't know mod_python, but I'm pretty sure you
can output what you want somehow to the output stream. So, do that. 

Or go down the easy road, create a temp-file to store the image and send
that.

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


Re: overriding methods - two questions

2007-11-19 Thread Bruno Desthuilliers
J. Clifford Dyer a écrit :
> On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote regarding 
> Re: overriding methods - two questions:
>> Steven D'Aprano a ?crit :
>>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>>>
> Question 1:
>
> Given that the user of the API can choose to override foo() or not, how
> can I control the signature that they use?
 While technically possible (using inspect.getargspec), trying to make
 your code idiot-proof is a lost fight and a pure waste of time.
>>>
>>> Worse: it's actually counter-productive!
>>>
>>> The whole idea of being able to subclass a class means that the user 
>>> should be able to override foo() *including* the signature. 
>> If you see subclassing as subtyping, the signatures should always stay 
>> fully compatibles.
>>
> 
> Isn't that more what Zope-type interfaces are for than inheritance?

With dynamically typed languages like Python, you don't need any formal 
mechanism (zope-like interface or whatever) for subtyping to work - just 
make sure your two classes have the same public interface and it's ok. 
So indeed inheritance is first a code-reuse feature.

> I'm uncertain here, but I'm not persuaded that changing signature is
> bad.

Depends if the subclass is supposed to be a proper subtype (according to 
LSP) too.
-- 
http://mail.python.org/mailman/listinfo/python-list


[EMAIL PROTECTED]: Re: overriding methods - two questions]

2007-11-19 Thread J. Clifford Dyer
On Mon, Nov 19, 2007 at 04:33:39PM +0100, Bruno Desthuilliers wrote regarding 
Re: overriding methods - two questions:
> 
> J. Clifford Dyer a ?crit :
> > On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote 
> > regarding Re: overriding methods - two questions:
> >> Steven D'Aprano a ?crit :
> >>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> >>>
> > Question 1:
> >
> > Given that the user of the API can choose to override foo() or not, how
> > can I control the signature that they use?
>  While technically possible (using inspect.getargspec), trying to make
>  your code idiot-proof is a lost fight and a pure waste of time.
> >>>
> >>> Worse: it's actually counter-productive!
> >>>
> >>> The whole idea of being able to subclass a class means that the user 
> >>> should be able to override foo() *including* the signature. 
> >> If you see subclassing as subtyping, the signatures should always stay 
> >> fully compatibles.
> >>
> > 
> > Isn't that more what Zope-type interfaces are for than inheritance?
> 
> With dynamically typed languages like Python, you don't need any formal 
> mechanism (zope-like interface or whatever) for subtyping to work - just 
> make sure your two classes have the same public interface and it's ok. 
> So indeed inheritance is first a code-reuse feature.
> 

Makes sense.  As nifty as interfaces seem, there's also something that struck 
me as too club-like about them.  Your suggestion seems much more pythonically 
dynamic and ducky.

> > I'm uncertain here, but I'm not persuaded that changing signature is
> > bad.
> 
> Depends if the subclass is supposed to be a proper subtype (according to 
> LSP) too.

Also makes sense, somewhat, but I'll need to reread the previously linked 
article, because I'm not clear in my mind on what makes a subclass a subtype 
*other than* having a matching signature.

Thanks,
Cliff

- End forwarded message -
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too complex ?!?!?!

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 8:52 AM,  <[EMAIL PROTECTED]> wrote:
>
> On Nov 17, 7:46 am, Brian <[EMAIL PROTECTED]> wrote:
> > Had a unsettling conversation with a CS instructor that
> > teaches at local high schools and the community
> > college. This person is a long-term Linux/C/Python
> > programmer, but he claims that the install, config, and
> > library models for C# have proved to be less
> > problematic than Python. So both his courses (intro,
> > data structs, algorithms) are taught in C#.
> >
> > I am a low-end (3-year) journeyman Pythonista, and I
> > was attracted to the language because of its
> > simplicity. And I have come to enjoy the richness of
> > available libraries.
> >
> > Many of the good people of this NG may be 'too close'
> > to answer, but has Python, as a general devel platform,
> > lost its simplicity ? Is library install too complex
> > and unreliable ? Will my dog go to heaven ?
>
> If this professor was only using Windows for his environment, then I
> might be able to understand his argument better. There are many more
> external modules for Python that don't have Windows installers than
> there are with binaries. And I've had more than my fair share of
> broken setup.py files.
>
> On the other hand, if all that is needed are the standard libraries,
> than it's a breeze to install Python since they're all included.
>
> Mike
>

These modules exist, but aren't that common. Certainly anything you're
likely to be using in an introductory compsci course is well packaged.
And even if it's not, it's really not that hard to create packages or
installers - a days work of course prep would take care of the
potential problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Boris Borcic
davenet wrote:
> Hi,
> 
> I'm new to Python and working on a school assignment.
> 
> I have setup a dictionary where the keys point to an object. Each
> object has two member variables. I need to find the smallest value
> contained in this group of objects.
> 
> The objects are defined as follows:
> 
> class Block:
>def __init__(self,addr):
>   self.addr = addr
>   self.age = 0
> 
> My dictionary is defined as:
>blocks = {}
> 
> I have added 1000 (will hold more after I get this working) objects. I
> need to find the lowest age in the dictionary. If there is more than
> one age that is lowest (like if several of them are '1', etc), then I
> can just pick randomly any that equal the lowest value.

 >>> help(min)
Help on built-in function min in module __builtin__:

min(...)
 min(iterable[, key=func]) -> value
 min(a, b, c, ...[, key=func]) -> value

 With a single iterable argument, return its smallest item.
 With two or more arguments, return the smallest argument.

 >>> def f(x) : return 3*x**2+10*x-4

 >>> min(f(x) for x in range(-100,100))
-12
 >>> min(range(-100,100), key=f)
-2
 >>> f(-2)
-12

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


Is python.org blocking traffic from the ibm.com domain?

2007-11-19 Thread scott . h . snyder
Hello all,

I work at IBM and was discussing with a fellow developer how to access
packages from the cheeseshop that might be useful for a project he is
working on.
He found that he could not connect to the cheeseshop
(chesseshop.python.org) from inside IBM but could connect from home.
I confirmed that this was true for me as well and tried other sites
within python.org such as wiki.python.org and www.python.org/pypi and
found that while requests get sent from inside IBM they never get a
reply from the server.

The main site www.python.org seems to work fine www.python.org
[82.94.237.218] but requests going to ximinez.python.org
[82.94.237.219] do not get replies.

IBM internal network security confirms that they are not blocking
access to these sites, so we are guessing that the websites themselves
are choosing not to respond, perhaps thinking that the volume of
traffic from the ibm.com domain is spam or DOS attack.

Can someone responsible for maintaining the website please check what
is happening and help me (and the rest of the IBM community) get back
into the python website ?

Thanks for your attention and if there is anything that we (IBM) needs
to do to help resolve this issue please let me know.

Thanks,

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


Re: how can i return a image in mod python ?

2007-11-19 Thread Arnaud Delobelle
On Nov 19, 10:27 am, Abandoned <[EMAIL PROTECTED]> wrote:
[...]
> Thank you but i have a another problem.
>
> def showimage(req):
> from PIL import Image
> im=Image.open("c:\image-2.jpg")
> im.thumbnail((800,600), Image.ANTIALIAS)
> req.sendfile(im)
>
> give me some error.
> How can i return this image witdhout save ?

You can use the cStringIO module (http://docs.python.org/lib/module-
cStringIO.html).

HTH

--
Arnaud

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



Efficient (HUGE) prime modulus

2007-11-19 Thread blaine
Hey guys,
  For my Network Security class we are designing a project that will,
among other things, implement a Diffie Hellman secret key exchange.
The rest of the class is doing Java, while myself and a classmate are
using Python (as proof of concept).  I am having problems though with
crunching huge numbers required for calculations.  As an alternative I
can use Java - but I'd rather have a pure python implementation.  The
problem is that Python takes a very long time (I haven't had it finish
yet) - but Java does it in 3 seconds.  Suggestions?


P and G are given to us. P represents a huge prime, G is the base, a
is my secret (random) long integer.  I want to compute: (G^A)%P
Python Code:
G =
long(2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603)
P =
long(7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647)

a = self.rand_long(1) # 512 bit long integer

A = (G ** a) % P # G^a mod P

## END #
The above code takes a very long time.  If I make little a only 16
bits instead of 512, it takes about 12 seconds on my machine to
compute. Is this incorrect usage of **?  I used math.pow and built-in
pow.  The math.pow complained about converting a long to a float.  The
built in pow() took a very long time as well.

The following Java code gives me a result in 2 seconds or so.

import java.math.*;

class cruncher {
// Simple class for crunching a secret key!
public static void main(String[] args) {
BigInteger p, g, a, B, out;
out = null;
a = new BigInteger(args[1]);

// To make sure the compiler doesn't complain:
if (a == null) {
System.out.println("You must specify little a");
System.exit(1);
}
g = new
BigInteger("2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603");
p = new
BigInteger("7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647");

// We now have a, g, and p.  Now, depending on what pass we are 
on,
// we will compute the appropriate output
System.out.println("Generating Secret Key(A)");
out = g.modPow(a, p);

System.out.println(out);
}
}

Any suggestions? Right now my solution is to just pipe the output from
my java program since I only need to crunch the numbers one time.  Is
there a python implementation of java's Modpow?

thanks,
Blaine
University of Cincinnati
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: securing a python execution environment...

2007-11-19 Thread Chris Withers
Paul Boddie wrote:
> http://wiki.python.org/moin/SandboxedPython
> http://wiki.python.org/moin/How_can_I_run_an_untrusted_Python_script_safely_%28i%2ee%2e_Sandbox%29

Yeah, from this I'm pretty much set on:

http://pypi.python.org/pypi/RestrictedPython/

I know it's pretty bulletproof (I've been using it inderectly for 
years!) but I do worry that it may be a little slow.

I guess some poking will tell...

If anyone's interested, I'll be continuing this discussion here:

http://mail.zope.org/pipermail/zope-dev/2007-November/030368.html

(this list is a little too high colume for me :-S)

cheers,

Chris

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Paul Rubin
blaine <[EMAIL PROTECTED]> writes:
> A = (G ** a) % P # G^a mod P

Think of how large the intermediate result G**a will be.  That should
explain why it's taking so long.  So figure out what Java's modPow
function must be doing, and write something similar.  Or, see the
docs for python's built-in pow function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too complex ?!?!?!

2007-11-19 Thread kyosohma
On Nov 19, 9:57 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On Nov 19, 2007 8:52 AM,  <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Nov 17, 7:46 am, Brian <[EMAIL PROTECTED]> wrote:
> > > Had a unsettling conversation with a CS instructor that
> > > teaches at local high schools and the community
> > > college. This person is a long-term Linux/C/Python
> > > programmer, but he claims that the install, config, and
> > > library models for C# have proved to be less
> > > problematic than Python. So both his courses (intro,
> > > data structs, algorithms) are taught in C#.
>
> > > I am a low-end (3-year) journeyman Pythonista, and I
> > > was attracted to the language because of its
> > > simplicity. And I have come to enjoy the richness of
> > > available libraries.
>
> > > Many of the good people of this NG may be 'too close'
> > > to answer, but has Python, as a general devel platform,
> > > lost its simplicity ? Is library install too complex
> > > and unreliable ? Will my dog go to heaven ?
>
> > If this professor was only using Windows for his environment, then I
> > might be able to understand his argument better. There are many more
> > external modules for Python that don't have Windows installers than
> > there are with binaries. And I've had more than my fair share of
> > broken setup.py files.
>
> > On the other hand, if all that is needed are the standard libraries,
> > than it's a breeze to install Python since they're all included.
>
> > Mike
>
> These modules exist, but aren't that common. Certainly anything you're
> likely to be using in an introductory compsci course is well packaged.
> And even if it's not, it's really not that hard to create packages or
> installers - a days work of course prep would take care of the
> potential problem.

I stand corrected. Thanks for the clarification.

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 10:32 AM, blaine <[EMAIL PROTECTED]> wrote:
> Hey guys,
>   For my Network Security class we are designing a project that will,
> among other things, implement a Diffie Hellman secret key exchange.
> The rest of the class is doing Java, while myself and a classmate are
> using Python (as proof of concept).  I am having problems though with
> crunching huge numbers required for calculations.  As an alternative I
> can use Java - but I'd rather have a pure python implementation.  The
> problem is that Python takes a very long time (I haven't had it finish
> yet) - but Java does it in 3 seconds.  Suggestions?
>

Python is quite slow for pure number crunching. Most people use the
numeric/numpy modules and/or psyco to speed up math.

Python + psyco approaches Java for the simple integer operations I've tested.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Steven Bethard
Boris Borcic wrote:
> davenet wrote:
>> Hi,
>>
>> I'm new to Python and working on a school assignment.
>>
>> I have setup a dictionary where the keys point to an object. Each
>> object has two member variables. I need to find the smallest value
>> contained in this group of objects.
>>
>> The objects are defined as follows:
>>
>> class Block:
>>def __init__(self,addr):
>>   self.addr = addr
>>   self.age = 0
>>
>> My dictionary is defined as:
>>blocks = {}
>>
>> I have added 1000 (will hold more after I get this working) objects. I
>> need to find the lowest age in the dictionary. If there is more than
>> one age that is lowest (like if several of them are '1', etc), then I
>> can just pick randomly any that equal the lowest value.
> 
>  >>> help(min)
> Help on built-in function min in module __builtin__:
> 
> min(...)
> min(iterable[, key=func]) -> value
> min(a, b, c, ...[, key=func]) -> value
> 
> With a single iterable argument, return its smallest item.
> With two or more arguments, return the smallest argument.
> 
>  >>> def f(x) : return 3*x**2+10*x-4
> 
>  >>> min(f(x) for x in range(-100,100))
> -12
>  >>> min(range(-100,100), key=f)
> -2
>  >>> f(-2)
> -12

I'd like to second this one just so it doesn't get lost among all the 
other responses.  You definitely want to look into the key= argument of 
min(). Your key function should look something like::

 def key(block):
 # return whatever attribute of block you care about

Then just modify this code::

 lowest = min(self.blocks.values())

to use the key= argument as well.  I don't think you need the list 
comprehension at all.

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Peter Otten
blaine wrote:

> A = (G ** a) % P # G^a mod P
> 
> ## END #
> The above code takes a very long time.  If I make little a only 16 bits
> instead of 512, it takes about 12 seconds on my machine to compute. Is
> this incorrect usage of **?  I used math.pow and built-in pow.  The
> math.pow complained about converting a long to a float.  The built in
> pow() took a very long time as well.

Even in its three-argument form?

"""
pow(...)
pow(x, y[, z]) -> number

With two arguments, equivalent to x**y.  With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for longs).
"""

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Steven Bethard
blaine wrote:
> Hey guys,
>   For my Network Security class we are designing a project that will,
> among other things, implement a Diffie Hellman secret key exchange.
> The rest of the class is doing Java, while myself and a classmate are
> using Python (as proof of concept).  I am having problems though with
> crunching huge numbers required for calculations.  As an alternative I
> can use Java - but I'd rather have a pure python implementation.  The
> problem is that Python takes a very long time (I haven't had it finish
> yet) - but Java does it in 3 seconds.  Suggestions?
> 
> 
> P and G are given to us. P represents a huge prime, G is the base, a
> is my secret (random) long integer.  I want to compute: (G^A)%P
> Python Code:
> G =
> long(2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603)
> P =
> long(7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647)
> 
> a = self.rand_long(1) # 512 bit long integer
> 
> A = (G ** a) % P # G^a mod P
> 
> ## END #
> The above code takes a very long time.

This executed almost instantaneously for me::

 >>> G = 
2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603
 >>> P 
=7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647
 >>> import random
 >>> a = random.getrandbits(512)
 >>> pow(G, a, P)
3277959392711594879221835927460692821823492945539627585936047598704303395627109292402670858323756252130899047733532207100944120599118796083912771339930412L

Did I run your algorithm wrong? Note the three argument form of pow::

 >>> help(pow)
Help on built-in function pow in module __builtin__:

pow(...)
 pow(x, y[, z]) -> number

 With two arguments, equivalent to x**y.  With three arguments,
 equivalent to (x**y) % z, but may be more efficient (e.g. for
 longs).

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Paul McGuire
On Nov 19, 10:32 am, blaine <[EMAIL PROTECTED]> wrote:
> Hey guys,
>   For my Network Security class we are designing a project that will,
> among other things, implement a Diffie Hellman secret key exchange.
> The rest of the class is doing Java, while myself and a classmate are
> using Python (as proof of concept).  I am having problems though with
> crunching huge numbers required for calculations.  As an alternative I
> can use Java - but I'd rather have a pure python implementation.  The
> problem is that Python takes a very long time (I haven't had it finish
> yet) - but Java does it in 3 seconds.  Suggestions?

Did you try the 3-argument version of the built-in pow?

A = pow(G,a,P)


Takes about .1 second on my machine, with your values. (I didn't
verify that the answer I got was correct, though.)

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


Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Hrvoje Niksic
blaine <[EMAIL PROTECTED]> writes:

> Python Code:
> G =
> long(2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603)
> P =
> long(7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647)
>
> a = self.rand_long(1) # 512 bit long integer
>
> A = (G ** a) % P # G^a mod P
[...]
> I used math.pow and built-in pow. [...]  Is there a python
> implementation of java's Modpow?

Have you read the documentation of the built-in pow?  It has exactly
the functionality you need:

>>> A = pow(G, a, P)
... executes in several milliseconda ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging.SocketHandler connections

2007-11-19 Thread Vinay Sajip
On Nov 19, 10:27 am, oj <[EMAIL PROTECTED]> wrote:
> On Nov 16, 2:31 pm, Vinay Sajip <[EMAIL PROTECTED]> wrote:
>
> Here is the server code. Pretty much directly copied from the example,
> aside from not having the the handler loop forever, and queing the
> records instead of dealing with the directly.
>
> After further investigation, running the client with a long timeout,
> without the server, so that every connection will fail, produces
> results much closer to what I would expect. Connections attempted for
> each message initially, but not for all of the later messages as the
> retry time increases.
>
> The point is kinda moot now, since I guess not closing the connection
> is the 'right way' to do this, but I'm still interested in why I see
> this behaviour when the server closes the connection.
>

I've investigated this and the issue appears not to be related to
closing connections. Your server code differs from the example in the
docs in one crucial way: there is a while loop which you have left out
in the handle() function, which deals with multiple logging events
received in one packet. Add this back in, and all 9 events are
received.

def handle(self):
while 1:
chunk = self.connection.recv(4)

if len(chunk) < 4:
break

slen = struct.unpack(">L", chunk)[0]
chunk = self.connection.recv(slen)

while len(chunk) < slen:
chunk = chunk + self.connection.recv(slen -
len(chunk))

obj = self.unPickle(chunk)
record = logging.makeLogRecord(obj)
queue_lock.acquire()
queue.insert(0, record)
queue_lock.release()

So it appears that due to buffering, 3 socket events are sent in each
packet sent over the wire. You were only processing the first of each
set of three, viz. nos. 0, 3, 6 and 9. Mystery solved, it appears!

Regards,


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


Re: regular expression

2007-11-19 Thread Paul McGuire
Sorry about your coffee cup!  Would you be interested in a pyparsing
rendition?

-- Paul


from pyparsing import *

def defineGrammar():
ParserElement.setDefaultWhitespaceChars(" \t")

ident = Word(alphanums+"_")
LT,GT = map(Suppress,"<>")
NL = LineEnd().suppress()

real = Word(nums,nums+".")
integer = Word(nums)
quotedString = QuotedString('"')

dataValue = real | integer | Word(alphas,alphanums) | quotedString
dataDef = ident + ZeroOrMore(dataValue) + NL
tagDef = Forward()
tagDef << LT + ident + ZeroOrMore(dataValue) + NL + \
Dict(ZeroOrMore(Group(dataDef) | Group(tagDef))) + GT + NL
tagData = Dict(OneOrMore(Group(tagDef)))
return tagData

results = defineGrammar().parseString(TESTTXT)
print( results.dump() )
print results.REAPER_PROJECT.TRACK.keys()
print results.REAPER_PROJECT.TRACK.PANENV2
print results.REAPER_PROJECT.TRACK.PANENV2.ACT


prints out:

[['REAPER_PROJECT', '0.1', ['METRONOME', '6', '2.00', ['SAMPLES',
'', '']], ['TRACK', ['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']],
['PANENV2', ['ACT', '1']
- REAPER_PROJECT: ['0.1', ['METRONOME', '6', '2.00', ['SAMPLES',
'', '']], ['TRACK', ['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']],
['PANENV2', ['ACT', '1'
  - METRONOME: ['6', '2.00', ['SAMPLES', '', '']]
- SAMPLES: ['', '']
  - TRACK: [['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']], ['PANENV2',
['ACT', '1']]]
- MAINSEND: 1
- PANENV2: [['ACT', '1']]
  - ACT: 1
- VOLENV2: [['ACT', '1']]
  - ACT: 1
['PANENV2', 'MAINSEND', 'VOLENV2']
[['ACT', '1']]
1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too complex ?!?!?!

2007-11-19 Thread Diez B. Roggisch
alain schrieb:
> On Nov 19, 9:44 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
>> On 17 Nov., 14:46, Brian <[EMAIL PROTECTED]> wrote:
>>
>>> Had a unsettling conversation with a CS instructor that
>>> teaches at local high schools and the community
>>> college. This person is a long-term Linux/C/Python
>>> programmer, but he claims that the install, config, and
>>> library models for C# have proved to be less
>>> problematic than Python. So both his courses (intro,
>>> data structs, algorithms) are taught in C#.
>> I don't understand this complaint. How does your instructor installs
>> libraries for C#? When he uses Linux for teaching purposes I assume
>> his students have little problems typing some shell commands and when
>> he uses Windows his students might feel comfortable double clicking on
>> a Windows installer - most likely containing prepackaged binaries.
>> What have I missed?
>>
>> Kay
> 
> I think i understand his complaint.
> Have you ever tried to install a package making use of easy_install?
> If you have, then you understand this is a real pain in the ass,
> especially if your internet access requires proxy authentication.
> The world was easy before easy_install !

setuptools might not be flawless, but it works for me most of the times 
- and always better than pure distutils.

BTW, you can download eggs and install them from files - so while 
teaching easy_install how to deal with proxies (are these still used by 
anyone - I thought that was in the 90ties... ) certainly would be good, 
it isn't necessary.

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


Re: embed ipython in wxPython app

2007-11-19 Thread chewie54
On Nov 18, 8:39 pm, chewie54 <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm evaluting IPython to see if I can it use like Tcl and Tk. If I
> start wish8.4,  I get a command line
> interpreter in xterm,  then I can source tcl progams that draw tk
> graphics on a canvas in another window.
>
> Is there a way to embed IPython in a wxPython app to do that?
> When I do as shown in the example below the GUI window does not show
> until I exit IPython.
>
> Thanks in advance for any help with this,
>
> import wx
> from IPython.Shell import IPShellEmbed
>
> class MyFrame(wx.Frame):
> def __init__(self,parent=None, id=-1, title=' '):
> wx.Frame.__init__(self,parent,id,title,size=(200,140))
> top = wx.Panel(self)
> sizer = wx.BoxSizer(wx.VERTICAL)
> lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> max,dozen)')
> sizer.Add(lb)
>
> top.SetSizer(sizer)
> self.Layout()
>
> class MyApp(wx.App):
> def OnInit(self):
> frame = MyFrame(title="wxWidgets")
> frame.Show(True)
> self.SetTopWindow(frame)
> return True
>
> def main():
> ipshell = IPShellEmbed()
> ipshell()
> app = MyApp()
> app.MainLoop()
>
> if __name__ == '__main__':
> main()

I forgot to mention.

I did see an example of embedding IPython in a PyGTK app on
http://ipython.scipy.org/moin/Cookbook

It would be nice to see an example that shows how to embed
IPython in a wxPython or Tkinter GUI app.

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


Is it possible to use sockets to login to a website that uses php?

2007-11-19 Thread Lamonte Harris
I need to some how make a script that logs into a website from my desktop
and I can do the rest and grab the information on my on hopefully.  How
would I login to a website using sockets with python?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: embed ipython in wxPython app

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 11:51 AM, chewie54 <[EMAIL PROTECTED]> wrote:
>
> On Nov 18, 8:39 pm, chewie54 <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > I'm evaluting IPython to see if I can it use like Tcl and Tk. If I
> > start wish8.4,  I get a command line
> > interpreter in xterm,  then I can source tcl progams that draw tk
> > graphics on a canvas in another window.
> >
> > Is there a way to embed IPython in a wxPython app to do that?
> > When I do as shown in the example below the GUI window does not show
> > until I exit IPython.
> >
> > Thanks in advance for any help with this,
> >
> > import wx
> > from IPython.Shell import IPShellEmbed
> >
> > class MyFrame(wx.Frame):
> > def __init__(self,parent=None, id=-1, title=' '):
> > wx.Frame.__init__(self,parent,id,title,size=(200,140))
> > top = wx.Panel(self)
> > sizer = wx.BoxSizer(wx.VERTICAL)
> > lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> > max,dozen)')
> > sizer.Add(lb)
> >
> > top.SetSizer(sizer)
> > self.Layout()
> >
> > class MyApp(wx.App):
> > def OnInit(self):
> > frame = MyFrame(title="wxWidgets")
> > frame.Show(True)
> > self.SetTopWindow(frame)
> > return True
> >
> > def main():
> > ipshell = IPShellEmbed()
> > ipshell()
> > app = MyApp()
> > app.MainLoop()
> >
> > if __name__ == '__main__':
> > main()
>
> I forgot to mention.
>
> I did see an example of embedding IPython in a PyGTK app on
> http://ipython.scipy.org/moin/Cookbook
>
> It would be nice to see an example that shows how to embed
> IPython in a wxPython or Tkinter GUI app.
>


IPython has a custom event loop. You'll need to look at it's sources
and figure out how to drive it externally. There's some plugins for
IPython that may help (or may even work out of the box), they're used
to let you run wx or gtk or other libraries that have their own event
loop within IPython.

Are you aware that wx already has a Python shell implementation? It's
different than IPython, of course, but it has graphical inspection of
objects which is the main reason people tend to use IPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: insert comments into elementtree

2007-11-19 Thread Tim Arnold
"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Tim Arnold wrote:
>> Hi, I'm using the TidyHTMLTreeBuilder to generate some elementtrees from
>> html. One by-product is that I'm losing comments embedded in the html.
>
> That's how the parser in ET works. Use lxml instead, which keeps documents
> intact while parsing.
>
> http://codespeak.net/lxml/dev/
> http://codespeak.net/lxml/dev/lxmlhtml.html
>
> Stefan

Thanks Stefan, I certainly would use lxml if I could get everything to 
compile on this HPux10.20.
I did manage to get this one solved by inserting the comments back in like 
this:
elem.insert(0,ET.Comment('stopindex'))

thanks,
--Tim Arnold


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


Efficient: put Content of HTML file into mysql database

2007-11-19 Thread Fabian López
Hi colegues,
do you know the most efficient way to put the content of an html file into a
mySQL database?Could it be this one?:
1.- I have the html document in my hard disk.
2.- Then I Open the file (maybe with fopen??)
3.- Read the content (fread or similar)
4.- Write all the content it in a SQL sentence.

What happens if the html file is very big?


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

Re: embed ipython in wxPython app

2007-11-19 Thread chewie54
On Nov 19, 1:07 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On Nov 19, 2007 11:51 AM, chewie54 <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Nov 18, 8:39 pm, chewie54 <[EMAIL PROTECTED]> wrote:
> > > Hi All,
>
> > > I'm evaluting IPython to see if I can it use like Tcl and Tk. If I
> > > start wish8.4,  I get a command line
> > > interpreter in xterm,  then I can source tcl progams that draw tk
> > > graphics on a canvas in another window.
>
> > > Is there a way to embed IPython in a wxPython app to do that?
> > > When I do as shown in the example below the GUI window does not show
> > > until I exit IPython.
>
> > > Thanks in advance for any help with this,
>
> > > import wx
> > > from IPython.Shell import IPShellEmbed
>
> > > class MyFrame(wx.Frame):
> > > def __init__(self,parent=None, id=-1, title=' '):
> > > wx.Frame.__init__(self,parent,id,title,size=(200,140))
> > > top = wx.Panel(self)
> > > sizer = wx.BoxSizer(wx.VERTICAL)
> > > lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> > > max,dozen)')
> > > sizer.Add(lb)
>
> > > top.SetSizer(sizer)
> > > self.Layout()
>
> > > class MyApp(wx.App):
> > > def OnInit(self):
> > > frame = MyFrame(title="wxWidgets")
> > > frame.Show(True)
> > > self.SetTopWindow(frame)
> > > return True
>
> > > def main():
> > > ipshell = IPShellEmbed()
> > > ipshell()
> > > app = MyApp()
> > > app.MainLoop()
>
> > > if __name__ == '__main__':
> > > main()
>
> > I forgot to mention.
>
> > I did see an example of embedding IPython in a PyGTK app on
> >http://ipython.scipy.org/moin/Cookbook
>
> > It would be nice to see an example that shows how to embed
> > IPython in a wxPython or Tkinter GUI app.
>
> IPython has a custom event loop. You'll need to look at it's sources
> and figure out how to drive it externally. There's some plugins for
> IPython that may help (or may even work out of the box), they're used
> to let you run wx or gtk or other libraries that have their own event
> loop within IPython.
>
> Are you aware that wx already has a Python shell implementation? It's
> different than IPython, of course, but it has graphical inspection of
> objects which is the main reason people tend to use IPython.

Yes,  I have seen the wxPython demo and PyShell example but was
looking
to use IPython since the user can navigate directories like other
unix
shells.

What are these plugins you mentioned?

Thanks,


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


Re: Sorting Countries by Region

2007-11-19 Thread martyw
nothing, Alan wrote:
> On Nov 16, 8:28 pm, martyw <[EMAIL PROTECTED]> wrote:
>> i would create a class to capture country information, e.g.
> 
> 
> What is the advantage of this:
> 
>>  def __cmp__(self, other):
>>  if self.name < other.name:
>>  return -1
>>  elif self.name > other.name:
>>  return 1
>>  else:
>>  return 0
>>
> 
> over
> def __cmp__(self,other):
> return cmp(self.name,other.name)
> 
> ?
> 
> --
> Alan
yours is better!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embed ipython in wxPython app

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 12:21 PM, chewie54 <[EMAIL PROTECTED]> wrote:
> On Nov 19, 1:07 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
> > On Nov 19, 2007 11:51 AM, chewie54 <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> > > On Nov 18, 8:39 pm, chewie54 <[EMAIL PROTECTED]> wrote:
> > > > Hi All,
> >
> > > > I'm evaluting IPython to see if I can it use like Tcl and Tk. If I
> > > > start wish8.4,  I get a command line
> > > > interpreter in xterm,  then I can source tcl progams that draw tk
> > > > graphics on a canvas in another window.
> >
> > > > Is there a way to embed IPython in a wxPython app to do that?
> > > > When I do as shown in the example below the GUI window does not show
> > > > until I exit IPython.
> >
> > > > Thanks in advance for any help with this,
> >
> > > > import wx
> > > > from IPython.Shell import IPShellEmbed
> >
> > > > class MyFrame(wx.Frame):
> > > > def __init__(self,parent=None, id=-1, title=' '):
> > > > wx.Frame.__init__(self,parent,id,title,size=(200,140))
> > > > top = wx.Panel(self)
> > > > sizer = wx.BoxSizer(wx.VERTICAL)
> > > > lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> > > > max,dozen)')
> > > > sizer.Add(lb)
> >
> > > > top.SetSizer(sizer)
> > > > self.Layout()
> >
> > > > class MyApp(wx.App):
> > > > def OnInit(self):
> > > > frame = MyFrame(title="wxWidgets")
> > > > frame.Show(True)
> > > > self.SetTopWindow(frame)
> > > > return True
> >
> > > > def main():
> > > > ipshell = IPShellEmbed()
> > > > ipshell()
> > > > app = MyApp()
> > > > app.MainLoop()
> >
> > > > if __name__ == '__main__':
> > > > main()
> >
> > > I forgot to mention.
> >
> > > I did see an example of embedding IPython in a PyGTK app on
> > >http://ipython.scipy.org/moin/Cookbook
> >
> > > It would be nice to see an example that shows how to embed
> > > IPython in a wxPython or Tkinter GUI app.
> >
> > IPython has a custom event loop. You'll need to look at it's sources
> > and figure out how to drive it externally. There's some plugins for
> > IPython that may help (or may even work out of the box), they're used
> > to let you run wx or gtk or other libraries that have their own event
> > loop within IPython.
> >
> > Are you aware that wx already has a Python shell implementation? It's
> > different than IPython, of course, but it has graphical inspection of
> > objects which is the main reason people tend to use IPython.
>
> Yes,  I have seen the wxPython demo and PyShell example but was
> looking
> to use IPython since the user can navigate directories like other
> unix
> shells.
>
> What are these plugins you mentioned?
>

http://ipython.scipy.org/moin/Cookbook/InterruptingThreads

I'm not sure how these work (the wiki page implies they just run the
external event loop in a thread, so they're not suitable for embedding
IPython in such a tool kit). I'm sure there's a way to pump IPython
though (there must be, since it's embeddable in gtk) so that's where
you'll want to look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient: put Content of HTML file into mysql database

2007-11-19 Thread Jesse Jaggars
Fabian López wrote:
> Hi colegues,
> do you know the most efficient way to put the content of an html file 
> into a mySQL database?Could it be this one?:
> 1.- I have the html document in my hard disk.
> 2.- Then I Open the file (maybe with fopen??)
> 3.- Read the content (fread or similar)
> 4.- Write all the content it in a SQL sentence.
>
> What happens if the html file is very big?
>
>
> Thanks!
> FAbian
>
>
I don't understand why you would want to store an entire static html 
page in the database. All that accomplishes is adding the overhead of 
calling MySQL too.

If you want to serve HTML do just let your webserver serve HTML.

Is there more to the situation that would help myself and others 
understand why you want to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


display messages in python shell

2007-11-19 Thread koutoo
Is it possible to display messages in the python shell?  I want to
display error messages based on parameters in my scripts to the
users.  Is there another way to display messages other than log
files?  Thanks.

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


Re: pydoc - how to generate documentation for an entire package?

2007-11-19 Thread Jens
On 8 Nov., 02:46, Jens <[EMAIL PROTECTED]> wrote:
> I have a project/package for which I want to generate documentation
> usingpydoc.
>
> My problem is that when I type "pydoc.py -w MyPackage" it only
> generates documentation for the package - no modules, classes or
> methods or sub-packages. Just a single HTML file called
> "MyPackage.html"
>
> That's strange - is there something here I'm missing. How do you
> generate documentation for a whole package?

No suggestions? All I can think of is to make a *.bat file on Windows
to call pydoc.py for each of my modules. Seems like a silly solution.

Also, when I have a module that imports from math (for example),
pydoc.py generates a broken link to the math module. This just seems
very silly.

Generating documentation form code is a nice thing, but this pydoc.py
is driving me insane - isn't there are better way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: display messages in python shell

2007-11-19 Thread Jens
On 19 Nov., 19:48, [EMAIL PROTECTED] wrote:
> Is it possible to display messages in the python shell?  I want to
> display error messages based on parameters in my scripts to the
> users.  Is there another way to display messages other than log
> files?  Thanks.
>
> Kou

What about using print? For example:

print "This is a message."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too complex ?!?!?!

2007-11-19 Thread Aaron Watters
On Nov 19, 3:44 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 17 Nov., 14:46, Brian <[EMAIL PROTECTED]> wrote:
> What have I missed?

Microsoft has a free download version of Visual Studio
which you can install in one go that has basically everything
you might want to cover in the first 2 or 3 programming
classes built in.  Also, when it comes to making things easy
the magic "intellisense" in VS cannot be beat, and stricter
typing rules tend to keep'em out of trouble.  I've seen
moderately skilled programmers get confused about list.append
versus list.extend -- it wouldn't happen in C#.

I would suggest that Python might be better for
more advanced classes like data structures
because Python cuts out all those declarations that get
in the way of understanding.  For example you could implement
a binary tree in Python in 5 minutes of typing, providing
"just the facts, M'am", whereas even
with intellisense help it would take 15 minutes in C# and
the students would be totally lost in the details when
you were done.

It's also possible that once you break'em in a bit
beginner students would make better progress with more
advanced concepts by making use of the interactive
interpreter.  I've taught java and C# where the students
freeze in abject fear when they confront their first
array -- Python lists are much less intimidating at
the interactive prompt.  At the beginning, however, I would
agree that C# has some serious advantages.  I don't
see anything wrong in teaching a bit of both, tho.

Students also like to learn languages which they can
find in the "help wanted" section very easily ;).

   -- Aaron Watters

===
http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=perverse+zone
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient: put Content of HTML file into mysql database

2007-11-19 Thread Fabian López
Thanks Jesse,
we have a webserver with different domains and I need to crawl different
urls so I decided first to download the file using :
f = urllib.urlretrieve(url,'doc.html')
And after that, I will read the content with all the HTML tags and save it
on our database in order to work with this text.
Is it enough? it is such an easy web crawler. Maybe I can save it without
downloading the file, can I?
Thanks
Fabian

2007/11/19, Jesse Jaggars <[EMAIL PROTECTED]>:
>
> Fabian López wrote:
> > Hi colegues,
> > do you know the most efficient way to put the content of an html file
> > into a mySQL database?Could it be this one?:
> > 1.- I have the html document in my hard disk.
> > 2.- Then I Open the file (maybe with fopen??)
> > 3.- Read the content (fread or similar)
> > 4.- Write all the content it in a SQL sentence.
> >
> > What happens if the html file is very big?
> >
> >
> > Thanks!
> > FAbian
> >
> >
> I don't understand why you would want to store an entire static html
> page in the database. All that accomplishes is adding the overhead of
> calling MySQL too.
>
> If you want to serve HTML do just let your webserver serve HTML.
>
> Is there more to the situation that would help myself and others
> understand why you want to do this?
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: display messages in python shell

2007-11-19 Thread Bruno Desthuilliers
Jens a écrit :
> On 19 Nov., 19:48, [EMAIL PROTECTED] wrote:
> 
>>Is it possible to display messages in the python shell?  I want to
>>display error messages based on parameters in my scripts to the
>>users.  Is there another way to display messages other than log
>>files?  Thanks.
>>
>>Kou
> 
> 
> What about using print? For example:
> 
> print "This is a message."

print writes to stdout - which is for normal program outputs. wrt/ 
errors, you want stderr, ie:

import sys

print >> sys.sdterr, "this is an error message"

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


Re: embed ipython in wxPython app

2007-11-19 Thread chewie54
On Nov 19, 1:44 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On Nov 19, 2007 12:21 PM, chewie54 <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Nov 19, 1:07 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
> > > On Nov 19, 2007 11:51 AM, chewie54 <[EMAIL PROTECTED]> wrote:
>
> > > > On Nov 18, 8:39 pm, chewie54 <[EMAIL PROTECTED]> wrote:
> > > > > Hi All,
>
> > > > > I'm evaluting IPython to see if I can it use like Tcl and Tk. If I
> > > > > start wish8.4,  I get a command line
> > > > > interpreter in xterm,  then I can source tcl progams that draw tk
> > > > > graphics on a canvas in another window.
>
> > > > > Is there a way to embed IPython in a wxPython app to do that?
> > > > > When I do as shown in the example below the GUI window does not show
> > > > > until I exit IPython.
>
> > > > > Thanks in advance for any help with this,
>
> > > > > import wx
> > > > > from IPython.Shell import IPShellEmbed
>
> > > > > class MyFrame(wx.Frame):
> > > > > def __init__(self,parent=None, id=-1, title=' '):
> > > > > wx.Frame.__init__(self,parent,id,title,size=(200,140))
> > > > > top = wx.Panel(self)
> > > > > sizer = wx.BoxSizer(wx.VERTICAL)
> > > > > lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> > > > > max,dozen)')
> > > > > sizer.Add(lb)
>
> > > > > top.SetSizer(sizer)
> > > > > self.Layout()
>
> > > > > class MyApp(wx.App):
> > > > > def OnInit(self):
> > > > > frame = MyFrame(title="wxWidgets")
> > > > > frame.Show(True)
> > > > > self.SetTopWindow(frame)
> > > > > return True
>
> > > > > def main():
> > > > > ipshell = IPShellEmbed()
> > > > > ipshell()
> > > > > app = MyApp()
> > > > > app.MainLoop()
>
> > > > > if __name__ == '__main__':
> > > > > main()
>
> > > > I forgot to mention.
>
> > > > I did see an example of embedding IPython in a PyGTK app on
> > > >http://ipython.scipy.org/moin/Cookbook
>
> > > > It would be nice to see an example that shows how to embed
> > > > IPython in a wxPython or Tkinter GUI app.
>
> > > IPython has a custom event loop. You'll need to look at it's sources
> > > and figure out how to drive it externally. There's some plugins for
> > > IPython that may help (or may even work out of the box), they're used
> > > to let you run wx or gtk or other libraries that have their own event
> > > loop within IPython.
>
> > > Are you aware that wx already has a Python shell implementation? It's
> > > different than IPython, of course, but it has graphical inspection of
> > > objects which is the main reason people tend to use IPython.
>
> > Yes,  I have seen the wxPython demo and PyShell example but was
> > looking
> > to use IPython since the user can navigate directories like other
> > unix
> > shells.
>
> > What are these plugins you mentioned?
>
> http://ipython.scipy.org/moin/Cookbook/InterruptingThreads
>
> I'm not sure how these work (the wiki page implies they just run the
> external event loop in a thread, so they're not suitable for embedding
> IPython in such a tool kit). I'm sure there's a way to pump IPython
> though (there must be, since it's embeddable in gtk) so that's where
> you'll want to look.

This was helpful.

ipython -wxthread

run test1_python.py

and the GUI window was displayed and I can see my object definitions.

I'm getting closer,  now I need to imbed ipython -wxthread shell in
the app somehow.


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


Python for embedded devices?

2007-11-19 Thread Malte Forkel
I would like to use Python on a router, an Edimax BR-6104K,  running OpenWrt 
(http://www.openwrt.org). While I probably won't need most of the fancier stuff 
in Python, serial I/O and threads should be supported.

The router is based on the ADM5120P, has 2MB of flash and 16MB of RAM, so the 
version of Python 2.5.1 that is part of OpenWrt is probably a litte to big.

Any suggestions?

Thanks in advance,
Malte

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


Re: Populating a dictionary, fast [SOLVED]

2007-11-19 Thread Francesc Altet
A Wednesday 14 November 2007, Francesc Altet escrigué:
> I think I've got messed on some benchmarks that I've done on that
> subject some time ago, but either my memory is bad or I've made some
> mistake on those experiments.  My apologies.

Just for the record.  I was unable to stop thinking about this, and 
after some investigation, I guess that my rememberings were gathered 
from some benchmarks with code in Pyrex (i.e. pretty near to C speed).

In the attached benchmark, I compare the speed of dictionary lookups in 
a big dictionary (more than 8 millions of entries) against doing the 
same, but using a binary search approach.  Here are the results:

$ python2.5 gq-binary-search.py
Creating the dictionary...
Time for dict creation: 13.001
Calibrating loop...
Calibrating time: 3.095
Timing queries with a dict...
Time for dict query: 7.747
Timing queries with binary search...
Time for binary queries: 3.551

so, a dictionary lookup takes around 950 ns, while a binary search 
lookup takes around 380 ns, i.e. binary searches are more than 2x 
faster than dictionary lookups, at least in this benchmark.

It might well be that the difference is due to the fact that the binary 
lookup in this case is made for only 64-bit integers, while the 
dictionary code has to check the type of index data first.  OTOH, it is 
also apparent that the binary code can be optimized for cache misses by 
using two levels of indirection for binary lookups, but this is too 
much work for today ;).  At any rate, it seems rather clear that binary 
lookups can be competive against hashes, when using Pyrex at least!

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"


gq-binary-search.py
Description: application/python


setup.py
Description: application/python
# BinarySearch class to demonstrate that binary search is competitive
# against dictionaries based on hashes

# In order to access the data area in NumPy objects
cdef extern from "numpy/arrayobject.h":

  ctypedef extern class numpy.ndarray [object PyArrayObject]:
cdef char *data

  void import_array()

import_array()


cdef long bisect_left(long long *a, long long x, long hi):
cdef long lo, mid

lo = 0
if x <= a[0]: return 0
if a[-1] < x: return hi
while lo < hi:
mid = (lo+hi)/2
if a[mid] < x: lo = mid+1
else: hi = mid
return lo


cdef class BinarySearch:
cdef long len
cdef ndarray str2
cdef long *revidd
cdef long long *sidd

def __new__(self, ndarray sid, ndarray revid, ndarray str2):
self.str2 = str2
self.revidd = revid.data
self.sidd = sid.data
self.len = len(str2) - 1

def __getitem__(self, x):
cdef long pos, idx

pos = bisect_left(self.sidd, x, self.len)
idx = self.revidd[pos]
return self.str2[idx]
-- 
http://mail.python.org/mailman/listinfo/python-list

Some clauses cases BeautifulSoup to choke?

2007-11-19 Thread Frank Stutzman
I've got a simple script that looks like (watch the wrap):
---
import BeautifulSoup,urllib

ifile = urllib.urlopen("http://www.naco.faa.gov/digital_tpp_search.asp?fldId
ent=klax&fld_ident_type=ICAO&ver=0711&bnSubmit=Complete+Search").read()

soup=BeautifulSoup.BeautifulSoup(ifile)
print soup.prettify()


and all I get out of it is garbage.  Other simular urls from the same site
work fine (use http://www.naco.faa.gov/digital_tpp_search.asp?fldId
ent=klax&fld_ident_type=ICAO&ver=0711&bnSubmit=Complete+Search as one example).

I did some poking and proding and it seems that there is something in the 
 clause that is causing the problem.  Heck if I can see what it is.

I'm new to BeautifulSoup (heck, I'm new to python).  If I'm doing something
dumb, you don't need to be gentle.

-- 
Frank Stutzman


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


Re: Some clauses cases BeautifulSoup to choke?

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 1:36 PM, Frank Stutzman <[EMAIL PROTECTED]> wrote:
> I've got a simple script that looks like (watch the wrap):
> ---
> import BeautifulSoup,urllib
>
> ifile = urllib.urlopen("http://www.naco.faa.gov/digital_tpp_search.asp?fldId
> ent=klax&fld_ident_type=ICAO&ver=0711&bnSubmit=Complete+Search").read()
>
> soup=BeautifulSoup.BeautifulSoup(ifile)
> print soup.prettify()
> 
>
> and all I get out of it is garbage.  Other simular urls from the same site
> work fine (use http://www.naco.faa.gov/digital_tpp_search.asp?fldId
> ent=klax&fld_ident_type=ICAO&ver=0711&bnSubmit=Complete+Search as one 
> example).
>
> I did some poking and proding and it seems that there is something in the
>  clause that is causing the problem.  Heck if I can see what it is.
>
> I'm new to BeautifulSoup (heck, I'm new to python).  If I'm doing something
> dumb, you don't need to be gentle.
>

You have the same URL as both your good and bad example.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie Q: sequence membership

2007-11-19 Thread Gabriel Genellina
En Mon, 19 Nov 2007 03:32:12 -0300, saccade <[EMAIL PROTECTED]> escribió:

> So if I am permitted to think of integers as immutable objects with
> predefined labels (i.e. the integers used in the text of the program
> code) that cannot de or re referenced then what a similar treatment of
> characters will look like seams to be an arbitary (a design) decition.
>
> In this vein it seams reasonable to expect 'a'[0] and 'ba'[1] to refer
> to the same object. If one follows the convention used with integers
> (9 and 9 refer to the same object) then 'ab' and 'ab' would be the
> same. An equally reasonable assumption would be that 'ab' and 'ab' are
> two different sequences and so not equal (I do not see the problem
> here).

Note that the fact that integers are immutable means that Python *could*  
share the same integer object any time that integer appears on the  
program. For mutable objects --lists by example-- this is not possible  
because different instances of the "same" list may be changed  
independently.
In the following example, both x and y *could* refer to the same object,  
but they don't:

py> x=1000
py> y=1000
py> x is y
False

In contrast, small integers are shared:

py> x=10
py> y=10
py> x is y
True

So immutability is a *necessary* condition for literals to be shared (in  
the Python object model), but it's not *sufficient*.

-- 
Gabriel Genellina

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


Python-URL! - weekly Python news and links (Nov 19)

2007-11-19 Thread Gabriel Genellina
QOTW:  "I think the need for these 'eventloop unifications' stems from Visual
Basic. VB programmers never learned to use more than one thread, and they are
still struggling to unlearn the bad habits they aquired." - sturlamolden
http://groups.google.com/group/comp.lang.python/msg/41d29242b2a825de

"XML.  Almost as good as plain text for grepping." - Joe Mason


Tips for loading data into MySQL efficiently:

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

A misunderstanding on how Python threads and the GIL
work leads to a good explanation by Chris Mellon:

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

Thoughts about composition / inheritance and when to use them in Python:

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

Comparison: the effort of migrating two web apps to a
new server, Python/Django vs. C#/ASP.net:

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

There appears to be an issue with dictionaries being
extremely slow on 64bits multiprocessor systems only:

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

Python 3000 featured on a futuristic novel ("Halting
State", by Charles Stross):

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



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

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

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

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

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

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

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

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

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

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

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

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

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

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

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented 

Re: Is it possible to use sockets to login to a website that uses php?

2007-11-19 Thread Gabriel Genellina
En Mon, 19 Nov 2007 15:01:16 -0300, Lamonte Harris <[EMAIL PROTECTED]>  
escribió:

> I need to some how make a script that logs into a website from my desktop
> and I can do the rest and grab the information on my on hopefully.  How
> would I login to a website using sockets with python?

See the urllib2 module.

-- 
Gabriel Genellina

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


Re: Python for embedded devices?

2007-11-19 Thread Chris Mellon
On Nov 19, 2007 11:17 AM, Malte Forkel <[EMAIL PROTECTED]> wrote:
> I would like to use Python on a router, an Edimax BR-6104K,  running OpenWrt 
> (http://www.openwrt.org). While I probably won't need most of the fancier 
> stuff in Python, serial I/O and threads should be supported.
>
> The router is based on the ADM5120P, has 2MB of flash and 16MB of RAM, so the 
> version of Python 2.5.1 that is part of OpenWrt is probably a litte to big.
>

You can reduce the size of the Python shared library considerably by
removing builtin modules, especially the built-in cjk codecs (I just
built without them on windows and reduced the size to 1.5 megs, down
from 2.5). That may or not be enough to get the size into useful range
for you.

This device may not really be suitable for Python - with so much more
RAM than flash, it seems that you're supposed to have a tiny kernel
and that most of the ram will be used for runtime data structures,
rather than for executable code. Even a very minimal Python library
will require a fair amount of space for .pyc files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for embedded devices?

2007-11-19 Thread Grant Edwards
On 2007-11-19, Malte Forkel <[EMAIL PROTECTED]> wrote:

> I would like to use Python on a router, an Edimax BR-6104K,
> running OpenWrt (http://www.openwrt.org). While I probably
> won't need most of the fancier stuff in Python, serial I/O and
> threads should be supported.
>
> The router is based on the ADM5120P, has 2MB of flash and 16MB
> of RAM, so the version of Python 2.5.1 that is part of OpenWrt
> is probably a litte to big.

Once upon a time there was a project called "deeply embedded
python" that consisted of a drastically stripped down version
of 1.5.1 that was intended to run on things like old PDAs
running PalmOS.  That project has been dormant for quite a
while, but it's the only thing I know of that might be relevant.

http://www.tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy
http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html

I'm not sure if those two links refer to the a same project
or not...

-- 
Grant Edwards   grante Yow! What a COINCIDENCE!
  at   I'm an authorized "SNOOTS
   visi.comOF THE STARS" dealer!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python application dll

2007-11-19 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> Hi,
> 
> Is there a way to create a .dll from a python program which includes
> the python runtime?
> 
> I'm building a Windows application (C# VisualStudio2005) and I'd like
> to utilize some of the functionality available in a Python module. For
> my users who install my Windows application, I'd prefer that they not
> have to install the entirety of Python on their machines.
> 
> Thanks much,
> D

Turn the Python program into a COM object instead.  Then it can be dispatched 
by 
any programming language and distributed after bundling with py2exe.

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


compiling python 2.5, missing zlib

2007-11-19 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I'm trying to compile Python 2.5 on a RHEL system, using "./
configure;make;make install".  The build seems to go alright, but the
zlib module is missing.

I've tried the following:
1) Download and build the zlib libraries myself
2) Specify '--without-system-zlib' to ./configure

Neither seems to work.  What am I missing here?

Thanks,

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


RE: Anyone knows how to use xemacs with ipython or python on WinXP? [phishing][html-removed]

2007-11-19 Thread Sells, Fred
you did remember to "byte-compile" the python-mode.el file?

> I am struggling to make the ipython or python works in 
> xemacs. I have been seraching on the internet for a solution 
> for one day. I have put python-mode.el and ipython.el in the 
> load-path and in the xemacs I type: M-x load library ipython. 
> Then M-x py-shell. However, I could not get the ipython 
> command window. emacs only creates a python window. If I exit 
> the xemacs, it will say an active process exit, do you want 
> to kill it? It seems the process is running but it could not 
> display the command window.
>  
> My ipython version is 0.8.1 and python-mode version is 4.76.
>  
> Thanks
>  
> Frank
> _
> 10??1?2???
> http://keyword.jp.msn.com/default.aspx
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: newbie Q: sequence membership

2007-11-19 Thread Sells, Fred
> >>> a, b = [], []
> >>> a.append(b)
> >>> b.append(a)
did you perhaps mean a.append('b'); b.append('a'); otherwise this seems pretty 
advanced for a newbie


> >>> b in a
> True
> >>> a in a
> Traceback (most recent call last):
>   File "", line 1, in 
> RuntimeError: maximum recursion depth exceeded in cmp
> >>>
> >>> a is a[0]
> False
> >>> a == a[0]
> Traceback (most recent call last):
>   File "", line 1, in 
> RuntimeError: maximum recursion depth exceeded in cmp
> 
> --
> 
> I'm a little new to this language so my mental model on whats going on
> may need to be refined.
> 
> I expect "a in a" to evaluate to "False". Since it does not it may be
> that while checking equality it uses "==" and not "is". If that is the
> reason then  the question becomes why doesn't "a == a[0]" evaluate to
> "False"? As a side, and if that is the reason, is there a version of
> "in" that uses "is"? "a is in a" does not work.
> 
> Thankx,
> Trivik
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Anyone knows how to use xemacs with ipython or python on WinXP? [phishing][html-removed]

2007-11-19 Thread wang frank

I did not byte-compile the python-mode.el. Does this change anything? I still 
cannot get the ipython commad prompt.
 
Thanks
 
Frank> Subject: RE: Anyone knows how to use xemacs with ipython or python on 
WinXP? [phishing][html-removed]> Date: Mon, 19 Nov 2007 15:57:59 -0500> From: 
[EMAIL PROTECTED]> To: [email protected]> > you did remember to 
"byte-compile" the python-mode.el file?> > > I am struggling to make the 
ipython or python works in > > xemacs. I have been seraching on the internet 
for a solution > > for one day. I have put python-mode.el and ipython.el in the 
> > load-path and in the xemacs I type: M-x load library ipython. > > Then M-x 
py-shell. However, I could not get the ipython > > command window. emacs only 
creates a python window. If I exit > > the xemacs, it will say an active 
process exit, do you want > > to kill it? It seems the process is running but 
it could not > > display the command window.> > > > My ipython version is 0.8.1 
and python-mode version is 4.76.> > > > Thanks> > > > Frank> > 
_> > 10??!
 1?2???> > http://keyword.jp.msn.com/default.aspx> 
> -- > > http://mail.python.org/mailman/listinfo/python-list> > > -- > 
http://mail.python.org/mailman/listinfo/python-list
_
Hotmailがお届けする、幸せになるためのメールマガジン「ビジネス幸福論」実施中
http://go.windowslive.jp/-- 
http://mail.python.org/mailman/listinfo/python-list

weave and compiler install help

2007-11-19 Thread Michael ODonnell
I am trying to compile some inline c++ code inside python using weave.
I always get a similar problem where the compiled file cannot be found
(see below). I am not sure if the problem is with the compiler
or something else. I am a new user of scipy and a novice with python so
I would appreciate any direction someone can give me because I have not
been able to figure out a work around.

PS. I have also posted this on scipy list and have not received any feedback.

Thank you,
Michael

+
I have the following related applications installed:
+
Python:
2.4.1 (I am using an older version because this is what ESRI GIS application 
 supports)
 
Scipy:
scipy-0.6.0.win32-py2.4.exe

MinGW:
MinGW-5.1.3.exe
gcc-4.1.2-mingw-setup.exe

cygwin:
3.2.25

OS:
Windows XP SP2


+
When I test the installation of Weave I get the following output:
+
>>> weave.test()
  Found 1 tests for scipy.weave.ast_tools
  Found 2 tests for scipy.weave.blitz_tools
  Found 9 tests for scipy.weave.build_tools
  Found 0 tests for scipy.weave.c_spec
  Found 26 tests for scipy.weave.catalog
building extensions here: 
c:\docume~1\michael\locals~1\temp\Michael\python24_compiled\m3
  Found 1 tests for scipy.weave.ext_tools
  Found 0 tests
 for scipy.weave.inline_tools
  Found 74 tests for scipy.weave.size_check
  Found 16 tests for scipy.weave.slice_handler
  Found 3 tests for
 scipy.weave.standard_array_spec
  Found 0 tests for __main__
...warning: specified build_dir '_bad_path_' does not exist or is not writable. 
Trying default locations
.warning: specified build_dir '_bad_path_' does not exist or is not 
writable. Trying default locations
removing 
'c:\docume~1\michael\locals~1\temp\tmpdqudhmcat_test' (and everything under it)
error
removing c:\docume~1\michael\locals~1\temp\tmpdqudhmcat_test:
c:\docume~1\michael\locals~1\temp\tmpdqudhmcat_test\win3224compiled_catalog:
Permission denied
error removing
c:\docume~1\michael\locals~1\temp\tmpdqudhmcat_test:
c:\docume~1\michael\locals~1\temp\tmpdqudhmcat_test: Directory not empty
.removing 'c:\docume~1\michael\locals~1\temp\tmpw144aycat_test' (and everything 
under
 it)
...
--
Ran 132 tests in 2.625s

OK



+
When I try to test the following script or any other script I get the following 
message:
+
def prod(m, v):
#C++ version
nrows, ncolumns = m.shape

res = numpy.zeros((nrows, ncolumns), float)
code = r"""
for (int i=0; i
running build_ext
running build_src
building extension "sc_045cfaf40ef1a0738b1066aaa886a55d7" sources
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
building 'sc_045cfaf40ef1a0738b1066aaa886a55d7' extension
compiling C++ sources
C compiler: g++ -mno-cygwin -O2 -Wall

compile
options: '-IC:\Python24\lib\site-packages\scipy\weave
-IC:\Python24\lib\site-packages\scipy\weave\scxx
-IC:\Python24\lib\site-packages\numpy\core\include
-IC:\Python24\include -IC:\Python24\PC -c'
g++
-mno-cygwin -O2 -Wall -IC:\Python24\lib\site-packages\scipy\weave
-IC:\Python24\lib\site-packages\scipy\weave\scxx
-IC:\Python24\lib\site-packages\numpy\core\include
-IC:\Python24\include -IC:\Python24\PC -c
c:\docume~1\michael\locals~1\temp\Michael\python24_compiled\sc_045cfaf40ef1a0738b1066aaa886a55d7.cpp
-o
c:\docume~1\michael\locals~1\temp\Michael\python24_intermediate\compiler_c8350d870e6c54e8f29dd7094c2bfb45\Release\docume~1\michael\locals~1\temp\michael\python24_compiled\sc_045cfaf40ef1a0738b1066aaa886a55d7.o
Traceback (most recent call last):
  File 
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 
310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\Michael\Application
 Data\ESRI\ArcToolbox\scripts\test_weave.py", line 179, in ?
main()
  File "C:\Documents and Settings\Michael\Application 
Data\ESRI\ArcToolbox\scripts\test_weave.py", line 170, in main
prod(m, v)
  File "C:\Documents and Settings\Michael\Application 
Data\ESRI\ArcToolbox\scripts\test_weave.py", line 44, in prod
err = weave.inline(code,['nrows', 'ncolumns', 'res', 'm', 'v'], verbose=2)
  File "C:\Python24\Lib\site-packages\scipy\weave\inline_tools.py", line 338, 
in inline
auto_downcast = auto_downcast,
  File "C:\Python24\Lib\site-packages\scipy\weave\inline_tools.py", line 447, 
in compile_function
verbose=verbose, **kw)
  File "C:\Python24\Lib\site-

getElementsByTagName in ElementTree

2007-11-19 Thread sndive
what's the equivalent of minidom's getElementsByTagName in ElementTree?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling python 2.5, missing zlib

2007-11-19 Thread Martin v. Löwis
> Neither seems to work.  What am I missing here?

You forgot to install the zlib header files, which come in
an RPM provided by Redhat (probably called zlib-dev or some
such).

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


Re: Is python.org blocking traffic from the ibm.com domain?

2007-11-19 Thread Martin v. Löwis
> IBM internal network security confirms that they are not blocking
> access to these sites, so we are guessing that the websites themselves
> are choosing not to respond, perhaps thinking that the volume of
> traffic from the ibm.com domain is spam or DOS attack.
> 
> Can someone responsible for maintaining the website please check what
> is happening and help me (and the rest of the IBM community) get back
> into the python website ?

Please contact me with details of the client machine trying to access
PyPI. We do block selected clients if they are accessing the
site in an excessive manner, but we don't (currently) block entire networks.

It's not normally the fear of Spam or a DOS that causes such blocking,
but just regular overloading, typically from a machine that fails to
honor robots.txt.

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


  1   2   >