コード例 #1
0
 def encode_amqp_type(amqp_type, test_value):
     """Encode an AMQP type from a stringified test_value"""
     if amqp_type == 'null':
         return None
     if amqp_type == 'boolean':
         return True if test_value == 'True' else False
     if amqp_type == 'ubyte':
         return proton.ubyte(int(test_value, 16))
     if amqp_type == 'ushort':
         return proton.ushort(int(test_value, 16))
     if amqp_type == 'uint':
         return proton.uint(int(test_value, 16))
     if amqp_type == 'ulong':
         return proton.ulong(int(test_value, 16))
     if amqp_type == 'byte':
         return proton.byte(int(test_value, 16))
     if amqp_type == 'short':
         return proton.short(int(test_value, 16))
     if amqp_type == 'int':
         return proton.int32(int(test_value, 16))
     if amqp_type == 'long':
         return _compat.str2long(test_value, 16)
     if amqp_type == 'float':
         return proton.float32(struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0])
     if amqp_type == 'double':
         return struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0]
     if amqp_type == 'decimal32':
         return proton.decimal32(int(test_value[2:], 16))
     if amqp_type == 'decimal64':
         return proton.decimal64(_compat.str2long(test_value[2:], 16))
     if amqp_type == 'decimal128':
         return proton.decimal128(_compat.decode_hex(test_value[2:]))
     if amqp_type == 'char':
         if len(test_value) == 1: # Format 'a'
             return proton.char(test_value)
         return proton.char(_compat.unichr(int(test_value, 16)))
     if amqp_type == 'timestamp':
         return proton.timestamp(int(test_value, 16))
     if amqp_type == 'uuid':
         return uuid.UUID(test_value)
     if amqp_type == 'binary':
         return test_value.encode('utf-8')
     if amqp_type == 'string':
         return _compat.unicode(test_value)
     if amqp_type == 'symbol':
         return proton.symbol(test_value)
     if amqp_type == 'list':
         return AmqpTypesTestSender.encode_amqp_list(test_value)
     if amqp_type == 'map':
         return AmqpTypesTestSender.encode_amqp_map(test_value)
     if amqp_type == 'array':
         #return AmqpTypesTestSender.encode_amqp_array(test_value)
         print('send: Unsupported AMQP type "%s"' % amqp_type)
         return None
     print('send: Unknown AMQP type "%s"' % amqp_type)
     return None
コード例 #2
0
 def update(self, delivery, state=None):
     if state:
         delivery.local.data = [self.id, Described(ulong(state), [])]
         delivery.update(0x34)
コード例 #3
0
 def create_message(self, test_value):
     """
     Creates a single message with the test value translated from its string representation to the appropriate
     AMQP value (set in self.amqp_type).
     """
     if self.amqp_type == 'null':
         return Message(id=(self.sent + 1), body=None)
     elif self.amqp_type == 'boolean':
         return Message(id=(self.sent + 1),
                        body=True if test_value == 'True' else False)
     elif self.amqp_type == 'ubyte':
         return Message(id=(self.sent + 1), body=ubyte(int(test_value, 16)))
     elif self.amqp_type == 'ushort':
         return Message(id=(self.sent + 1),
                        body=ushort(int(test_value, 16)))
     elif self.amqp_type == 'uint':
         return Message(id=(self.sent + 1), body=uint(int(test_value, 16)))
     elif self.amqp_type == 'ulong':
         return Message(id=(self.sent + 1), body=ulong(int(test_value, 16)))
     elif self.amqp_type == 'byte':
         return Message(id=(self.sent + 1), body=byte(int(test_value, 16)))
     elif self.amqp_type == 'short':
         return Message(id=(self.sent + 1), body=short(int(test_value, 16)))
     elif self.amqp_type == 'int':
         return Message(id=(self.sent + 1), body=int32(int(test_value, 16)))
     elif self.amqp_type == 'long':
         return Message(id=(self.sent + 1), body=long(int(test_value, 16)))
     elif self.amqp_type == 'float':
         return Message(id=(self.sent + 1),
                        body=float32(
                            unpack('!f', test_value[2:].decode('hex'))[0]))
     elif self.amqp_type == 'double':
         return Message(id=(self.sent + 1),
                        body=unpack('!d', test_value[2:].decode('hex'))[0])
     elif self.amqp_type == 'decimal32':
         return Message(id=(self.sent + 1),
                        body=decimal32(int(test_value[2:], 16)))
     elif self.amqp_type == 'decimal64':
         l64 = long(test_value[2:], 16)
         return Message(id=(self.sent + 1), body=decimal64(l64))
     elif self.amqp_type == 'decimal128':
         return Message(id=(self.sent + 1),
                        body=decimal128(test_value[2:].decode('hex')))
     elif self.amqp_type == 'char':
         if len(test_value) == 1:  # Format 'a'
             return Message(id=(self.sent + 1), body=char(test_value))
         else:
             val = int(test_value, 16)
             return Message(id=(self.sent + 1), body=char(unichr(val)))
     elif self.amqp_type == 'timestamp':
         return Message(id=(self.sent + 1),
                        body=timestamp(int(test_value, 16)))
     elif self.amqp_type == 'uuid':
         return Message(id=(self.sent + 1), body=UUID(test_value))
     elif self.amqp_type == 'binary':
         return Message(id=(self.sent + 1), body=bytes(test_value))
     elif self.amqp_type == 'string':
         return Message(id=(self.sent + 1), body=unicode(test_value))
     elif self.amqp_type == 'symbol':
         return Message(id=(self.sent + 1), body=symbol(test_value))
     elif self.amqp_type == 'list':
         return Message(id=(self.sent + 1), body=test_value)
     elif self.amqp_type == 'map':
         return Message(id=(self.sent + 1), body=test_value)
     else:
         print 'send: Unsupported AMQP type "%s"' % self.amqp_type
         return None