code: def _match_pattern(filename, include, exclude, real, path, follow):
      
  
      if real:
          symlinks = {}
          if isinstance(filename, bytes):
              curdir = os.fsencode(os.curdir)
              mount = RE_BWIN_MOUNT if util.platform() == "windows" else RE_BMOUNT
          else:
              curdir = os.curdir
              mount = RE_WIN_MOUNT if util.platform() == "windows" else RE_MOUNT
  
          if not mount.match(filename):
              exists = os.path.lexists(os.path.join(curdir, filename))
          else:
              exists = os.path.lexists(filename)
  
          if not exists:
              return False
          if path:
              return _match_real(filename, include, exclude, follow, symlinks)
  
      matched = False
      for pattern in include:
          if pattern.fullmatch(filename):
              matched = True
              break
  
      if not include and exclude:
          matched = True
  
      if matched:
          matched = True
          if exclude:
              for pattern in exclude:
                  if not pattern.fullmatch(filename):
                      matched = False
                      break
      return matched
docs: Match includes and excludes.