Use Python2/3-compatible code in selftest.py
Use Python2/3-compatible code in selftest.py

* Detect if Python2's xrange is present, or use Python3's range;
* Get exception from sys.exc_info().

fixes: #1426

Signed-off-by: Olivier Mehani <9858fe98d2c7f5f35e0d2a08f134cfc58afd42d3@nicta.com.au>

mytestbed/oml,lees0414/EUproject,mytestbed/oml,lees0414/EUproject,mytestbed/oml,alco90/soml,alco90/soml,mytestbed/oml,lees0414/EUproject,lees0414/EUproject,lees0414/EUproject,mytestbed/oml,alco90/soml,alco90/soml,alco90/soml