python regex negative lookahead assertions problems

2009-11-22 Thread Jelle Smet
Hi List,

I'm trying to match lines in python using the re module.
The end goal is to have a regex which enables me to skip lines which have ok 
and warning in it.
But for some reason I can't get negative lookaheads working, the way it's 
explained in http://docs.python.org/library/re.html;.

Consider this example:

Python 2.6.4 (r264:75706, Nov  2 2009, 14:38:03) 
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.
 import re
 line='2009-11-22 12:15:441  lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh 
 qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh 
 qiusdfhq iusfh'
 re.match('.*(?!warning)',line)
_sre.SRE_Match object at 0xb75b1598

I would expect that this would NOT match as it's a negative lookahead and 
warning is in the string.


Thanks,


-- 
Jelle Smet
http://www.smetj.net
-- 
http://mail.python.org/mailman/listinfo/python-list


SimpleXMLRPCServer and creating a new object on for each new client request.

2009-05-06 Thread Jelle Smet
Hi list,

My goals is to have concurrent and separated client sessions using xmlrpc.
Initially my though was that SimpleXMLRPCServer was able to create a new
object instance for each incoming request.
But this doesn't appear to be the case, unless I'm overlooking something,
if so please point me out.

Concider following simplified code


#!/usr/bin/python

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import random

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)

# Create a simple example class
class Randomizer:
def __init__(self):
self.random=random.randrange(0,10)
def show_random(self):
return self.random

# Create server
server = SimpleXMLRPCServer((localhost,
8000),requestHandler=RequestHandler,allow_none=1)
server.register_introspection_functions()

server.register_instance(Randomizer())
server.serve_forever()



I start python interactively:
 import xmlrpclib
 session1=xmlrpclib.ServerProxy('http://localhost:8000')
 session2=xmlrpclib.ServerProxy('http://localhost:8000')
 print session1.show_random()
13930
 print session2.show_random()
13930
 

I though that session1 and session2 would be 2 different Randomizer objects
each having a different result for self.random
But as the example shows this is not the case.
How can I solve this?

Thanks

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