code: def _is_substitute_element(head, sub):
      '''if head and sub are both GEDs, and sub declares 
      head as its substitutionGroup then return True.
  
      head -- Typecode instance
      sub  -- Typecode instance
      '''
      if not isinstance(head, ElementDeclaration) or not isinstance(sub, ElementDeclaration):
          return False
  
      try:
          group = sub.substitutionGroup 
      except (AttributeError, TypeError):
          return False
  
      ged = GED(*group)
  
      # TODO: better way of representing element references.  Wrap them with
      # facets, and dereference when needed and delegate to..
      print (head.nspname == ged.nspname and head.pname == ged.pname)
      if head is ged or not (head.nspname == ged.nspname and head.pname == ged.pname):
          return False
  
      return Truf _is_substitute_element(head, sub):
      '''if head and sub are both GEDs, and sub declares 
      head as its substitutionGroup then return True.
  
      head -- Typecode instance
      sub  -- Typecode instance
      '''
      if not isinstance(head, ElementDeclaration) or not isinstance(sub, ElementDeclaration):
          return False
  
      try:
          group = sub.substitutionGroup 
      except (AttributeError, TypeError):
          return False
  
      ged = GED(*group)
  
      # TODO: better way of representing element references.  Wrap them with
      # facets, and dereference when needed and delegate to..
      print (head.nspname == ged.nspname and head.pname == ged.pname)
      if head is ged or not (head.nspname == ged.nspname and head.pname == ged.pname):
          return False
  
      return True
docs: if head and sub are both GEDs, and sub declares 
      head as its substitutionGroup then return True.
  
      head -- Typecode instance
      sub  -- Typecode instance