Confusion about scan_code in modulefinder.py (in python 2.6)

B

Brock Pytlik

I've been working with the modulefinder.py code recently and I've come
across a bit of code I'm not grasping. In the scan_code function, there
are the following lines:
if sys.version_info >= (2, 5):
scanner = self.scan_opcodes_25
else:
scanner = self.scan_opcodes
I don't understand their purpose. Why would I be running a version of
python less than 2.6 and using the 2.6 module? Should this be looking at
the version of python that was used to compile 'co'?

In my use, I'm subclassing the modulefinder class and adapting the
scan_code function to do what I need, but I've found I need separate
classes for (2.4, 2.5) and 2.6 because when running 2.4 or 2.5, the
above code traces back. (In 2.4 because self.scan_opcodes isn't defined,
in 2.5 because self.scan_opcodes_25 isn't.)

In the end, I've gotten everything working to my satisfaction, but I'm
curious about how this module (and those lines in particular) were
designed to be used. Any insight would be appreciated.

Thanks,
Brock
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top