def METHOD_NAME(cls, netrc_file="~/.netrc"):
    # type: (Optional[str]) -> PasswordDatabase
    if not netrc_file:
        return cls()
    netrc_path = os.path.expanduser(netrc_file)
    if not os.path.isfile(netrc_path):
        return cls()
    try:
        netrc_database = netrc(netrc_path)
    except NetrcParseError as e:
        pex_warnings.warn(
            "Failed to load netrc credentials: {err}\n"
            "Continuing without netrc credentials.".format(err=e)
        )
        return cls()
    def iter_entries():
        # type: () -> Iterator[PasswordEntry]
        for machine, (login, _, password) in netrc_database.hosts.items():
            if password is None:
                continue
            if machine == "default":
                # The `default` entry is special and means just that; so we omit any qualifying
                # machine.
                yield PasswordEntry(username=login, password=password)
            # Traditionally, ~/.netrc machine entries just contain a bare hostname but we allow
            # for them containing a scheme since the format is so poorly documented and really
            # used as the beholder sees fit (it's a shared ~community format at this point and
            # used differently by a wide range of tools; I think FTP originally - thus it has
            # `macros` entries which ~no-one knows about / uses).
            #
            # For scheme syntax, see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
            if re.search(r"^(?P<scheme>[a-zA-Z][a-zA-Z\d+.-]*)://", machine):
                yield PasswordEntry(
                    machine=Machine.from_url(machine),
                    username=login,
                    password=password,
                )
                continue
            for scheme in "http", "https":
                yield PasswordEntry(
                    machine=Machine.from_url(
                        "{scheme}://{machine}".format(scheme=scheme, machine=machine)
                    ),
                    username=login,
                    password=password,
                )
    return cls(entries=tuple(iter_entries()))