Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def message(self, event):
"""
Sends a message to the subscription.
"""
if self.name not in self.session.subscriptions:
raise EventError(c.ERR_SUBSCRIPTION_NOT_FOUND)
message_data = event.data.get('data')
result = await self.on_message(message_data)
if 'data' in result:
if event:
await event.send_ok(result['data'])
async def full_process(self):
"""
Fully process an event and return whether it was successful.
"""
try:
return await self.process()
except EventError as e:
await self.send_error(e.error, data=e.data)
return False
async def perform_service_request(self, service_event, extra_data={},
error_message=None, raise_error=True):
if service_event in self.service_config:
url = self.service_config[service_event]
data = self.prepare_service_data()
data.update(extra_data)
result = await http_post(self.shark, url, data)
if raise_error and result.get('status') != 'ok':
raise EventError(result.get('error', error_message or
c.ERR_UNHANDLED_EXCEPTION),
data=result.get('data'))
return result
return {'status': 'ok'}