Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def data_received(self, data):
self.buffer += data
while self.buffer:
length, raw = variant.read_variant(self.buffer)
if len(raw) < length:
return
data = raw[:length]
self.buffer = raw[length:]
parsed = protobuf.ProtocolMessage()
parsed.ParseFromString(data)
_LOGGER.info('Incoming message: %s', parsed)
try:
def unhandled_message(message):
_LOGGER.warning('No message handler for %s', message)
self.mapping.get(parsed.type, unhandled_message)(parsed)
except Exception:
_LOGGER.exception('Error while dispatching message')
def set_active_player(self, identifier):
if identifier not in self.states:
raise Exception('invalid player: %s', identifier)
now_playing = messages.create(
protobuf.SET_NOW_PLAYING_CLIENT_MESSAGE)
client = now_playing.inner().client
client.bundleIdentifier = identifier
self._send(now_playing)
def __init__(self, testcase, loop):
super().__init__(testcase)
self.loop = loop
self.app.on_startup.append(self.start)
self.outstanding_keypresses = set() # Pressed but not released
self.last_button_pressed = None
self.connection_state = None
self.states = {}
self.server = None
self.buffer = b''
self.transport = None
self.mapping = {
protobuf.DEVICE_INFO_MESSAGE: self.handle_device_info,
protobuf.CRYPTO_PAIRING_MESSAGE: self.handle_crypto_pairing,
protobuf.SET_CONNECTION_STATE_MESSAGE:
self.handle_set_connection_state,
protobuf.CLIENT_UPDATES_CONFIG_MESSAGE:
self.handle_client_updates_config_message,
protobuf.GET_KEYBOARD_SESSION_MESSAGE:
self.handle_get_keyboard_session_message,
protobuf.SEND_HID_EVENT_MESSAGE:
self.handle_send_hid_event_message,
protobuf.SEND_COMMAND_MESSAGE:
self.handle_send_command_message,
}
def handle_get_keyboard_session_message(self, message):
_LOGGER.debug('Get keyboard session')
# This message has a lot more fields, but pyatv currently
# not use them so ignore for now
resp = messages.create(protobuf.KEYBOARD_MESSAGE)
resp.identifier = message.identifier
self._send(resp)
self.outstanding_keypresses = set() # Pressed but not released
self.last_button_pressed = None
self.connection_state = None
self.states = {}
self.server = None
self.buffer = b''
self.transport = None
self.mapping = {
protobuf.DEVICE_INFO_MESSAGE: self.handle_device_info,
protobuf.CRYPTO_PAIRING_MESSAGE: self.handle_crypto_pairing,
protobuf.SET_CONNECTION_STATE_MESSAGE:
self.handle_set_connection_state,
protobuf.CLIENT_UPDATES_CONFIG_MESSAGE:
self.handle_client_updates_config_message,
protobuf.GET_KEYBOARD_SESSION_MESSAGE:
self.handle_get_keyboard_session_message,
protobuf.SEND_HID_EVENT_MESSAGE:
self.handle_send_hid_event_message,
protobuf.SEND_COMMAND_MESSAGE:
self.handle_send_command_message,
}
def __init__(self, testcase, loop):
super().__init__(testcase)
self.loop = loop
self.app.on_startup.append(self.start)
self.outstanding_keypresses = set() # Pressed but not released
self.last_button_pressed = None
self.connection_state = None
self.states = {}
self.server = None
self.buffer = b''
self.transport = None
self.mapping = {
protobuf.DEVICE_INFO_MESSAGE: self.handle_device_info,
protobuf.CRYPTO_PAIRING_MESSAGE: self.handle_crypto_pairing,
protobuf.SET_CONNECTION_STATE_MESSAGE:
self.handle_set_connection_state,
protobuf.CLIENT_UPDATES_CONFIG_MESSAGE:
self.handle_client_updates_config_message,
protobuf.GET_KEYBOARD_SESSION_MESSAGE:
self.handle_get_keyboard_session_message,
protobuf.SEND_HID_EVENT_MESSAGE:
self.handle_send_hid_event_message,
protobuf.SEND_COMMAND_MESSAGE:
self.handle_send_command_message,
}
def __init__(self, testcase, loop):
super().__init__(testcase)
self.loop = loop
self.app.on_startup.append(self.start)
self.outstanding_keypresses = set() # Pressed but not released
self.last_button_pressed = None
self.connection_state = None
self.states = {}
self.server = None
self.buffer = b''
self.transport = None
self.mapping = {
protobuf.DEVICE_INFO_MESSAGE: self.handle_device_info,
protobuf.CRYPTO_PAIRING_MESSAGE: self.handle_crypto_pairing,
protobuf.SET_CONNECTION_STATE_MESSAGE:
self.handle_set_connection_state,
protobuf.CLIENT_UPDATES_CONFIG_MESSAGE:
self.handle_client_updates_config_message,
protobuf.GET_KEYBOARD_SESSION_MESSAGE:
self.handle_get_keyboard_session_message,
protobuf.SEND_HID_EVENT_MESSAGE:
self.handle_send_hid_event_message,
protobuf.SEND_COMMAND_MESSAGE:
self.handle_send_command_message,
}
def command(cmd):
"""Playback command request."""
message = create(protobuf.SEND_COMMAND_MESSAGE)
send_command = message.inner()
send_command.command = cmd
return message
def _handle_message(self, data):
if self._chacha:
data = self._chacha.decrypt(data)
log_binary(_LOGGER, '<< Receive', Decrypted=data)
parsed = protobuf.ProtocolMessage()
parsed.ParseFromString(data)
_LOGGER.debug('<< Receive: Protobuf=%s', parsed)
if self.listener:
self.listener.message_received(parsed, data)
def __init__(self, loop, credentials, atv_device_id):
"""Initialize a new instance of ProxyMrpAppleTV."""
self.loop = loop
self.credentials = credentials
self.atv_device_id = atv_device_id
self.server = None
self.buffer = b''
self.has_paired = False
self.transport = None
self.chacha = None
self.connection = None
self.input_key = None
self.output_key = None
self.mapping = {
protobuf.DEVICE_INFO_MESSAGE: self.handle_device_info,
protobuf.CRYPTO_PAIRING_MESSAGE: self.handle_crypto_pairing,
}
self._shared = None
self._session_key = None
self._signing_key = SigningKey(32 * b'\x01')
self._auth_private = self._signing_key.to_seed()
self._auth_public = self._signing_key.get_verifying_key().to_bytes()
self._verify_private = curve25519.Private(secret=32 * b'\x01')
self._verify_public = self._verify_private.get_public()
self.context = SRPContext(
'Pair-Setup', str(1111),
prime=constants.PRIME_3072,
generator=constants.PRIME_3072_GEN,
hash_func=hashlib.sha512,
bits_salt=128)