parameters: (self, data)
docstring: \
          Handle a bunch of incoming bytes. This is a generator. It will yield
          all characters not of interest for Telnet/RFC 2217.
  
          The idea is that the reader thread pushes data from the socket through
          this filter:
  
          for byte in filter(socket.recv(1024)):
              # do things like CR/LF conversion/whatever
              # and write data to the serial port
              serial.write(byte)
  
          (socket error handling code left as exercise for the reader)
docstring_summary: \
          Handle a bunch of incoming bytes. This is a generator. It will yield
          all characters not of interest for Telnet/RFC 2217.
docstring_tokens: \ Handle a bunch of incoming bytes . This is a generator . It will yield all characters not of interest for Telnet / RFC 2217 .
function: def filter(self, data):
          """\
          Handle a bunch of incoming bytes. This is a generator. It will yield
          all characters not of interest for Telnet/RFC 2217.
  
          The idea is that the reader thread pushes data from the socket through
          this filter:
  
          for byte in filter(socket.recv(1024)):
              # do things like CR/LF conversion/whatever
              # and write data to the serial port
              serial.write(byte)
  
          (socket error handling code left as exercise for the reader)
          """
          for byte in iterbytes(data):
              if self.mode == M_NORMAL:
                  # interpret as command or as data
                  if byte == IAC:
                      self.mode = M_IAC_SEEN
                  else:
                      # store data in sub option buffer or pass it to our
                      # consumer depending on state
                      if self.suboption is not None:
                          self.suboption += byte
                      else:
                          yield byte
              elif self.mode == M_IAC_SEEN:
                  if byte == IAC:
                      # interpret as command doubled -> insert character
                      # itself
                      if self.suboption is not None:
                          self.suboption += byte
                      else:
                          yield byte
                      self.mode = M_NORMAL
                  elif byte == SB:
                      # sub option start
                      self.suboption = bytearray()
                      self.mode = M_NORMAL
                  elif byte == SE:
                      # sub option end -> process it now
                      self._telnet_process_subnegotiation(bytes(self.suboption))
                      self.suboption = None
                      self.mode = M_NORMAL
                  elif byte in (DO, DONT, WILL, WONT):
                      # negotiation
                      self.telnet_command = byte
                      self.mode = M_NEGOTIATE
                  else:
                      # other telnet commands
                      self._telnet_process_command(byte)
                      self.mode = M_NORMAL
              elif self.mode == M_NEGOTIATE:  # DO, DONT, WILL, WONT was received, option now following
                  self._telnet_negotiate_option(self.telnet_command, byte)
                  self.mode = M_NORMAL
function_tokens: def filter ( self , data ) : for byte in iterbytes ( data ) : if self . mode == M_NORMAL : # interpret as command or as data if byte == IAC : self . mode = M_IAC_SEEN else : # store data in sub option buffer or pass it to our # consumer depending on state if self . suboption is not None : self . suboption += byte else : yield byte elif self . mode == M_IAC_SEEN : if byte == IAC : # interpret as command doubled -> insert character # itself if self . suboption is not None : self . suboption += byte else : yield byte self . mode = M_NORMAL elif byte == SB : # sub option start self . suboption = bytearray ( ) self . mode = M_NORMAL elif byte == SE : # sub option end -> process it now self . _telnet_process_subnegotiation ( bytes ( self . suboption ) ) self . suboption = None self . mode = M_NORMAL elif byte in ( DO , DONT , WILL , WONT ) : # negotiation self . telnet_command = byte self . mode = M_NEGOTIATE else : # other telnet commands self . _telnet_process_command ( byte ) self . mode = M_NORMAL elif self . mode == M_NEGOTIATE : # DO, DONT, WILL, WONT was received, option now following self . _telnet_negotiate_option ( self . telnet_command , byte ) self . mode = M_NORMAL