code: def get_parens(line,retlevel=0,retblevel=0):
      
      if len(line) == 0: return line
      parenstr = ''
      level = 0
      blevel = 0
      for char in line:
          if char == '(':
              level += 1
          elif char == ')':
              level -= 1
          elif char == '[':
              blevel += 1
          elif char == ']':
              blevel -= 1
          elif (char.isalpha() or char == '_' or char == ':' or char == ',' 
            or char == ' ') and level == retlevel and blevel == retblevel:
              return parenstr
          parenstr = parenstr + char
      
      if level == retlevel and blevel == retblevel: return parenstr    
      raise Exception("Couldn't parse parentheses: {}".format(line))
docs: By default akes a string starting with an open parenthesis and returns the portion
      of the string going to the corresponding close parenthesis. If retlevel != 0 then
      will return when that level (for parentheses) is reached. Same for retblevel.