code: def expanduser(path):
      
  
      path = path2fsn(path)
  
      if path == "~":
          return _get_userdir()
      elif path.startswith("~" + sep) or (
              altsep is not None and path.startswith("~" + altsep)):
          userdir = _get_userdir()
          if userdir is None:
              return path
          return userdir + path[1:]
      elif path.startswith("~"):
          sep_index = path.find(sep)
          if altsep is not None:
              alt_index = path.find(altsep)
              if alt_index != -1 and alt_index < sep_index:
                  sep_index = alt_index
  
          if sep_index == -1:
              user = path[1:]
              rest = ""
          else:
              user = path[1:sep_index]
              rest = path[sep_index:]
  
          userdir = _get_userdir(user)
          if userdir is not None:
              return userdir + rest
          else:
              return path
      else:
          return path
docs: Args:
          path (pathlike): A path to expand
      Returns:
          `fsnative`
  
      Like :func:`python:os.path.expanduser` but supports unicode home
      directories under Windows + Python 2 and always returns a `fsnative`.