[mod_python] problem using regular expressions in CGI scripts

Gregory Trubetskoy grisha at modpython.org
Fri May 19 19:47:06 EST 2000


I'm unable to reproduce this. Tried it as DSO, on Linux and FreeBSD and it
works fine...

Anybody else on the list want to try it?

Grisha


On Thu, 18 May 2000, Ralf Canis wrote:

> On Thu, May 18, 2000 at 09:15:50AM -0400, Gregory Trubetskoy wrote:
> 
> Hi Grisha,
> 
> same errors, here's one for example.
> 
> Ralf
> 
> ---snip---
> \nERROR mod_python: "PythonHandler myhandler"
> 
> Traceback (innermost last):
> 
>   File "/usr/lib/python1.5/site-packages/mod_python/apache.py", line 110, in Dispatch
>     result = object(req)
> 
>   File "./myhandler.py", line 8, in handler
>     re.compile( r'foo(\(.+\))bar' )
> 
>   File "/usr/lib/python1.5/re.py", line 79, in compile
>     code=pcre_compile(pattern, flags, groupindex)
> 
> pcre.error: ('missing )', 2493)
> 
> 
> NOTE: More output from other handlers, if any, may follow.
> This will NOT happen, and request processing will STOP
> at this point when you remove PythonDebug directive.
> ---snip---
> 
> > 
> > Can you try running the same code in your own handler, and see where that
> > takes you, in other words:
> > 
> > httpd.conf:
> > AddHandler python-program .py
> > PythonHandler myhandler
> > PythonDebug
> > 
> > Then the myhandler.py file would have something like
> > 
> > --- snip ---
> > 
> > from mod_python import apache
> > import re, sys
> > 
> > def handler(req):
> > 
> >     req.content_type = 'text/plain'
> >     req.send_http_header()
> >     re.compile( r'foo(\(.+\))bar' )
> >     req.write('ok')
> >     return apache.OK
> > 
> > --- snip ---
> > 
> > 
> > Note that it is not necessary to print out the traceback - mod_python does
> > that for you if PythonDebug directive is specified.
> > 
> > Grisha
> > 
> > 
> > On Thu, 18 May 2000, Ralf Canis wrote:
> > 
> > > On Thu, May 18, 2000 at 02:39:46PM +0300, Erno Kuusela wrote:
> > > 
> > > Hello Erno,
> > > 
> > > > i haven't even installed mod_python yet, but a debugging idea
> > > > came to mind...
> > > > 
> > > > if you compile your regular expressions, they will have a .pattern
> > > > attribute that contains your regexp. it seem to me something
> > > > in mod_python may be munging/interpreting \-escapes, so if
> > > > you print the pattern out and it looks different from the
> > > > one you put in, you might be closer to figuring out what
> > > > is going on..
> > > 
> > > Yes, I thought so, too. Therefor I modified re.py in lib/python1.5
> > > at line 79 (re.compile) to print the pattern right before calling
> > > pcre_compile - it's the pattern I call it with :(
> > > Regarding this, I guess the problem is in prce_compile, but I did
> > > not investigate this further.
> > > 
> -- 
> Ralf Canis            ralf at silicon.org
> Germany               canis at bigfoot.com
> 




More information about the Mod_python mailing list