code: def fsencode(path, os_name=os.name, fs_encoding=FS_ENCODING, errors=None):
      '''
      Encode given path.
  
      :param path: path will be encoded if not using bytes
      :type path: bytes or str
      :param os_name: operative system name, defaults to os.name
      :type os_name: str
      :param fs_encoding: current filesystem encoding, defaults to autodetected
      :type fs_encoding: str
      :return: encoded path
      :rtype: bytes
      '''
      if isinstance(path, bytes):
          return path
      if not errors:
          use_strict = PY_LEGACY or os_name == 'nt'
          errors = 'strict' if use_strict else 'surrogateescape'
      return path.encode(fs_encoding, errors=errorsf fsencode(path, os_name=os.name, fs_encoding=FS_ENCODING, errors=None):
      '''
      Encode given path.
  
      :param path: path will be encoded if not using bytes
      :type path: bytes or str
      :param os_name: operative system name, defaults to os.name
      :type os_name: str
      :param fs_encoding: current filesystem encoding, defaults to autodetected
      :type fs_encoding: str
      :return: encoded path
      :rtype: bytes
      '''
      if isinstance(path, bytes):
          return path
      if not errors:
          use_strict = PY_LEGACY or os_name == 'nt'
          errors = 'strict' if use_strict else 'surrogateescape'
      return path.encode(fs_encoding, errors=errors)
docs: Encode given path.
  
      :param path: path will be encoded if not using bytes
      :type path: bytes or str
      :param os_name: operative system name, defaults to os.name
      :type os_name: str
      :param fs_encoding: current filesystem encoding, defaults to autodetected
      :type fs_encoding: str
      :return: encoded path
      :rtype: bytes