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 = dmap.parse(in_data, lookup_tag) self.assertEqual(dmap.pprint(parsed, lookup_tag), 'cona: [container, container]\n' + ' conb: [container, container 2]\n' + ' uuu8: 12 [uint, uint8]\n')
def handle_playstatus(self, request): """Handler for playstatus (currently playing) requests.""" self._verify_auth_parameters(request) body = b'' playing = self.responses['playing'] if playing.paused is not None: body += tags.uint32_tag('caps', 3 if playing.paused else 4) if playing.title is not None: body += tags.string_tag('cann', playing.title) if playing.artist is not None: body += tags.string_tag('cana', playing.artist) if playing.album is not None: body += tags.string_tag('canl', playing.album) if playing.total_time is not None: total_time = playing.total_time * 1000 # sec -> ms body += tags.uint32_tag('cast', total_time) if playing.position is not None: pos = (playing.total_time - playing.position) body += tags.uint32_tag('cant', pos * 1000) # sec -> ms if playing.mediakind is not None: body += tags.uint32_tag('cmmk', playing.mediakind) if playing.playstatus is not None: body += tags.uint32_tag('caps', playing.playstatus) return web.Response(body=tags.container_tag('cmst', body), status=200)
def handle_login(self, request): """Handler for login requests.""" self._verify_headers(request) self._verify_auth_parameters(request, check_session=False) data = self.responses['login'] mlid = tags.uint32_tag('mlid', data.session) mlog = tags.container_tag('mlog', mlid) return web.Response(body=mlog, status=data.status)
def test_parse_value_in_container(self): in_data = tags.container_tag('cona', tags.uint8_tag('uuu8', 36) + tags.uint16_tag('uu16', 13000)) parsed = dmap.parse(in_data, lookup_tag) self.assertEqual(1, len(parsed)) inner = dmap.first(parsed, 'cona') self.assertEqual(2, len(inner)) self.assertEqual(36, dmap.first(inner, 'uuu8')) self.assertEqual(13000, dmap.first(inner, 'uu16'))
def handle_playstatus(self, request): """Handler for playstatus (currently playing) requests.""" self._verify_auth_parameters(request) body = b'' playing = self._get_response('playing') # Make sure revision matches revision = int(request.rel_url.query['revision-number']) if playing.revision != revision: # Not a valid response as a real device, just to make tests fail return web.Response(status=500) if playing.paused is not None: body += tags.uint32_tag('caps', 3 if playing.paused else 4) if playing.title is not None: body += tags.string_tag('cann', playing.title) if playing.artist is not None: body += tags.string_tag('cana', playing.artist) if playing.album is not None: body += tags.string_tag('canl', playing.album) if playing.total_time is not None: total_time = playing.total_time * 1000 # sec -> ms body += tags.uint32_tag('cast', total_time) if playing.position is not None: pos = (playing.total_time - playing.position) body += tags.uint32_tag('cant', pos*1000) # sec -> ms if playing.mediakind is not None: body += tags.uint32_tag('cmmk', playing.mediakind) if playing.playstatus is not None: body += tags.uint32_tag('caps', playing.playstatus) if playing.repeat is not None: body += tags.uint8_tag('carp', playing.repeat) body += tags.uint8_tag('cash', playing.shuffle) body += tags.uint32_tag('cmsr', playing.revision + 1) return web.Response( body=tags.container_tag('cmst', body), status=200)
def handle_request(self, request): """Respond to request if PIN is correct.""" service_name = request.rel_url.query['servicename'] received_code = request.rel_url.query['pairingcode'].lower() _LOGGER.info('Got pairing request from %s with code %s', service_name, received_code) if self._verify_pin(received_code): cmpg = tags.uint64_tag('cmpg', 1) cmnm = tags.string_tag('cmnm', self._name) cmty = tags.string_tag('cmty', 'ipod') response = tags.container_tag('cmpa', cmpg + cmnm + cmty) self.has_paired = True return web.Response(body=response) # Code did not match, generate an error return web.Response(status=500)
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 = dmap.parse(in_data, lookup_tag) self.assertEqual(12, dmap.first(parsed, 'cona', 'conb', 'uuu8'))