>  but because it looks like you're modifying str(iff.FORMAT_AGENT)

I am indeed doing that. I'll remove this (and the result will no longer have a trailing newline).