code: def _read_password_from_pgpass(
          *, passfile: typing.Optional[pathlib.Path],
          hosts: typing.List[str],
          ports: typing.List[int],
          database: str,
          user: str):
      
  
      passtab = _read_password_file(passfile)
      if not passtab:
          return None
  
      for host, port in zip(hosts, ports):
          if host.startswith('/'):
              # Unix sockets get normalized into 'localhost'
              host = 'localhost'
  
          for phost, pport, pdatabase, puser, ppassword in passtab:
              if phost != '*' and phost != host:
                  continue
              if pport != '*' and pport != str(port):
                  continue
              if pdatabase != '*' and pdatabase != database:
                  continue
              if puser != '*' and puser != user:
                  continue
  
              # Found a match.
              return ppassword
  
      return None
docs: Parse the pgpass file and return the matching password.
  
      :return:
          Password string, if found, ``None`` otherwise.