How to use the pyatv.dmap.parser.parse function in pyatv

To help you get started, we’ve selected a few pyatv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_simple_pprint(self):
        elem = tags.uint8_tag('uuu8', 12)
        inner = tags.container_tag('conb', elem)
        in_data = tags.container_tag('cona', inner)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(parser.pprint(parsed, lookup_tag),
                         'cona: [container, container]\n' +
                         '  conb: [container, container 2]\n' +
                         '    uuu8: 12 [uint, uint8]\n')
github postlund / pyatv / tests / fake_daap_atv.py View on Github external
def handle_remote_button(self, request):
        """Handle remote control buttons."""
        self._verify_auth_parameters(request)
        content = yield from request.content.read()
        parsed = parser.parse(content, tag_definitions.lookup_tag)
        self.last_button_pressed = self._convert_button(parsed)
        self.buttons_press_count += 1
        return web.Response(status=200)
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_extract_simplified_container(self):
        elem = tags.uint8_tag('uuu8', 12)
        inner = tags.container_tag('conb', elem)
        in_data = tags.container_tag('cona', inner)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(12, parser.first(parsed, 'cona', 'conb', 'uuu8'))
github postlund / pyatv / tests / fake_daap_atv.py View on Github external
def perform_pairing(self, pairing_response, port):
        """Pair with a remote client.

        This will perform a GET-request to the specified port and hand over
        information to the client (pyatv) so that the pairing process can be
        completed.
        """
        server = 'http://127.0.0.1:{}'.format(port)
        url = '{}/pairing?pairingcode={}&servicename=test'.format(
            server, pairing_response.pairing_code)
        data, _ = yield from utils.simple_get(url, self.loop)

        # Verify content returned in pairingresponse
        parsed = parser.parse(data, tag_definitions.lookup_tag)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmpg'), 1)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmnm'),
                            pairing_response.remote_name)
        self.tc.assertEqual(parser.first(parsed, 'cmpa', 'cmty'), 'ipod')
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_value_in_container(self):
        in_data = tags.container_tag('cona',
                                     tags.uint8_tag('uuu8', 36) +
                                     tags.uint16_tag('uu16', 13000))
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(1, len(parsed))
        inner = parser.first(parsed, 'cona')
        self.assertEqual(2, len(inner))
        self.assertEqual(36, parser.first(inner, 'uuu8'))
        self.assertEqual(13000, parser.first(inner, 'uu16'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_strings(self):
        in_data = tags.string_tag('stra', '') + \
                  tags.string_tag('strb', 'test string')
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(2, len(parsed))
        self.assertEqual('', parser.first(parsed, 'stra'))
        self.assertEqual('test string', parser.first(parsed, 'strb'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_bool(self):
        in_data = tags.bool_tag('bola', True) + \
                  tags.bool_tag('bolb', False)
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(2, len(parsed))
        self.assertTrue(parser.first(parsed, 'bola'))
        self.assertFalse(parser.first(parsed, 'bolb'))
github postlund / pyatv / tests / dmap / test_parser.py View on Github external
def test_parse_binary_plist(self):
        data = {"key": "value"}
        in_data = tags.raw_tag(
            'plst', plistlib.dumps(data, fmt=plistlib.FMT_BINARY))
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(1, len(parsed))
        self.assertEqual(data, parser.first(parsed, 'plst'))
github postlund / pyatv / pyatv / dmap / daap.py View on Github external
async def _do(self, action, retry=True, is_login=False, is_daap=True):
        resp, status = await action()
        if is_daap:
            resp = parser.parse(resp, lookup_tag)

        self._log_response(str(action.__name__) + ': %s', resp, is_daap)
        if 200 <= status < 300:
            return resp

        if not is_login:
            # If a request fails, try to login again before retrying
            _LOGGER.info('implicitly logged out, logging in again')
            await self.login()

        # Retry once if we got a bad response, otherwise bail out
        if retry:
            return (await self._do(
                action, False, is_login=is_login, is_daap=is_daap))

        raise exceptions.AuthenticationError(