def setHeader(self, new): """ Applies a new header to this channel. If this channel already has a header, then the new values are merged with the existing. @param new: The header to apply to this channel. @type new: L{header.Header} @return: The previous header, if there is one. @rtype: L{header.Header} or C{None} """ old = self.header if self.header is None: self.header = new else: self.header = header.merge(self.header, new) if new.timestamp == -1: # receiving a new message and no timestamp has been supplied means # we use the last known if self.bytes == 0: self.setTimestamp(self._lastDelta, True) else: if not new.continuation: self.setTimestamp(new.timestamp, not new.full) self._bodyRemaining = self.header.bodyLength - self.bytes return old
def mergeHeader(self, new): """ Merge a new header with the current one and return the result. This allows subclasses to override this behaviour if necessary. @param new: The L{header.Header} to be merged. @rtype: L{header.Header}. """ return header.merge(self.header, new)
def merge(self, **kwargs): """ Generates a relative header and with the same channelId on each call. """ import copy h = copy.copy(self.absolute) for k, v in kwargs.items(): setattr(h, k, v) return header.merge(self.absolute, h)