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 decrypt_loop(client, body):
while True:
try:
logger.info("Trying to decrypt sync")
return decryption_method(body, ignore_failures=False)
except EncryptionError:
logger.info("Error decrypting sync, waiting for next pan " "sync")
await client.synced.wait(),
logger.info("Pan synced, retrying decryption.")
async def decrypt_loop(client, body):
while True:
try:
logger.info("Trying to decrypt sync")
return decryption_method(body, ignore_failures=False)
except EncryptionError:
logger.info("Error decrypting sync, waiting for next pan " "sync")
await client.synced.wait(),
logger.info("Pan synced, retrying decryption.")
try:
return await asyncio.wait_for(
decrypt_loop(client, body), timeout=self.decryption_timeout
)
except asyncio.TimeoutError:
logger.info("Decryption attempt timed out, decrypting with " "failures")
return decryption_method(body, ignore_failures=True)
async def decrypt_loop(client, body):
while True:
try:
logger.info("Trying to decrypt sync")
return decryption_method(body, ignore_failures=False)
except EncryptionError:
logger.info("Error decrypting sync, waiting for next pan " "sync")
await client.synced.wait(),
logger.info("Pan synced, retrying decryption.")
def message_callback(self):
try:
message = self.receive_queue.get_nowait()
except Empty:
return True
logger.debug(f"UI loop received message {message}")
if isinstance(message, UpdateDevicesMessage):
self.device_if.update_devices(message)
elif isinstance(message, UpdateUsersMessage):
self.control_if.update_users(message)
elif isinstance(message, UnverifiedDevicesSignal):
self.control_if.UnverifiedDevices(
message.pan_user, message.room_id, message.room_display_name
)
if self.notifications:
self.unverified_notification(message)
elif isinstance(message, InviteSasSignal):
async def decrypt_loop(client, body):
while True:
try:
logger.info("Trying to decrypt sync")
return decryption_method(body, ignore_failures=False)
except EncryptionError:
logger.info("Error decrypting sync, waiting for next pan " "sync")
await client.synced.wait(),
logger.info("Pan synced, retrying decryption.")
def run(self):
self.loop = GLib.MainLoop()
if self.config.notifications:
try:
notify2.init("pantalaimon", mainloop=self.loop)
self.notifications = True
except dbus.DBusException:
logger.error(
"Notifications are enabled but no notification "
"server could be found, disabling notifications."
)
self.notifications = False
GLib.timeout_add(100, self.message_callback)
self.loop.run()
def _load_context(self, user, event, before, after):
context = {}
if before > 0:
query = (
Event.select()
.join(UserMessages)
.where(
(Event.date <= event.date)
& (Event.room_id == event.room_id)
& (Event.id != event.id)
& (UserMessages.user == user)
)
.order_by(Event.date.desc())
.limit(before)
)
context["events_before"] = [e.source for e in query]
else:
context["events_before"] = []
if after > 0:
query = (
Event.select()
.join(UserMessages)
.order_by(Event.date.desc())
.limit(before)
)
context["events_before"] = [e.source for e in query]
else:
context["events_before"] = []
if after > 0:
query = (
Event.select()
.join(UserMessages)
.where(
(Event.date >= event.date)
& (Event.room_id == event.room_id)
& (Event.id != event.id)
& (UserMessages.user == user)
)
.order_by(Event.date)
.limit(after)
)
context["events_after"] = [e.source for e in query]
else:
context["events_after"] = []
return context
(Event.date <= event.date)
& (Event.room_id == event.room_id)
& (Event.id != event.id)
& (UserMessages.user == user)
)
.order_by(Event.date.desc())
.limit(before)
)
context["events_before"] = [e.source for e in query]
else:
context["events_before"] = []
if after > 0:
query = (
Event.select()
.join(UserMessages)
.where(
(Event.date >= event.date)
& (Event.room_id == event.room_id)
& (Event.id != event.id)
& (UserMessages.user == user)
)
.order_by(Event.date)
.limit(after)
)
context["events_after"] = [e.source for e in query]
else:
context["events_after"] = []
return context
def _load_context(self, user, event, before, after):
context = {}
if before > 0:
query = (
Event.select()
.join(UserMessages)
.where(
(Event.date <= event.date)
& (Event.room_id == event.room_id)
& (Event.id != event.id)
& (UserMessages.user == user)
)
.order_by(Event.date.desc())
.limit(before)
)
context["events_before"] = [e.source for e in query]
else:
context["events_before"] = []
if after > 0:
query = (
Event.select()
.join(UserMessages)
.where(