Refactor boilerplate code with python decorator.

Change-Id: I5b71e3b37df82dbad606442aff6fa07eeea6c924