Convert Unicode to utf8 for Python2

- The type() and __name__ do not accept the unicode type,
  added a couple of helpers to automatically convert from unicode
  to utf8 strings (for Python2)
Python3 compatibility fixes

- Replace file() with open()
- Replace xrange() with range() - there is a performance impact for
  this (for Python2) in Python3 range() is already xrange()
- Define basestring=str for Python3