parameters: (pretty_printers, name_re, subname_re, flag)
return_statement: return total
docstring: Worker for enabling/disabling pretty-printers.
  
      Arguments:
          pretty_printers: list of pretty-printers
          name_re: regular-expression object to select printers
          subname_re: regular expression object to select subprinters or None
                      if all are affected
          flag: True for Enable, False for Disable
  
      Returns:
          The number of printers affected.
          This is just for informational purposes for the user.
docstring_summary: Worker for enabling/disabling pretty-printers.
docstring_tokens: Worker for enabling / disabling pretty - printers .
function: def do_enable_pretty_printer_1 (pretty_printers, name_re, subname_re, flag):
      """Worker for enabling/disabling pretty-printers.
  
      Arguments:
          pretty_printers: list of pretty-printers
          name_re: regular-expression object to select printers
          subname_re: regular expression object to select subprinters or None
                      if all are affected
          flag: True for Enable, False for Disable
  
      Returns:
          The number of printers affected.
          This is just for informational purposes for the user.
      """
      total = 0
      for printer in pretty_printers:
          if (hasattr(printer, "name") and name_re.match(printer.name) or
              hasattr(printer, "__name__") and name_re.match(printer.__name__)):
              if (hasattr(printer, "subprinters") and
                  printer.subprinters is not None):
                  if not subname_re:
                      # Only record printers that change state.
                      if printer_enabled_p(printer) != flag:
                          for subprinter in printer.subprinters:
                              if printer_enabled_p(subprinter):
                                  total += 1
                      # NOTE: We preserve individual subprinter settings.
                      printer.enabled = flag
                  else:
                      # NOTE: Whether this actually disables the subprinter
                      # depends on whether the printer's lookup function supports
                      # the "enable" API.  We can only assume it does.
                      for subprinter in printer.subprinters:
                          if subname_re.match(subprinter.name):
                              # Only record printers that change state.
                             if (printer_enabled_p(printer) and
                                 printer_enabled_p(subprinter) != flag):
                                 total += 1
                             subprinter.enabled = flag
              else:
                  # This printer has no subprinters.
                  # If the user does "disable pretty-printer .* .* foo"
                  # should we disable printers that don't have subprinters?
                  # How do we apply "foo" in this context?  Since there is no
                  # "foo" subprinter it feels like we should skip this printer.
                  # There's still the issue of how to handle
                  # "disable pretty-printer .* .* .*", and every other variation
                  # that can match everything.  For now punt and only support
                  # "disable pretty-printer .* .*" (i.e. subname is elided)
                  # to disable everything.
                  if not subname_re:
                      # Only record printers that change state.
                      if printer_enabled_p(printer) != flag:
                          total += 1
                      printer.enabled = flag
      return total
function_tokens: def do_enable_pretty_printer_1 ( pretty_printers , name_re , subname_re , flag ) : total = 0 for printer in pretty_printers : if ( hasattr ( printer , "name" ) and name_re . match ( printer . name ) or hasattr ( printer , "__name__" ) and name_re . match ( printer . __name__ ) ) : if ( hasattr ( printer , "subprinters" ) and printer . subprinters is not None ) : if not subname_re : # Only record printers that change state. if printer_enabled_p ( printer ) != flag : for subprinter in printer . subprinters : if printer_enabled_p ( subprinter ) : total += 1 # NOTE: We preserve individual subprinter settings. printer . enabled = flag else : # NOTE: Whether this actually disables the subprinter # depends on whether the printer's lookup function supports # the "enable" API.  We can only assume it does. for subprinter in printer . subprinters : if subname_re . match ( subprinter . name ) : # Only record printers that change state. if ( printer_enabled_p ( printer ) and printer_enabled_p ( subprinter ) != flag ) : total += 1 subprinter . enabled = flag else : # This printer has no subprinters. # If the user does "disable pretty-printer .* .* foo" # should we disable printers that don't have subprinters? # How do we apply "foo" in this context?  Since there is no # "foo" subprinter it feels like we should skip this printer. # There's still the issue of how to handle # "disable pretty-printer .* .* .*", and every other variation # that can match everything.  For now punt and only support # "disable pretty-printer .* .*" (i.e. subname is elided) # to disable everything. if not subname_re : # Only record printers that change state. if printer_enabled_p ( printer ) != flag : total += 1 printer . enabled = flag return total