code: def apply_plan(text, plan):
      
      obj = text
      for operation, encoding, _ in plan:
          if operation == 'encode':
              obj = obj.encode(encoding)
          elif operation == 'decode':
              obj = obj.decode(encoding)
          elif operation == 'transcode':
              if encoding in TRANSCODERS:
                  obj = TRANSCODERS[encoding](obj)
              else:
                  raise ValueError("Unknown transcode operation: %s" % encoding)
          else:
              raise ValueError("Unknown plan step: %s" % operation)
  
      return obj
docs: Apply a plan for fixing the encoding of text.
  
      The plan is a list of tuples of the form (operation, encoding, cost):
  
      - `operation` is 'encode' if it turns a string into bytes, 'decode' if it
        turns bytes into a string, and 'transcode' if it keeps the type the same.
      - `encoding` is the name of the encoding to use, such as 'utf-8' or
        'latin-1', or the function name in the case of 'transcode'.
      - The `cost` does not affect how the plan itself works. It's used by other
        users of plans, namely `fix_encoding_and_explain`, which has to decide
        *which* plan to use.