[reportlab-users] PythonPoint styles "search path" extended

Dinu Gherman reportlab-users@reportlab.com
Wed, 30 Oct 2002 09:52:37 +0100


Hi,

while doing some experiments with empy and pythonpoint (a great
combination, BTW) I was annoyed enough to extend PythonPoint in
such a way that it also searches style files in the current
directory. To be more precise, in stdparser.py I changed this:

def getModule(modulename,fromPath='reportlab.tools.pythonpoint.styles'):
     try:
         exec 'from reportlab.tools.pythonpoint import '+modulename
         return eval(modulename)
     except ImportError:
         exec 'from reportlab.tools.pythonpoint.styles import 
'+modulename
         return eval(modulename)

to the following:

def getModule(modulename,fromPath='reportlab.tools.pythonpoint.styles'):
     """Get a module containing style declarations.

     Search order is:
         reportlab/tools/pythonpoint/
         reportlab/tools/pythonpoint/styles/
         ./
     """

     try:
         exec 'from reportlab.tools.pythonpoint import '+modulename
         return eval(modulename)
     except ImportError:
         try:
             exec 'from reportlab.tools.pythonpoint.styles import 
'+modulename
             return eval(modulename)
         except ImportError:
             exec 'import '+modulename
             return eval(modulename)

The "fromPath" parameter seems to be for the birds, but I haven't
touched it... The change is only in CVS.

I'm not claiming this is the smartest way to do it, but it's been
the least intrusive one, which is the usual policy here - apart
from the unexpected docstring, perhaps! ;-)

Regards,

Dinu

--
Dinu C. Gherman
......................................................................
"Patriotism is the willingness to kill and be killed for trivial
reasons." (Bertrand Russell)