Ifdef the 3.1 code to avoid a deprecation warning.