docstr: Create a bracemap of brackets in the program, to compute jmps.
  Maps open -> close brackets as well as close -> open brackets.
  
  Also returns True if the program is valid Brainfuck code. If False, we
  won't even try to run it.
docstr_tok: ["Create","a","bracemap","of","brackets","in","the","program",",","to","compute","jmps",".","Maps","open","-",">","close","brackets","as","well","as","close","-",">","open","brackets",".","Also","returns","True","if","the","program","is","valid","Brainfuck","code",".","If","False",",","we","wo","n't","even","try","to","run","it","."]
code: def bracemap_and_check(
      self, program: str
  ) -> Tuple[Optional[Dict], bool]:
      """
      Create a bracemap of brackets in the program, to compute jmps.
      Maps open -> close brackets as well as close -> open brackets.
  
      Also returns True if the program is valid Brainfuck code. If False, we
      won't even try to run it.
      """
  
      open_stack = []
      bracemap = dict()
      legal_instructions = {"+", "-", ">", "<", "[", "]", "."}
      legal_count = 0
  
      # If the program actually outputs anything (contains ".")
      prints = False
  
      for idx, instruction in enumerate(program):
          # If instruction is brainfuck (without input) or whitespace, it counts
          if instruction in legal_instructions or re.match(
              r"\s", instruction
          ):
              legal_count += 1
  
          if not prints and instruction == ".":
              # If there are no "." instructions then this program will not output anything
              prints = True
  
          elif instruction == "[":
              open_stack.append(idx)
  
          elif instruction == "]":
              try:
                  opbracket = open_stack.pop()
                  bracemap[opbracket] = idx
                  bracemap[idx] = opbracket
              except IndexError:
                  # Mismatched braces, not a valid program
                  # Closing braces > opening braces
                  return (None, False)
  
      # 1. All characters are instructions or whitespace
      # 2. There are no extra open braces
      # 3. There is at least one character to be "printed"
      # (result is >=1 in length)
      is_brainfuck = (
          legal_count == len(program)
          and len(open_stack) == 0
          and prints
      )
  
      return bracemap, is_brainfuck
  
file_path: Ciphey/ciphey/basemods/Decoders/brainfuck.py
imports: import re
  import time
  from typing import Dict, Optional, Tuple
  import logging
  from rich.logging import RichHandler
  from ciphey.iface import Config, Decoder, ParamSpec, T, U, WordList, registry
label_desc: Use image node_id 2 for calling the Brainfuck obj's underlying member method code with example usage: obj.bracemap_and_check(program) and returns: bracemap,  is_brainfuck, None,  False