class_docstr: Parser for the Telnet protocol.
  Usage::
  
      def data_received(data):
          print(data)
  
      def size_received(rows, columns):
          print(rows, columns)
  
      p = TelnetProtocolParser(data_received, size_received)
      p.feed(binary_data)
class_docstr_tok: ["Parser","for","the","Telnet","protocol",".","Usage",":",":","def","data_received","(","data",")",":","print","(","data",")","def","size_received","(","rows",",","columns",")",":","print","(","rows",",","columns",")","p","=","TelnetProtocolParser","(","data_received",",","size_received",")","p.feed","(","binary_data",")"]
docstr: Parser state machine.
  Every 'yield' expression returns the next byte.
docstr_tok: ["Parser","state","machine",".","Every","'yield","'","expression","returns","the","next","byte","."]
code: def _parse_coroutine(self):
      """
      Parser state machine.
      Every 'yield' expression returns the next byte.
      """
      while True:
          d = yield
  
          if d == int2byte(0):
              pass  # NOP
  
          # Go to state escaped.
          elif d == IAC:
              d2 = yield
  
              if d2 == IAC:
                  self.received_data(d2)
  
              # Handle simple commands.
              elif d2 in (NOP, DM, BRK, IP, AO, AYT, EC, EL, GA):
                  self.command_received(d2, None)
  
              # Handle IAC-[DO/DONT/WILL/WONT] commands.
              elif d2 in (DO, DONT, WILL, WONT):
                  d3 = yield
                  self.command_received(d2, d3)
  
              # Subnegotiation
              elif d2 == SB:
                  # Consume everything until next IAC-SE
                  data = []
  
                  while True:
                      d3 = yield
  
                      if d3 == IAC:
                          d4 = yield
                          if d4 == SE:
                              break
                          else:
                              data.append(d4)
                      else:
                          data.append(d3)
  
                  self.negotiate(b"".join(data))
          else:
              self.received_data(d)
  
file_path: catboost/contrib/python/prompt-toolkit/py2/prompt_toolkit/contrib/telnet/protocol.py
imports: from __future__ import unicode_literals
  import struct
  from six import int2byte, binary_type, iterbytes
  from .log import logger
label_desc: Use image node_id 10 for calling the TelnetProtocolParser obj's underlying member method code with example usage: obj._parse_coroutine() without return types