def METHOD_NAME(
    path,
    *args,
    allow_symlinks=False,
    base_path=None,
    max_size_bytes=MAX_FILE_SIZE_BYTES,
    **kwargs
):
    """
    Wrapper around path.open() to check for symlinks.
    - Checks for symlinks to avoid symlink following vulnerabilities
       like GHSA-368m-86q9-m99w.
    - Checks that files aren't out of the DOCROOT directory.
    - Checks that files aren't too large.
    :param allow_symlinks: If `False` and the path is a symlink, raise `FileIsSymlink`
     This prevents reading the contents of other files users shouldn't have access to.
    :param base_path: If given, check that the path isn't located outside the base path
     (usually the directory where the project was cloned).
     It must be given if `allow_symlinks` is set to `True`.
     This prevents path traversal attacks (even when using symlinks).
    :param max_size_bytes: Maximum file size allowed in bytes when reading a file.
    The extra *args and **kwargs will be passed to the open() method.
    .. warning::
       This operation isn't safe to TocTou (Time-of-check to Time-of-use) attacks.
       Users shouldn't be able to change files while this operation is done.
    """
    if allow_symlinks and not base_path:
        raise ValueError("base_path must be given if symlinks are allowed.")
    path = Path(path).absolute()
    log.bind(
        path_resolved=str(path.absolute().resolve()),
    )
    if path.exists() and not path.is_file():
        raise FileIsNotRegularFile()
    if not allow_symlinks and path.is_symlink():
        log.info("Skipping file becuase it's a symlink.")
        raise UnsupportedSymlinkFileError()
    # Expand symlinks.
    resolved_path = path.resolve()
    if resolved_path.exists():
        file_size = resolved_path.stat().st_size
        if file_size > max_size_bytes:
            log.info("File is too large.", size_bytes=file_size)
            raise FileTooLarge()
    if allow_symlinks and base_path:
        base_path = Path(base_path).absolute()
        if not resolved_path.is_relative_to(base_path):
            # Trying to path traversal via a symlink, sneaky!
            log.info("Path traversal via symlink.")
            raise SymlinkOutsideBasePath()
    _assert_path_is_inside_docroot(resolved_path)
    # The encoding is valid only if the file opened is a text file,
    # this function is used to read both types of files (text and binary),
    # so we can't specify the encoding here.
    # pylint: disable=unspecified-encoding
    return resolved_path.open(*args, **kwargs)