code: def escape(self, text):
          
          return self.__escapable.sub(self.__escape, compat.text_type(text)
                                      ).encode('ascii')
docs: Replace characters with their character references.
  
          Replace characters by their named entity references.
          Non-ASCII characters, if they do not have a named entity reference,
          are replaced by numerical character references.
  
          The return value is guaranteed to be ASCII.