parameters: (self, regex=b"^\d\d\d\d OK.*$")
docstring: Receive a full message.
  
          It retrieves messages (header + message text),
          until
  
             1. the message contains the specified regex or
             2. the header indicates a signal.
  
          Args:
            regex (bytes): Descripes the expected end of the message.
  
          Returns:
             bytearray: Message retrieved via the connection.
  
          Raises:
              bareos.exceptions.SignalReceivedException:
                 If a Bareos signal is received.
docstring_summary: Receive a full message.
docstring_tokens: Receive a full message .
function: def recv_msg(self, regex=b"^\d\d\d\d OK.*$"):
          """Receive a full message.
  
          It retrieves messages (header + message text),
          until
  
             1. the message contains the specified regex or
             2. the header indicates a signal.
  
          Args:
            regex (bytes): Descripes the expected end of the message.
  
          Returns:
             bytearray: Message retrieved via the connection.
  
          Raises:
              bareos.exceptions.SignalReceivedException:
                 If a Bareos signal is received.
          """
          self.__check_socket_connection()
          try:
              timeouts = 0
              while True:
                  # get the message header
                  try:
                      header = self.__get_header()
                  except (socket.timeout, ssl.SSLError) as exception:
                      # When using a SSL connection,
                      # a timeout is raised as
                      # ssl.SSLError exception with message: 'The read operation timed out'.
                      # ssl.SSLError is inherited from socket.error.
                      # Because we can't be sure,
                      # that it is really a timeout, we log it.
                      if isinstance(exception, ssl.SSLError) and self.logger.isEnabledFor(
                          logging.DEBUG
                      ):
                          # self.logger.exception('On SSL connections, timeout are raised as ssl.SSLError exceptions:')
                          self.logger.debug("{0}".format(repr(exception)))
                      self.logger.debug("timeout (%i) on receiving header" % (timeouts))
                      timeouts += 1
                  else:
                      if header <= 0:
                          # header is a signal
                          self.__set_status(header)
                          if self.is_end_of_message(header):
                              result = self.receive_buffer
                              self.receive_buffer = b""
                              return result
                      else:
                          # header is the length of the next message
                          length = header
                          submsg = self.recv_submsg(length)
                          # check for regex in new submsg
                          # and last line in old message,
                          # which might have been incomplete without new submsg.
                          lastlineindex = self.receive_buffer.rfind(b"\n") + 1
                          self.receive_buffer += submsg
                          match = re.search(
                              regex, self.receive_buffer[lastlineindex:], re.DOTALL
                          )
                          # Bareos indicates end of command result by line starting with 4 digits
                          if match:
                              self.logger.debug(
                                  'msg "{0}" matches regex "{1}"'.format(
                                      self.receive_buffer.strip(), regex
                                  )
                              )
                              result = self.receive_buffer[
                                  0 : lastlineindex + match.end()
                              ]
                              self.receive_buffer = self.receive_buffer[
                                  lastlineindex + match.end() + 1 :
                              ]
                              return result
          except socket.error as e:
              self._handleSocketError(e)
function_tokens: def recv_msg ( self , regex = b"^\d\d\d\d OK.*$" ) : self . __check_socket_connection ( ) try : timeouts = 0 while True : # get the message header try : header = self . __get_header ( ) except ( socket . timeout , ssl . SSLError ) as exception : # When using a SSL connection, # a timeout is raised as # ssl.SSLError exception with message: 'The read operation timed out'. # ssl.SSLError is inherited from socket.error. # Because we can't be sure, # that it is really a timeout, we log it. if isinstance ( exception , ssl . SSLError ) and self . logger . isEnabledFor ( logging . DEBUG ) : # self.logger.exception('On SSL connections, timeout are raised as ssl.SSLError exceptions:') self . logger . debug ( "{0}" . format ( repr ( exception ) ) ) self . logger . debug ( "timeout (%i) on receiving header" % ( timeouts ) ) timeouts += 1 else : if header <= 0 : # header is a signal self . __set_status ( header ) if self . is_end_of_message ( header ) : result = self . receive_buffer self . receive_buffer = b"" return result else : # header is the length of the next message length = header submsg = self . recv_submsg ( length ) # check for regex in new submsg # and last line in old message, # which might have been incomplete without new submsg. lastlineindex = self . receive_buffer . rfind ( b"\n" ) + 1 self . receive_buffer += submsg match = re . search ( regex , self . receive_buffer [ lastlineindex : ] , re . DOTALL ) # Bareos indicates end of command result by line starting with 4 digits if match : self . logger . debug ( 'msg "{0}" matches regex "{1}"' . format ( self . receive_buffer . strip ( ) , regex ) ) result = self . receive_buffer [ 0 : lastlineindex + match . end ( ) ] self . receive_buffer = self . receive_buffer [ lastlineindex + match . end ( ) + 1 : ] return result except socket . error as e : self . _handleSocketError ( e )