code: def _joinrealpath(self, path, rest, seen):
          
          curdir = self.filesystem._matching_string(path, '.')
          pardir = self.filesystem._matching_string(path, '..')
  
          sep = self.filesystem._path_separator(path)
          if self.isabs(rest):
              rest = rest[1:]
              path = sep
  
          while rest:
              name, _, rest = rest.partition(sep)
              if not name or name == curdir:
                  # current dir
                  continue
              if name == pardir:
                  # parent dir
                  if path:
                      path, name = self.filesystem.splitpath(path)
                      if name == pardir:
                          path = self.filesystem.joinpaths(path, pardir, pardir)
                  else:
                      path = pardir
                  continue
              newpath = self.filesystem.joinpaths(path, name)
              if not self.filesystem.islink(newpath):
                  path = newpath
                  continue
              # Resolve the symbolic link
              if newpath in seen:
                  # Already seen this path
                  path = seen[newpath]
                  if path is not None:
                      # use cached value
                      continue
                  # The symlink is not resolved, so we must have a symlink loop.
                  # Return already resolved part + rest of the path unchanged.
                  return self.filesystem.joinpaths(newpath, rest), False
              seen[newpath] = None  # not resolved symlink
              path, ok = self._joinrealpath(
                  path, self.filesystem.readlink(newpath), seen)
              if not ok:
                  return self.filesystem.joinpaths(path, rest), False
              seen[newpath] = path  # resolved symlink
          return path, True
docs: Join two paths, normalizing and eliminating any symbolic links
          encountered in the second path.
          Taken from Python source and adapted.