[mod_python] Strange sre module import anomaly

Conrad Steenberg conrad at hep.caltech.edu
Thu Jul 1 10:27:31 EDT 2004


I'm seeing a strange failure to load the sre module (directly or
indirectly from the re module) in a mod_python handler:

Traceback (most recent call last):
  File "/opt/openpkg/lib/python/mod_python/apache.py", line 299, in HandlerDispatch\n    result = object(req)
  File "/opt/openpkg/share/apache2/clarens/clarens_server.py", line 673, in handler\n    return real_handler(req) 
  File "/opt/openpkg/share/apache2/clarens/system/__init__.py", line 1515, in handler\n    retval=exec_method(req,decoded[0],decoded[1],user,pw)
  File "/opt/openpkg/share/apache2/clarens/system/__init__.py", line 1296, in exec_method\n    return method_object(req,method_name,args)
  File "/opt/openpkg/share/apache2/clarens/echo/__init__.py", line 55, in echo\n newResult = myRe.sub(r"='\\1'", myString)
  File "/opt/openpkg/RPM/TMP/python-2.2.3-root/opt/openpkg/lib/python/sre.py", line 96, in ?\n    import sys
ImportError: No module named sys

I.e. for some reason the sre module can't import the sys module. To
reproduce, simply do 'import sre' _before_ importing sys in a handler

The sre module is in the path, and importing other modules in the same
directory (/opt/openpkg/lib/python) works fine, even ones that import
sys themselves.

A code snippet like
import sys
import re
newval=re.sub('sompat','somerepl' some_string)

will mysteriously fail with the above exception trace. The work-around
is to import and use sre directly and make sure it is imported after the
sys module, e.g.:

import sys
import sre
newval=sre.sub('sompat','somerepl' some_string)

The Python version is 2.3.3 from OpenPKG.

I don't know if this is a bug report, or just a heads-up for others that
may run into the same problem, reply or ignore as appropriate ;-)



Conrad Steenberg <conrad at hep.caltech.edu>

More information about the Mod_python mailing list