<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _matching_pattern_sets(self):
 """Returns an iterator containing all PatternSets that match this directory. This is build by chaining the this-directory specific PatternSet (self.matched_and_subdir), the local (non-inheriting) PatternSet (self.matched_no_subdir) with all the inherited PatternSets that match this directory and all its parents (self.match_inherit)."""

        gather = []
        if self.matched_and_subdir:
            gather.append(self.matched_and_subdir.iter())
            gather.append(self.matched_no_subdir.iter())
        ref = self
        while ref is not None:
            if ref.matched_inherit:
                gather.append(ref.matched_inherit.iter())
            if ref.parent_has_patterns:
                ref = ref.parent
            else:
                ref = None
        return chain.from_iterable(gather)