class_docstr: Base class of color palettes.
  
  Color palettes are mappings that assign integers from the range
  0..M{n-1} to colors (4-tuples). M{n} is called the size or length
  of the palette. C{igraph} comes with a number of predefined palettes,
  so this class is useful for you only if you want to define your
  own palette. This can be done by subclassing this class and implementing
  the L{Palette._get} method as necessary.
  
  Palettes can also be used as lists or dicts, for the C{__getitem__}
  method is overridden properly to call L{Palette.get}.
class_docstr_tok: ["Base","class","of","color","palettes",".","Color","palettes","are","mappings","that","assign","integers","from","the","range","0","..","M","{","n-1","}","to","colors","(","4-tuples",")",".","M","{","n","}","is","called","the","size","or","length","of","the","palette",".","C","{","igraph","}","comes","with","a","number","of","predefined","palettes",",","so","this","class","is","useful","for","you","only","if","you","want","to","define","your","own","palette",".","This","can","be","done","by","subclassing","this","class","and","implementing","the","L","{","Palette._get","}","method","as","necessary",".","Palettes","can","also","be","used","as","lists","or","dicts",",","for","the","C","{","__getitem__","}","method","is","overridden","properly","to","call","L","{","Palette.get","}","."]
docstr: Returns the given color from the palette.
  
  Values are cached: if the specific value given has already been
  looked up, its value will be returned from the cache instead of
  calculating it again. Use L{Palette.clear_cache} to clear the cache
  if necessary.
  
  @note: you shouldn't override this method in subclasses, override
    L{_get} instead. If you override this method, lookups in the
    L{known_colors} dict won't work, so you won't be able to refer to
    colors by names or RGBA quadruplets, only by integer indices. The
    caching functionality will disappear as well. However,
    feel free to override this method if this is exactly the behaviour
    you want.
  
  @param v: the color to be retrieved. If it is an integer, it is
    passed to L{Palette._get} to be translated to an RGBA quadruplet.
    Otherwise it is passed to L{color_name_to_rgb()} to determine the
    RGBA values.
  
  @return: the color as an RGBA quadruplet
docstr_tok: ["Returns","the","given","color","from","the","palette",".","Values","are","cached",":","if","the","specific","value","given","has","already","been","looked","up",",","its","value","will","be","returned","from","the","cache","instead","of","calculating","it","again",".","Use","L","{","Palette.clear_cache","}","to","clear","the","cache","if","necessary",".","@","note",":","you","should","n't","override","this","method","in","subclasses",",","override","L","{","_get","}","instead",".","If","you","override","this","method",",","lookups","in","the","L","{","known_colors","}","dict","wo","n't","work",",","so","you","wo","n't","be","able","to","refer","to","colors","by","names","or","RGBA","quadruplets",",","only","by","integer","indices",".","The","caching","functionality","will","disappear","as","well",".","However",",","feel","free","to","override","this","method","if","this","is","exactly","the","behaviour","you","want",".","@","param","v",":","the","color","to","be","retrieved",".","If","it","is","an","integer",",","it","is","passed","to","L","{","Palette._get","}","to","be","translated","to","an","RGBA","quadruplet",".","Otherwise","it","is","passed","to","L","{","color_name_to_rgb","(",")","}","to","determine","the","RGBA","values",".","@","return",":","the","color","as","an","RGBA","quadruplet"]
code: def get(self, v):
      """Returns the given color from the palette.
  
      Values are cached: if the specific value given has already been
      looked up, its value will be returned from the cache instead of
      calculating it again. Use L{Palette.clear_cache} to clear the cache
      if necessary.
  
      @note: you shouldn't override this method in subclasses, override
        L{_get} instead. If you override this method, lookups in the
        L{known_colors} dict won't work, so you won't be able to refer to
        colors by names or RGBA quadruplets, only by integer indices. The
        caching functionality will disappear as well. However,
        feel free to override this method if this is exactly the behaviour
        you want.
  
      @param v: the color to be retrieved. If it is an integer, it is
        passed to L{Palette._get} to be translated to an RGBA quadruplet.
        Otherwise it is passed to L{color_name_to_rgb()} to determine the
        RGBA values.
  
      @return: the color as an RGBA quadruplet"""
      if isinstance(v, list):
          v = tuple(v)
      try:
          return self._cache[v]
      except KeyError:
          pass
      if isinstance(v, str):
          result = color_name_to_rgba(v)
      elif hasattr(v, "__iter__"):  # lists, tuples etc
          return v  # no need to cache
      else:
          if v < 0:
              raise IndexError("color index must be non-negative")
          if v >= self._length:
              raise IndexError("color index too large")
          result = self._get(v)
      self._cache[v] = result
      return result
  
imports: from abc import ABCMeta, abstractmethod
  from math import ceil
label_desc: Use image node_id 3 for calling the Palette obj's underlying member method code with example usage: obj.get(v) and returns: result, self, v