コード例 #1
0
ファイル: TransporLayer.py プロジェクト: businka/Bubot_Core
    def _prepare_request(self,
                         operation,
                         to,
                         data=None,
                         *,
                         secure=False,
                         multicast=False,
                         query=None,
                         **kwargs):
        # secure = kwargs.get('secure', False)
        # multicast = kwargs.get('multicast', False)
        scheme = 'coaps' if secure else 'coap'
        family = to['family']

        request = Request()
        request.type = NON
        request.scheme = scheme
        request.multicast = multicast
        request.family = family
        request.source = (to['net_interface'], None)

        if multicast:
            request.destination = (self.coap_discovery[family][0],
                                   self.coap_discovery_port)
        else:
            request.destination = to[scheme]

        request.code = self.map_crudn_to_coap_code(operation)
        request.uri_path = to.get('href', '')

        option = Option()
        option.number = defines.OptionRegistry.CONTENT_TYPE.number
        option.value = 10000
        request.add_option(option)

        # request.accept = 10000

        # query = kwargs.get('query')
        if query:
            request.query = query

        if data:
            request.encode_payload(data)
        return request
コード例 #2
0
    async def test_device_self_post_request(self):
        defines.EXCHANGE_LIFETIME = 2
        device0 = Device.init_from_file(
            di='10000000-0000-0000-0000-000000000001',
            class_name='EchoDevice',
            path=self.config_path)
        await wait_run_device(device0)

        address = list(device0.transport_layer.eps_coap_ipv4.keys())[0]
        request = Request()
        # request.token = _token
        # request.query = {'owned': ['TRUE']}
        request.type = NON
        request.code = Code.POST
        request.uri_path = '/oic/sec/doxm'
        request.content_type = 10000
        request.source = (
            address,
            list(device0.transport_layer.eps_coap_ipv4[address].keys())[0])
        # request.multicast = True
        # request.family = _msg.family
        request.encode_payload({'oxmsel': 0})
        request.scheme = 'coap'
        request.destination = (
            address,
            list(device0.transport_layer.eps_coap_ipv4[address].keys())[0])
        # request.destination = (address, 5683)
        res2 = await device0.transport_layer.coap.send_message(request)
        links = res2.decode_payload()
        await asyncio.sleep(15)
        await device0.stop()
        self.assertGreater(len(links), 7)
        link = links[0]
        self.assertIn('href', link)
        self.assertIn('eps', link)
        pass