Upstream fixes for python2.6
Merge pull request #801 from pyhalov/python

Upstream fixes for python2.6