def parseMessage(rawMessage, oobFDs): """ Parses the raw binary message and returns a L{DBusMessage} subclass. Unmarshalling DBUS 'h' (UNIX_FD) gets the FDs from the oobFDs list. @type rawMessage: C{str} @param rawMessage: Raw binary message to parse @rtype: L{DBusMessage} subclass @returns: The L{DBusMessage} subclass corresponding to the contained message """ lendian = rawMessage[0] == b'l'[0] nheader, hval = marshal.unmarshal( _headerFormat, rawMessage, 0, lendian, oobFDs, ) messageType = hval[1] if messageType not in _mtype: raise error.MarshallingError( 'Unknown Message Type: ' + str(messageType) ) m = object.__new__(_mtype[messageType]) m.rawHeader = rawMessage[:nheader] npad = nheader % 8 and (8 - nheader % 8) or 0 m.rawPadding = rawMessage[nheader: nheader + npad] m.rawBody = rawMessage[nheader + npad:] m.serial = hval[5] for code, v in hval[6]: try: setattr(m, _hcode[code], v) except KeyError: pass if m.signature: nbytes, m.body = marshal.unmarshal( m.signature, m.rawBody, lendian=lendian, oobFDs=oobFDs, ) return m
def check(self, sig, expected_value, encoding): nbytes, value = m.unmarshal(sig, encoding, 0) self.assertEquals( nbytes, len(encoding), "Unmarshalling length mismatch. Expected %d bytes consumed. Got %d" % (len(encoding), nbytes)) self.assertTrue( check_equal([expected_value], value), 'Value mismatch. Expected: "%s". Got: "%s"' % (repr(expected_value), repr(value)))
def check(self, sig, expected_value, encoding): nbytes, value = m.unmarshal( sig, encoding, 0 ) self.assertEquals( nbytes, len(encoding), "Unmarshalling length mismatch. Expected %d bytes consumed. Got %d" % (len(encoding), nbytes) ) self.assertTrue( check_equal([expected_value], value), 'Value mismatch. Expected: "%s". Got: "%s"' % (repr(expected_value), repr(value)))