code: def _read_python_expr(it, end_tokens):
      # Read out a full python expression, stopping when we hit an
      # unnested end token.
      pytypes = []
      token_strings = []
      origins = []
      bracket_level = 0
      for pytype, token_string, origin in it:
          assert bracket_level >= 0
          if bracket_level == 0 and token_string in end_tokens:
              it.push_back((pytype, token_string, origin))
              break
          if token_string in ("(", "[", "{"):
              bracket_level += 1
          if token_string in (")", "]", "}"):
              bracket_level -= 1
          if bracket_level < 0:
              raise PatsyError("unmatched close bracket", origin)
          pytypes.append(pytype)
          token_strings.append(token_string)
          origins.append(origin)
      # Either we found an end_token, or we hit the end of the string
      if bracket_level == 0:
          expr_text = pretty_untokenize(zip(pytypes, token_strings))
          if expr_text == "0":
              token_type = "ZERO"
          elif expr_text == "1":
              token_type = "ONE"
          elif _is_a(int, expr_text) or _is_a(float, expr_text):
              token_type = "NUMBER"
          else:
              token_type = "PYTHON_EXPR"
          return Token(
              token_type, Origin.combine(origins), extra=expr_text
          )
      else:
          raise PatsyError(
              "unclosed bracket in embedded Python " "expression",
              Origin.combine(origins),
          )
  
imports: from __future__ import print_function
  import tokenize
  import six
  from six.moves import cStringIO
  from patsy import PatsyError
  from patsy.origin import Origin
  from patsy.infix_parser import Token, Operator, infix_parse, ParseNode
  from patsy.tokens import python_tokenize, pretty_untokenize
  from patsy.util import PushbackAdapter
label_desc: Use image node_id 2 for calling a global function with example usage: _read_python_expr(it, end_tokens) and returns: Token