Removed xrange() - use six.moves.range() instead

xrange() was renamed to range() in python3 so we should not use it.
Use range() in for a small values and six.moves.range() for a large.
python3: replaced basestring to six.string_types
python3: fix a long integer usage
python3: Replace file and _fileobject

Use io.IOBase instead of file and socket.SocketIO instead of
socket._fileobject
python 3: Use queue instead of Queue in py3 env
python 3: Replace thread to _thread in py3 env
Syntax py3 fixes in /tmp/* test files
Remove `new` module usage

Module new from python stdlib was removed in python 3 so we should
remove it's usage due to py3 compability
Remove tuples from function signature
Add __bool__() and __next__() methods