def wrapBool(self, bool):
     value = bytearray()
     if bool:
         code = AMQPType.BOOLEAN_TRUE
     else:
         code = AMQPType.BOOLEAN_FALSE
     return TLVFixed(code, value)
 def wrapUShort(self, sh):
     if sh < 0:
         raise ValueError('negative value of ' + str(sh) +
                          ' cannot be assignet to UShort type')
     data = bytearray()
     data = util.addShort(data, sh)
     return TLVFixed(AMQPType.USHORT, data)
예제 #3
0
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()
        if self.handle == None:
            raise ValueError("Transfer header's handle can't be null")
        list.addElement(0, wrapper.wrap(self.handle))
        if self.deliveryId is not None:
            list.addElement(1, wrapper.wrap(self.deliveryId))
        if self.deliveryTag is not None:
            list.addElement(2, wrapper.wrap(self.deliveryTag))
        if self.messageFormat is not None and isinstance(
                self.messageFormat, AMQPMessageFormat):
            list.addElement(3, wrapper.wrap(self.messageFormat.encode()))
        if self.settled is not None:
            list.addElement(4, wrapper.wrap(self.settled))
        if self.more is not None:
            list.addElement(5, wrapper.wrap(self.more))
        if self.rcvSettleMode is not None and isinstance(
                self.rcvSettleMode, ReceiveCode):
            list.addElement(6, wrapper.wrap(self.rcvSettleMode.value))
        if self.state is not None and isinstance(self.state, AMQPState):
            list.addElement(7, wrapper.wrap(self.state.toArgumentsList()))
        if self.resume is not None:
            list.addElement(8, wrapper.wrap(self.resume))
        if self.aborted is not None:
            list.addElement(9, wrapper.wrap(self.aborted))
        if self.batchable is not None:
            list.addElement(10, wrapper.wrap(self.batchable))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
예제 #4
0
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()
        if self.remoteChannel is not None:
            list.addElement(0, wrapper.wrap(self.remoteChannel))
        if self.nextOutgoingId is None:
            raise ValueError("Begin header's next-outgoing-id can't be null")
        list.addElement(1, wrapper.wrap(self.nextOutgoingId))
        if self.incomingWindow is None:
            raise ValueError("Begin header's incoming-window can't be null")
        list.addElement(2, wrapper.wrap(self.incomingWindow))
        if self.outgoingWindow is None:
            raise ValueError("Begin header's outgoing-window can't be null")
        list.addElement(3, wrapper.wrap(self.outgoingWindow))
        if self.handleMax is not None:
            list.addElement(4, wrapper.wrap(self.handleMax))
        if self.offeredCapabilities is not None and len(
                self.offeredCapabilities) > 0:
            list.addElement(5, wrapper.wrapArray(self.offeredCapabilities))
        if self.desiredCapabilities is not None and len(
                self.desiredCapabilities) > 0:
            list.addElement(6, wrapper.wrapArray(self.desiredCapabilities))
        if self.properties is not None and len(self.properties) > 0:
            list.addElement(7, wrapper.wrapMap(self.properties))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None,None)
        wrapper = AMQPWrapper()
        if self.containerId is None:
            raise ValueError("Detach header's container id can't be null")
        list.addElement(0, wrapper.wrap(self.containerId))
        if self.hostname is not None:
            list.addElement(1, wrapper.wrap(self.hostname))
        if self.maxFrameSize is not None:
            list.addElement(2, wrapper.wrap(self.maxFrameSize))
        if self.channelMax is not None:
            list.addElement(3, wrapper.wrap(self.channelMax))
        if self.idleTimeout is not None:
            list.addElement(4, wrapper.wrap(self.idleTimeout))
        if self.outgoingLocales is not None and len(self.outgoingLocales) > 0:
            list.addElement(5, wrapper.wrapArray(self.outgoingLocales))
        if self.incomingLocales is not None and len(self.incomingLocales) > 0:
            list.addElement(6, wrapper.wrapArray(self.incomingLocales))
        if self.offeredCapabilities is not None and len(self.offeredCapabilities) > 0:
            list.addElement(7, wrapper.wrapArray(self.offeredCapabilities))
        if self.desiredCapabilities is not None and len(self.desiredCapabilities) > 0:
            list.addElement(8, wrapper.wrapArray(self.desiredCapabilities))
        if self.properties is not None and len(self.properties) > 0:
            list.addElement(9, wrapper.wrapMap(self.properties))

        constructor = DescribedConstructor(list.getCode(),TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        #print('AMQPOpen list.values= ' + str(list.values))
        return list
 def wrapTimestamp(self, stamp):
     if stamp is None:
         raise ValueError('Wrapper cannot wrap timestamp null')
     data = bytearray()
     ts = (stamp - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(
         1, 's')
     data = util.addLong(data, ts)
     return TLVFixed(AMQPType.TIMESTAMP, data)
 def getList(self):
     list = TLVList(None, None)
     if isinstance(self.code, LifetimePolicy):
         constructor = DescribedConstructor(
             list.getCode(), TLVFixed(AMQPType.SMALL_ULONG,
                                      self.code.value))
         list.setConstructor(constructor)
     return list
예제 #8
0
    def toArgumentsList(self):
        list = TLVList(None,None)
        if self.error is not None and isinstance(self.error, AMQPError):
            list.addElement(0, self.error.toArgumentsList())

        constructor = DescribedConstructor(list.getCode(),TLVFixed(AMQPType.SMALL_ULONG, 0x25))
        list.setConstructor(constructor)
        return list
 def wrapLong(self, l):
     value = self.convertULong(l)
     code = None
     if len(value) > 1:
         code = AMQPType.LONG
     else:
         code = AMQPType.SMALL_LONG
     return TLVFixed(code, value)
 def wrapInt(self, i):
     value = self.convertUInt(i)
     code = None
     if len(value) > 0:
         code = AMQPType.INT
     else:
         code = AMQPType.SMALL_INT
     return TLVFixed(code, value)
    def toArgumentsList(self):
        list = TLVList(None, None)

        if self.mechanisms == None:
            raise ValueError("At least one SASL Mechanism must be specified")
        wrapper = AMQPWrapper()
        list.addElement(0, wrapper.wrapArray(self.mechanisms))
        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, 0x40))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None, None)

        if self.challenge == None:
            raise ValueError("SASL-Challenge header's challenge can't be null")
        list.addElement(0, AMQPWrapper.wrap(self.challenge))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, 0x42))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()
        if self.nextIncomingId is not None:
            list.addElement(0, wrapper.wrap(self.nextIncomingId))
        if self.incomingWindow is None:
            raise ValueError("Flow header's incoming-window can't be null")
        list.addElement(1, wrapper.wrap(self.incomingWindow))
        if self.nextOutgoingId is None:
            raise ValueError("Flow header's next-outgoing-id can't be null")
        list.addElement(2, wrapper.wrap(self.nextOutgoingId))
        if self.outgoingWindow is None:
            raise ValueError("Flow header's outgoing-window can't be null")
        list.addElement(3, wrapper.wrap(self.outgoingWindow))
        if self.handle is not None:
            list.addElement(4, wrapper.wrap(self.handle))
        if self.deliveryCount is not None:
            if self.handle is not None:
                list.addElement(5, wrapper.wrap(self.deliveryCount))
            else:
                raise ValueError(
                    "Flow headers delivery-count can't be assigned when handle is not specified"
                )
        if self.linkCredit is not None:
            if self.handle is not None:
                list.addElement(6, wrapper.wrap(self.linkCredit))
            else:
                raise ValueError(
                    "Flow headers link-credit can't be assigned when handle is not specified"
                )
        if self.available is not None:
            if self.handle is not None:
                list.addElement(7, wrapper.wrap(self.available))
            else:
                raise ValueError(
                    "Flow headers available can't be assigned when handle is not specified"
                )
        if self.drain is not None:
            if self.handle is not None:
                list.addElement(8, wrapper.wrap(self.drain))
            else:
                raise ValueError(
                    "Flow headers drain can't be assigned when handle is not specified"
                )
        if self.echo is not None:
            list.addElement(9, wrapper.wrap(self.echo))
        if self.properties is not None and len(self.properties) > 0:
            list.addElement(10, wrapper.wrapMap(self.properties))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
 def wrapUInt(self, i):
     if i < 0:
         raise ValueError('Error negative value of ' + str(i) +
                          ' cannot be assigned to UINT type')
     value = self.convertUInt(i)
     code = None
     if len(value) == 0:
         code = AMQPType.UINT_0
     elif len(value) == 1:
         code = AMQPType.SMALL_UINT
     elif len(value) > 1:
         code = AMQPType.UINT
     return TLVFixed(code, value)
예제 #15
0
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()

        if self.name is None:
            raise ValueError("Attach header's name can't be null")
        list.addElement(0, wrapper.wrapString(self.name))

        if self.handle is None:
            raise ValueError("Attach header's handle can't be null")
        list.addElement(1, wrapper.wrap(self.handle))

        if self.role is None:
            raise ValueError("Attach header's role can't be null")

        list.addElement(2, wrapper.wrap(self.role.value))
        if self.sndSettleMode is not None:
            list.addElement(3, wrapper.wrap(self.sndSettleMode))
        if self.rcvSettleMode is not None:
            list.addElement(4, wrapper.wrap(self.rcvSettleMode))
        if self.source is not None and isinstance(self.source, AMQPSource):
            list.addElement(5, self.source.toArgumentsList())
        if self.target is not None and isinstance(self.target, AMQPTarget):
            list.addElement(6, self.target.toArgumentsList())
        if self.unsettled is not None and len(self.unsettled) > 0:
            list.addElement(7, wrapper.wrapMap(self.unsettled))
        if self.incompleteUnsettled is not None:
            list.addElement(8, wrapper.wrap(self.incompleteUnsettled))

        if self.initialDeliveryCount is not None:
            list.addElement(9, wrapper.wrap(self.initialDeliveryCount))
        elif self.role == RoleCode.SENDER:
            raise ValueError(
                "Sender's attach header must contain a non-null initial-delivery-count value"
            )

        if self.maxMessageSize is not None:
            list.addElement(10, wrapper.wrap(self.maxMessageSize))
        if self.offeredCapabilities is not None and len(
                self.offeredCapabilities) > 0:
            list.addElement(11, wrapper.wrapArray(self.offeredCapabilities))
        if self.desiredCapabilities is not None and len(
                self.desiredCapabilities) > 0:
            list.addElement(12, wrapper.wrapArray(self.desiredCapabilities))
        if self.properties is not None and len(self.properties) > 0:
            list.addElement(13, wrapper.wrapMap(self.properties))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None,None)
        wrapper = AMQPWrapper()
        if self.mechanism == None:
            raise ValueError("SASL-Init header's mechanism can't be null")
        list.addElement(0,wrapper.wrap(self.mechanism))
        if self.initialRespone is not None:
            list.addElement(1,wrapper.wrap(self.initialRespone))
        if self.hostName is not None:
            list.addElement(2, wrapper.wrap(self.hostName))

        constructor = DescribedConstructor(list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, 0x41))
        list.setConstructor(constructor)
        return list
 def wrapULong(self, l):
     if l is None:
         raise ValueError('Wrapper cannot wrap ulong null')
     if l < 0:
         raise ValueError('negative value of ' + str(l) +
                          ' cannot be assignet to ULONG type')
     value = self.convertULong(l)
     code = None
     if len(value) == 0:
         code = AMQPType.ULONG_0
     elif len(value) == 1:
         code = AMQPType.SMALL_ULONG
     else:
         code = AMQPType.ULONG
     return TLVFixed(code, value)
    def toArgumentsList(self):
        list = TLVList(None, None)

        if self.outcomeCode == None and isinstance(self.outcomeCode,
                                                   OutcomeCode):
            raise ValueError("SASL-Outcome header's code can't be null")
        list.addElement(0, AMQPWrapper.wrap(self.outcomeCode.value))

        if self.additionalData is not None:
            list.addElement(1, AMQPWrapper.wrap(self.additionalData))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, 0x44))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()
        if self.handle is None:
            raise ValueError("Detach header's handle can't be null")
        list.addElement(0, wrapper.wrap(self.handle))
        if self.closed is not None:
            list.addElement(1, wrapper.wrap(self.closed))
        if self.error is not None and isinstance(self.error, AMQPError):
            list.addElement(2, self.error.toArgumentsList())

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
    def toArgumentsList(self):
        list = TLVList(None, None)
        wrapper = AMQPWrapper()
        if self.role is None:
            raise ValueError("Disposition header's role can't be null")
        if isinstance(self.role, RoleCode):
            list.addElement(0, wrapper.wrap(self.role.value))
        if self.first is None:
            raise ValueError("Disposition header's first can't be null")
        list.addElement(1, wrapper.wrap(self.first))
        if self.last is not None:
            list.addElement(2, wrapper.wrap(self.last))
        if self.settled is not None:
            list.addElement(3, wrapper.wrap(self.settled))
        if self.state is not None:
            if isinstance(self.state, AMQPState):
                list.addElement(4, self.state.toArgumentsList())
        if self.batchable is not None and len(self.outgoingLocales) > 0:
            list.addElement(5, wrapper.wrap(self.batchable))

        constructor = DescribedConstructor(
            list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, self.code.value))
        list.setConstructor(constructor)
        return list
 def wrapDecimal128(self, d):
     if d is None:
         raise ValueError('Wrapper cannot wrap decimal128 null')
     if isinstance(d, AMQPDecimal):
         return TLVFixed(AMQPType.DECIMAL_128, d.getValue())
 def wrapUByte(self, bt):
     if bt < 0:
         raise ValueError('Error negative value of ' + str(bt) +
                          ' cannot be assigned to UBYTE type')
     return TLVFixed(AMQPType.UBYTE, bt)
예제 #23
0
    def getElement(self, constructor, buf):
        tlv = None
        code = constructor.getCode()
        if isinstance(code, AMQPType):
            if code == AMQPType.NULL:
                tlv = TLVNull()
            elif code in (AMQPType.BOOLEAN_TRUE, AMQPType.BOOLEAN_FALSE,
                          AMQPType.UINT_0, AMQPType.ULONG_0):
                tlv = TLVFixed(code, bytearray())
            elif code in (AMQPType.BOOLEAN, AMQPType.UBYTE, AMQPType.BYTE,
                          AMQPType.SMALL_UINT, AMQPType.SMALL_INT,
                          AMQPType.SMALL_ULONG, AMQPType.SMALL_LONG):
                value1 = util.getByte(buf, self.index)
                self.index += 1
                tlv = TLVFixed(code, value1)
            elif code in (AMQPType.SHORT, AMQPType.USHORT):
                value2 = buf[self.index:self.index + 2]
                self.index += 2
                tlv = TLVFixed(code, value2)
            elif code in (AMQPType.UINT, AMQPType.INT, AMQPType.FLOAT,
                          AMQPType.DECIMAL_32, AMQPType.CHAR):
                value4 = buf[self.index:self.index + 4]
                self.index += 4
                tlv = TLVFixed(code, value4)
            elif code in (AMQPType.ULONG, AMQPType.LONG, AMQPType.DECIMAL_64,
                          AMQPType.DOUBLE, AMQPType.TIMESTAMP):
                value8 = buf[self.index:self.index + 8]
                self.index += 8
                tlv = TLVFixed(code, value8)
            elif code in (AMQPType.DECIMAL_128, AMQPType.UUID):
                value16 = buf[self.index:self.index + 16]
                self.index += 16
                tlv = TLVFixed(code, value16)
            elif code in (AMQPType.STRING_8, AMQPType.SYMBOL_8,
                          AMQPType.BINARY_8):
                varlen = util.getByte(buf, self.index) & 0xff
                self.index += 1
                varValue8 = buf[self.index:self.index + int(varlen)]
                self.index += int(varlen)
                tlv = TLVVariable(code, varValue8)
            elif code in (AMQPType.STRING_32, AMQPType.SYMBOL_32,
                          AMQPType.BINARY_32):
                var32len = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                varValue32 = buf[self.index:self.index + int(var32len)]
                self.index += int(var32len)
                tlv = TLVVariable(code, varValue32)
            elif code is AMQPType.LIST_0:
                tlv = TLVList(None, None)
            elif code is AMQPType.LIST_8:
                list8size = util.getByte(buf, self.index) & 0xff
                self.index += 1
                list8count = util.getByte(buf, self.index) & 0xff
                self.index += 1
                list8values = []
                for i in range(0, list8count):
                    entity = self.getTlv(buf)
                    list8values.append(entity)
                tlv = TLVList(code, list8values)
            elif code is AMQPType.LIST_32:
                list32size = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                list32count = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                list32values = []
                for i in range(0, list32count):
                    list32values.append(self.getTlv(buf))
                tlv = TLVList(code, list32values)
            elif code is AMQPType.MAP_8:
                map8size = util.getByte(buf, self.index) & 0xff
                self.index += 1
                map8count = util.getByte(buf, self.index) & 0xff
                self.index += 1
                stop8 = self.index + map8size - 1
                map8 = TLVMap(None, None)
                while self.index < stop8:
                    map8.putElement(self.getTlv(buf), self.getTlv(buf))
                tlv = TLVMap(code, map8)
            elif code is AMQPType.MAP_32:
                map32size = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                map32count = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                stop32 = self.index + map32size - 4
                map32 = TLVMap(None, None)
                while self.index < stop32:
                    map32.putElement(self.getTlv(buf), self.getTlv(buf))
                tlv = TLVMap(code, map32)
            elif code is AMQPType.ARRAY_8:
                array8size = util.getByte(buf, self.index) & 0xff
                self.index += 1
                array8count = util.getByte(buf, self.index) & 0xff
                self.index += 1
                arr8 = []
                arr8constructor = self.getConstructor(buf)
                for i in range(0, array8count):
                    arr8.append(self.getElement(arr8constructor, buf))
                tlv = TLVArray(code, arr8)
            elif code is AMQPType.ARRAY_32:
                arr32size = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                arr32count = util.getInt(buf[self.index:self.index + 4])
                self.index += 4
                arr32 = []
                arr32constructor = self.getConstructor(buf)
                for i in range(0, arr32count):
                    arr32.append(self.getElement(arr32constructor, buf))
                tlv = TLVArray(code, arr32)

            if isinstance(constructor, DescribedConstructor):
                tlv.setConstructor(constructor)

            return tlv
 def wrapByte(self, bt):
     return TLVFixed(AMQPType.BYTE, bt)
예제 #25
0
 def toArgumentsList(self):
     list = TLVList(None, None)
     constructor = DescribedConstructor(
         list.getCode(), TLVFixed(AMQPType.SMALL_ULONG, 0x26))
     list.setConstructor(constructor)
     return list
 def wrapUuid(self, uuid):
     if uuid is None:
         raise ValueError('Wrapper cannot wrap uuid null')
     return TLVFixed(AMQPType.UUID, bytes(uuid, 'utf-8'))
 def wrapShort(self, sh):
     data = bytearray()
     data = util.addShort(data, sh)
     return TLVFixed(AMQPType.USHORT, data)
 def wrapDouble(self, db):
     data = bytearray()
     data = util.addDouble(data, db)
     return TLVFixed(AMQPType.DOUBLE, data)
 def wrapFloat(self, f):
     data = bytearray()
     data = util.addFloat(data, f)
     return TLVFixed(AMQPType.FLOAT, data)
 def wrapChar(self, ch):
     data = bytearray()
     data = util.addInt(data, ch)
     return TLVFixed(AMQPType.CHAR, data)