def transmit(self, frame): """ Convert a frame object to a frame string and transmit to the server. :param Frame frame: the Frame object to transmit """ with self.__listeners_change_condition: listeners = sorted(self.listeners.items()) for (_, listener) in listeners: if not listener: continue try: listener.on_send(frame) except AttributeError: continue if frame.cmd == CMD_DISCONNECT and HDR_RECEIPT in frame.headers: self.__disconnect_receipt = frame.headers[HDR_RECEIPT] lines = utils.convert_frame(frame) packed_frame = pack(lines) if log.isEnabledFor(logging.DEBUG): log.debug("Sending frame: %s", lines) else: log.info("Sending frame: %r", frame.cmd or "heartbeat") self.send(packed_frame)
def transmit(self, frame): """ Convert a frame object to a frame string and transmit to the server. :param Frame frame: the Frame object to transmit """ with self.__listeners_change_condition: listeners = list(self.listeners.values()) for listener in listeners: if not listener: continue try: listener.on_send(frame) except AttributeError: continue lines = utils.convert_frame(frame) packed_frame = pack(lines) if log.isEnabledFor(logging.DEBUG): log.debug("Sending frame: %s", lines) else: log.info("Sending frame: %r", frame.cmd or "heartbeat") self.send(packed_frame)