class_docstr: Base class for attribute collector subclasses. Classes that inherit
  this class may use a declarative syntax to specify which vertex or edge
  attributes they intend to collect. See L{AttributeCollectorMeta} for
  the details.
docstr: Collects graph visualization attributes from various sources.
  
  This method can be used to collect the attributes required for graph
  visualization from various sources. Attribute value sources are:
  
    - A specific value of a Python dict belonging to a given key. This dict
      is given by the argument M{self.kwds} at construction time, and
      the name of the key is determined by the argument specification
      given in M{attr_spec}.
  
    - A vertex or edge sequence of a graph, given in M{self.seq}
  
    - The global configuration, given in M{config}
  
    - A default value when all other sources fail to provide the value.
      This is also given in M{attr_spec}.
  
  @param  attr_spec: an L{AttributeSpecification} object which contains
                     the name of the attribute when it is coming from a
                     list of Python keyword arguments, the name of the
                     attribute when it is coming from the graph attributes
                     directly, the default value of the attribute and an
                     optional callable transformation to call on the values.
                     This can be used to ensure that the attributes are of
                     a given type.
  @param  config:    a L{Configuration} object to be used for determining the
                     defaults if all else fails. If C{None}, the global
                     igraph configuration will be used
  @return: the collected attributes
docstr_tok: ["Collects","graph","visualization","attributes","from","various","sources",".","This","method","can","be","used","to","collect","the","attributes","required","for","graph","visualization","from","various","sources",".","Attribute","value","sources","are",":","-","A","specific","value","of","a","Python","dict","belonging","to","a","given","key",".","This","dict","is","given","by","the","argument","M","{","self.kwds","}","at","construction","time",",","and","the","name","of","the","key","is","determined","by","the","argument","specification","given","in","M","{","attr_spec","}",".","-","A","vertex","or","edge","sequence","of","a","graph",",","given","in","M","{","self.seq","}","-","The","global","configuration",",","given","in","M","{","config","}","-","A","default","value","when","all","other","sources","fail","to","provide","the","value",".","This","is","also","given","in","M","{","attr_spec","}",".","@","param","attr_spec",":","an","L","{","AttributeSpecification","}","object","which","contains","the","name","of","the","attribute","when","it","is","coming","from","a","list","of","Python","keyword","arguments",",","the","name","of","the","attribute","when","it","is","coming","from","the","graph","attributes","directly",",","the","default","value","of","the","attribute","and","an","optional","callable","transformation","to","call","on","the","values",".","This","can","be","used","to","ensure","that","the","attributes","are","of","a","given","type",".","@","param","config",":","a","L","{","Configuration","}","object","to","be","used","for","determining","the","defaults","if","all","else","fails",".","If","C","{","None","}",",","the","global","igraph","configuration","will","be","used","@","return",":","the","collected","attributes"]
code: def _collect_attributes(self, attr_spec, config=None):
      """Collects graph visualization attributes from various sources.
  
      This method can be used to collect the attributes required for graph
      visualization from various sources. Attribute value sources are:
  
        - A specific value of a Python dict belonging to a given key. This dict
          is given by the argument M{self.kwds} at construction time, and
          the name of the key is determined by the argument specification
          given in M{attr_spec}.
  
        - A vertex or edge sequence of a graph, given in M{self.seq}
  
        - The global configuration, given in M{config}
  
        - A default value when all other sources fail to provide the value.
          This is also given in M{attr_spec}.
  
      @param  attr_spec: an L{AttributeSpecification} object which contains
                         the name of the attribute when it is coming from a
                         list of Python keyword arguments, the name of the
                         attribute when it is coming from the graph attributes
                         directly, the default value of the attribute and an
                         optional callable transformation to call on the values.
                         This can be used to ensure that the attributes are of
                         a given type.
      @param  config:    a L{Configuration} object to be used for determining the
                         defaults if all else fails. If C{None}, the global
                         igraph configuration will be used
      @return: the collected attributes
      """
      kwds = self.kwds
      seq = self.seq
  
      n = len(seq)
  
      # Special case if the attribute name is "label"
      if attr_spec.name == "label":
          if (
              attr_spec.alt_name in kwds
              and kwds[attr_spec.alt_name] is None
          ):
              return [None] * n
  
      # If the attribute uses an external callable to derive the attribute
      # values, call it and store the results
      if attr_spec.func is not None:
          func = attr_spec.func
          result = [func(i) for i in range(n)]
          return result
  
      # Get the configuration object
      if config is None:
          config = Configuration.instance()
  
      # Fetch the defaults from the vertex/edge sequence
      try:
          attrs = seq[attr_spec.name]
      except KeyError:
          attrs = None
  
      # Override them from the keyword arguments (if any)
      result = kwds.get(attr_spec.alt_name, None)
      if attrs:
          if not result:
              result = attrs
          else:
              if isinstance(result, str):
                  result = [result] * n
              try:
                  len(result)
              except TypeError:
                  result = [result] * n
              result = [
                  result[idx] or attrs[idx]
                  for idx in range(len(result))
              ]
  
      # Special case for string overrides, strings are not treated
      # as sequences here
      if isinstance(result, str):
          result = [result] * n
  
      # If the result is still not a sequence, make it one
      try:
          len(result)
      except TypeError:
          result = [result] * n
  
      # If it is not a list, ensure that it is a list
      if not hasattr(result, "extend"):
          result = list(result)
  
      # Ensure that the length is n
      while len(result) < n:
          if len(result) <= n / 2:
              result.extend(result)
          else:
              result.extend(result[0 : (n - len(result))])
  
      # By now, the length of the result vector should be n as requested
      # Get the configuration defaults
      try:
          default = config["plotting.%s" % attr_spec.alt_name]
      except NoOptionError:
          default = None
  
      if default is None:
          default = attr_spec.default
  
      # Fill the None values with the default values
      for idx in range(len(result)):
          if result[idx] is None:
              result[idx] = default
  
      # Finally, do the transformation
      if attr_spec.transform is not None:
          transform = attr_spec.transform
          result = [transform(x) for x in result]
  
      return result
  
file_path: python-igraph/src/igraph/drawing/metamagic.py
imports: from configparser import NoOptionError
  from igraph.configuration import Configuration
label_desc: Use image node_id 2 for calling the AttributeCollectorBase obj's underlying member method code with example usage: obj._collect_attributes(attr_spec, config) and returns: result, result, unknown