parameters: (self)
docstring: read loop for the socket.
docstring_summary: read loop for the socket.
docstring_tokens: read loop for the socket .
function: def _telnetReadLoop(self):
          """read loop for the socket."""
          mode = M_NORMAL
          suboption = None
          try:
              while self._socket is not None:
                  try:
                      data = self._socket.recv(1024)
                  except socket.timeout:
                      # just need to get out of recv form time to time to check if
                      # still alive
                      continue
                  except socket.error, e:
                      # connection fails -> terminate loop
                      if self.logger:
                          self.logger.debug("socket error in reader thread: %s" % (e,))
                      break
                  if not data: break # lost connection
                  for byte in data:
                      if mode == M_NORMAL:
                          # interpret as command or as data
                          if byte == IAC:
                              mode = M_IAC_SEEN
                          else:
                              # store data in read buffer or sub option buffer
                              # depending on state
                              if suboption is not None:
                                  suboption.append(byte)
                              else:
                                  self._read_buffer.put(byte)
                      elif mode == M_IAC_SEEN:
                          if byte == IAC:
                              # interpret as command doubled -> insert character
                              # itself
                              if suboption is not None:
                                  suboption.append(IAC)
                              else:
                                  self._read_buffer.put(IAC)
                              mode = M_NORMAL
                          elif byte == SB:
                              # sub option start
                              suboption = bytearray()
                              mode = M_NORMAL
                          elif byte == SE:
                              # sub option end -> process it now
                              self._telnetProcessSubnegotiation(bytes(suboption))
                              suboption = None
                              mode = M_NORMAL
                          elif byte in (DO, DONT, WILL, WONT):
                              # negotiation
                              telnet_command = byte
                              mode = M_NEGOTIATE
                          else:
                              # other telnet commands
                              self._telnetProcessCommand(byte)
                              mode = M_NORMAL
                      elif mode == M_NEGOTIATE: # DO, DONT, WILL, WONT was received, option now following
                          self._telnetNegotiateOption(telnet_command, byte)
                          mode = M_NORMAL
          finally:
              self._thread = None
              if self.logger:
                  self.logger.debug("read thread terminated")
function_tokens: def _telnetReadLoop ( self ) : mode = M_NORMAL suboption = None try : while self . _socket is not None : try : data = self . _socket . recv ( 1024 ) except socket . timeout : # just need to get out of recv form time to time to check if # still alive continue except socket . error , e : # connection fails -> terminate loop if self . logger : self . logger . debug ( "socket error in reader thread: %s" % ( e , ) ) break if not data : break # lost connection for byte in data : if mode == M_NORMAL : # interpret as command or as data if byte == IAC : mode = M_IAC_SEEN else : # store data in read buffer or sub option buffer # depending on state if suboption is not None : suboption . append ( byte ) else : self . _read_buffer . put ( byte ) elif mode == M_IAC_SEEN : if byte == IAC : # interpret as command doubled -> insert character # itself if suboption is not None : suboption . append ( IAC ) else : self . _read_buffer . put ( IAC ) mode = M_NORMAL elif byte == SB : # sub option start suboption = bytearray ( ) mode = M_NORMAL elif byte == SE : # sub option end -> process it now self . _telnetProcessSubnegotiation ( bytes ( suboption ) ) suboption = None mode = M_NORMAL elif byte in ( DO , DONT , WILL , WONT ) : # negotiation telnet_command = byte mode = M_NEGOTIATE else : # other telnet commands self . _telnetProcessCommand ( byte ) mode = M_NORMAL elif mode == M_NEGOTIATE : # DO, DONT, WILL, WONT was received, option now following self . _telnetNegotiateOption ( telnet_command , byte ) mode = M_NORMAL finally : self . _thread = None if self . logger : self . logger . debug ( "read thread terminated" )