Port cfd.py from compat

Change-Id: Ie0221f95ccbb2048a03bce74421c25e5a51a294a
PEP8-ify cfd.py

Change-Id: I58eb26f7ef6e89092402f1d15775b7ae03e7ee82