code: def getpreferredencoding():
      
      encoding = locale.getpreferredencoding(False)
      if sys.platform == 'darwin' and encoding.startswith('mac-'):
          # Upgrade ancient MacOS encodings in Python < 2.7
          encoding = 'utf-8'
      return encoding
docs: Return preferred encoding for text I/O.