Rewrite for python3.

Change-Id: I7b17aee5f743848596cea5f7d0d5e2469cdbcf6d