code: def _get_matching(self, reltype, target, is_external=False):
          
          def matches(rel, reltype, target, is_external):
              if rel.reltype != reltype:
                  return False
              if rel.is_external != is_external:
                  return False
              rel_target = rel.target_ref if rel.is_external else rel.target_part
              if rel_target != target:
                  return False
              return True
  
          for rel in self.values():
              if matches(rel, reltype, target, is_external):
                  return rel
          return None
docs: Return relationship of matching *reltype*, *target*, and
          *is_external* from collection, or None if not found.