Refactor the 1.7-specific code

Checking for the attribute is probably cleaner than catching all
AttributeErrors.