Porting protect.py from compat to core.

Change-Id: I085c1a271e91324e8641f405fccec297f5533703
Merge "Porting protect.py from compat to core."