Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'))
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.genre is not None:
body += tags.string_tag('cang', playing.genre)
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:
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.genre is not None:
body += tags.string_tag('cang', playing.genre)
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)
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.genre is not None:
body += tags.string_tag('cang', playing.genre)
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:
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.genre is not None:
body += tags.string_tag('cang', playing.genre)
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:
async 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', int(self._pairing_guid, 16))
cmnm = tags.string_tag('cmnm', self._name)
cmty = tags.string_tag('cmty', 'iPhone')
response = tags.container_tag('cmpa', cmpg + cmnm + cmty)
self._has_paired = True
self.service.credentials = '0x' + self._pairing_guid
return web.Response(body=response)
# Code did not match, generate an error
return web.Response(status=500)
def _move(direction, time, point1, point2):
data = 'touch{0}&time={1}&point={2},{3}'.format(
direction, time, point1, point2)
return tags.uint8_tag('cmcc', 0x30) + tags.string_tag('cmbe', data)
async 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', int(self._pairing_guid, 16))
cmnm = tags.string_tag('cmnm', self._name)
cmty = tags.string_tag('cmty', 'iPhone')
response = tags.container_tag('cmpa', cmpg + cmnm + cmty)
self._has_paired = True
self.service.credentials = '0x' + self._pairing_guid
return web.Response(body=response)
# Code did not match, generate an error
return web.Response(status=500)