parameters: (self, path_elements)
docstring: Returns a :class:`MatchType` for the directory, expressed as a list of path
          elements, match for the :class:`Pattern`.
  
          If ``self.bound_start`` is True, the first :class:`Section` must match
          from the first directory element.
  
          If ``self.bound_end`` is True, the last :class:`Section` must match
          the last contiguous elements of *path_elements*.
docstring_summary: Returns a :class:`MatchType` for the directory, expressed as a list of path
          elements, match for the :class:`Pattern`.
docstring_tokens: Returns a : class : MatchType for the directory expressed as a list of path elements match for the : class : Pattern .
function: def match_directory(self, path_elements):
          """Returns a :class:`MatchType` for the directory, expressed as a list of path
          elements, match for the :class:`Pattern`.
  
          If ``self.bound_start`` is True, the first :class:`Section` must match
          from the first directory element.
  
          If ``self.bound_end`` is True, the last :class:`Section` must match
          the last contiguous elements of *path_elements*.
          """
  
          def match_recurse(is_start, sections, path_elements, location):
              """A private function for implementing the recursive search.
  
              The function takes the first section from sections and tries to
              match this against the elements in path_elements, starting from
              the location'th element in that list.
  
              If sections is empty, this is taken to mean all sections have
              been previously matched, therefore a match has been found.
              """
              if sections:
                  section = sections[0]
                  any_match = False
                  for end in section.match_iter(path_elements, location):
                      any_match = True
                      match = match_recurse(False, sections[1:], path_elements, end)
                      if match | MatchType.MATCH:
                          return match
  
                  # No match found
                  if is_start and self.bound_start and not any_match:
                      # This this is the start of the recursion AND the pattern
                      # is bound to the start of the path ("/start/**") AND this
                      # did not match, then no subdirectories are possible either
  
                      # WAS if len(path_elements) >= 1:
  
                      if len(path_elements) >= len(section.elements):
                          return MatchType.NO_MATCH_NO_SUBDIRECTORIES
                      else:
                          return MatchType.NO_MATCH
                  else:
                      return MatchType.NO_MATCH
              else:
                  # Termination of the recursion after FINDING the match.
                  if len(self.sections) == 1 and self.bound_start and self.bound_end:
                      # If this pattern is of the form "/test/*" it matches
                      # just THIS directory and no subdirectories
                      return MatchType.MATCH_BUT_NO_SUBDIRECTORIES
                  elif self.bound_end:
                      # "**/test/*" matches just this directory
                      # and allows subdirectories to also match
                      return MatchType.MATCH
                  else:
                      # If the pattern is not bound to the end of the path (eg
                      # NOT "**/term/**") the pattern matches all subdirectories
                      return MatchType.MATCH_ALL_SUBDIRECTORIES
              # End of: def match_recurse(is_start, sections, path_elements, location):
  
          if self.sections:
              return match_recurse(True, self.sections, path_elements, 0)
          else:
              # Catches directory-less patterns like "*.py" and "/*.py".
              if self.bound_start:
                  if len(path_elements) == 0:
                      # Eg "*/*.py" in the root directory
                      return MatchType.MATCH_BUT_NO_SUBDIRECTORIES
                  else:
                      # Eg "/*.py" meets directory "/test/" - nothing happening
                      return MatchType.NO_MATCH_NO_SUBDIRECTORIES
              else:
                  # Eg "**/*.py" - match all directories
                  return MatchType.MATCH_ALL_SUBDIRECTORIES
function_tokens: def match_directory ( self , path_elements ) : def match_recurse ( is_start , sections , path_elements , location ) : """A private function for implementing the recursive search.
  
              The function takes the first section from sections and tries to
              match this against the elements in path_elements, starting from
              the location'th element in that list.
  
              If sections is empty, this is taken to mean all sections have
              been previously matched, therefore a match has been found.
              """ if sections : section = sections [ 0 ] any_match = False for end in section . match_iter ( path_elements , location ) : any_match = True match = match_recurse ( False , sections [ 1 : ] , path_elements , end ) if match | MatchType . MATCH : return match # No match found if is_start and self . bound_start and not any_match : # This this is the start of the recursion AND the pattern # is bound to the start of the path ("/start/**") AND this # did not match, then no subdirectories are possible either # WAS if len(path_elements) >= 1: if len ( path_elements ) >= len ( section . elements ) : return MatchType . NO_MATCH_NO_SUBDIRECTORIES else : return MatchType . NO_MATCH else : return MatchType . NO_MATCH else : # Termination of the recursion after FINDING the match. if len ( self . sections ) == 1 and self . bound_start and self . bound_end : # If this pattern is of the form "/test/*" it matches # just THIS directory and no subdirectories return MatchType . MATCH_BUT_NO_SUBDIRECTORIES elif self . bound_end : # "**/test/*" matches just this directory # and allows subdirectories to also match return MatchType . MATCH else : # If the pattern is not bound to the end of the path (eg # NOT "**/term/**") the pattern matches all subdirectories return MatchType . MATCH_ALL_SUBDIRECTORIES # End of: def match_recurse(is_start, sections, path_elements, location): if self . sections : return match_recurse ( True , self . sections , path_elements , 0 ) else : # Catches directory-less patterns like "*.py" and "/*.py". if self . bound_start : if len ( path_elements ) == 0 : # Eg "*/*.py" in the root directory return MatchType . MATCH_BUT_NO_SUBDIRECTORIES else : # Eg "/*.py" meets directory "/test/" - nothing happening return MatchType . NO_MATCH_NO_SUBDIRECTORIES else : # Eg "**/*.py" - match all directories return MatchType . MATCH_ALL_SUBDIRECTORIES