fix #69 to ensure encode_name works on python 2.7

The previous monkey patching does not work in modern
python, so now we explicitly adjust 'safe' whenever we
use quote in a situation where the resulting string will
be used outside of the current instance.

See 7e57446e3e89a566ccce9bd5715215e69418f864 for the
original change (from 4 years ago!).