Add Python 2.6 support.

Hi Lczub,

I found the piece of code can't work on Python 2.6. And I do some modify. Please review it.
Thanks,

Charles