[Pythonmac-SIG] Spotlight and Python

David Reed dreedmac at columbus.rr.com
Wed May 11 03:55:07 CEST 2005


On May 10, 2005, at 8:52 PM, Jonathan Wight wrote:

> I've made a first pass at it and have a Spotlight importer that  
> calls a built-in Python function to import a file's metadata.
>
> I started to look at module inspect to find out how to extract  
> information from a Python module but then realised that I'd need to  
> import the file the importer is analysing. This would mean it will  
> be executing arbitrary code inside that file. That's got to be a  
> bad thing for security reasons.
>
> So instead I'm just going to have to use string processing to scan  
> the file instead. Are there any modules out there for extracting  
> information from Python script files?
>
>     Jon.


It's been a while since I looked at the inspect module - I didn't  
remember it actually executed code. I'm not aware of any code that  
processes a python file w/o executing it (I do remember that being a  
complaint about pychecker). You could rip out code from the Python  
interpreter, but I could probably write a C or C++ function that read  
a file and returned the names of the classes and functions/methods in  
less time than I could find and decipher the Python interpreter code  
if that would help you. Would you pass it a filename or a file handle  
and how would you want the data back (an array of strings or one long  
string separated by spaces, etc.). Does it matter if it's C or could  
it use C++ features (the C++ string class might be useful). I would  
just look for "def" or "class" and grab the next word up to a "(" or  
":".

Dave



More information about the Pythonmac-SIG mailing list