diff libervia/pages/chat/page_meta.py @ 1216:b2d067339de3

python 3 port: /!\ Python 3.6+ is now needed to use libervia /!\ instability may occur and features may not be working anymore, this will improve with time /!\ TxJSONRPC dependency has been removed The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog, JSON RPC related code). Adapted code to work without `html` and `themes` dirs.
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:12:31 +0200
parents 251eba911d4d
children 4ccc5bb65be2
line wrap: on
line diff
--- a/libervia/pages/chat/page_meta.py	Tue Aug 13 09:39:33 2019 +0200
+++ b/libervia/pages/chat/page_meta.py	Tue Aug 13 19:12:31 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 from sat.core.i18n import _
@@ -11,9 +11,9 @@
 from libervia.server.constants import Const as C
 from libervia.server import session_iface
 
-name = u"chat"
+name = "chat"
 access = C.PAGES_ACCESS_PROFILE
-template = u"chat/chat.html"
+template = "chat/chat.html"
 dynamic = True
 
 
@@ -24,15 +24,15 @@
         target_jid_s = self.nextPath(request)
     except IndexError:
         # not chat jid, we redirect to jid selection page
-        self.pageRedirect(u"chat_select", request)
+        self.pageRedirect("chat_select", request)
 
     try:
         target_jid = jid.JID(target_jid_s)
         if not target_jid.user:
-            raise ValueError(_(u"invalid jid for chat (no local part)"))
+            raise ValueError(_("invalid jid for chat (no local part)"))
     except Exception as e:
         log.warning(
-            _(u"bad chat jid entered: {jid} ({msg})").format(jid=target_jid, msg=e)
+            _("bad chat jid entered: {jid} ({msg})").format(jid=target_jid, msg=e)
         )
         self.pageError(request, C.HTTP_BAD_REQUEST)
     else:
@@ -49,14 +49,14 @@
     profile = session.profile
     profile_jid = session.jid
 
-    disco = yield self.host.bridgeCall(u"discoInfos", target_jid.host, u"", True, profile)
+    disco = yield self.host.bridgeCall("discoInfos", target_jid.host, "", True, profile)
     if "conference" in [i[0] for i in disco[1]]:
         chat_type = C.CHAT_GROUP
         join_ret = yield self.host.bridgeCall(
-            u"mucJoin", target_jid.userhost(), "", "", profile
+            "mucJoin", target_jid.userhost(), "", "", profile
         )
         already_joined, room_jid_s, occupants, user_nick, room_subject, __ = join_ret
-        template_data[u"subject"] = room_subject
+        template_data["subject"] = room_subject
         own_jid = jid.JID(room_jid_s)
         own_jid.resource = user_nick
     else:
@@ -65,9 +65,9 @@
     rdata["chat_type"] = chat_type
     template_data["own_jid"] = own_jid
 
-    self.registerSignal(request, u"messageNew")
+    self.registerSignal(request, "messageNew")
     history = yield self.host.bridgeCall(
-        u"historyGet",
+        "historyGet",
         profile_jid.userhost(),
         target_jid.userhost(),
         20,
@@ -78,45 +78,45 @@
     authors = {m[2] for m in history}
     identities = {}
     for author in authors:
-        identities[author] = yield self.host.bridgeCall(u"identityGet", author, profile)
+        identities[author] = yield self.host.bridgeCall("identityGet", author, profile)
 
-    template_data[u"messages"] = data_objects.Messages(history)
-    rdata[u'identities'] = template_data[u"identities"] = identities
-    template_data[u"target_jid"] = target_jid
-    template_data[u"chat_type"] = chat_type
+    template_data["messages"] = data_objects.Messages(history)
+    rdata['identities'] = template_data["identities"] = identities
+    template_data["target_jid"] = target_jid
+    template_data["chat_type"] = chat_type
 
 
 def on_data(self, request, data):
     session = self.host.getSessionData(request, session_iface.ISATSession)
     rdata = self.getRData(request)
     target = rdata["target"]
-    data_type = data.get(u"type", "")
+    data_type = data.get("type", "")
     if data_type == "msg":
-        message = data[u"body"]
+        message = data["body"]
         mess_type = (
             C.MESS_TYPE_GROUPCHAT
             if rdata["chat_type"] == C.CHAT_GROUP
             else C.MESS_TYPE_CHAT
         )
-        log.debug(u"message received: {}".format(message))
+        log.debug("message received: {}".format(message))
         self.host.bridgeCall(
-            u"messageSend",
+            "messageSend",
             target.full(),
-            {u"": message},
+            {"": message},
             {},
             mess_type,
             {},
             session.profile,
         )
     else:
-        log.warning(u"unknown message type: {type}".format(type=data_type))
+        log.warning("unknown message type: {type}".format(type=data_type))
 
 
 @defer.inlineCallbacks
 def on_signal(self, request, signal, *args):
     if signal == "messageNew":
         rdata = self.getRData(request)
-        template_data_update = {u"msg": data_objects.Message((args))}
+        template_data_update = {"msg": data_objects.Message((args))}
         target_jid = rdata["target"]
         identities = rdata["identities"]
         uid, timestamp, from_jid_s, to_jid_s, message, subject, mess_type, extra, __ = (
@@ -134,11 +134,11 @@
         if from_jid_s not in identities:
             profile = self.getProfile(request)
             identities[from_jid_s] = yield self.host.bridgeCall(
-                u"identityGet", from_jid_s, profile
+                "identityGet", from_jid_s, profile
             )
             template_data_update["identities"] = identities
         self.renderAndUpdate(
-            request, u"chat/message.html", "#messages", template_data_update
+            request, "chat/message.html", "#messages", template_data_update
         )
     else:
-        log.error(_(u"Unexpected signal: {signal}").format(signal=signal))
+        log.error(_("Unexpected signal: {signal}").format(signal=signal))