diff libervia/pages/g/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 bfbfe04209e9
children f511f8fbbf8a
line wrap: on
line diff
--- a/libervia/pages/g/page_meta.py	Tue Aug 13 09:39:33 2019 +0200
+++ b/libervia/pages/g/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 libervia.server.constants import Const as C
@@ -10,7 +10,7 @@
 log = getLogger(__name__)
 
 access = C.PAGES_ACCESS_PUBLIC
-template = u"invitation/welcome.html"
+template = "invitation/welcome.html"
 
 
 @defer.inlineCallbacks
@@ -32,7 +32,7 @@
     if current_id is not None and current_id != invitation_id:
         log.info(
             _(
-                u"killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]"
+                "killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]"
             ).format(old_id=current_id, new_id=invitation_id)
         )
         self.host.purgeSession(request)
@@ -46,7 +46,7 @@
     if profile is not None and current_id is None:
         log.info(
             _(
-                u"killing current profile session [{profile}] because a guest id is used"
+                "killing current profile session [{profile}] because a guest id is used"
             ).format(profile=profile)
         )
         self.host.purgeSession(request)
@@ -56,7 +56,7 @@
         profile = None
 
     if current_id is None:
-        log.debug(_(u"checking invitation [{id}]").format(id=invitation_id))
+        log.debug(_("checking invitation [{id}]").format(id=invitation_id))
         try:
             data = yield self.host.bridgeCall("invitationGet", invitation_id)
         except Exception:
@@ -68,21 +68,21 @@
         data = guest_session.data
 
     if profile is None:
-        log.debug(_(u"connecting profile [{}]").format(profile))
+        log.debug(_("connecting profile [{}]").format(profile))
         # we need to connect the profile
         profile = data["guest_profile"]
         password = data["password"]
         try:
             yield self.host.connect(request, profile, password)
         except Exception as e:
-            log.warning(_(u"Can't connect profile: {msg}").format(msg=e))
+            log.warning(_("Can't connect profile: {msg}").format(msg=e))
             # FIXME: no good error code correspond
             #        maybe use a custom one?
             self.pageError(request, code=C.HTTP_SERVICE_UNAVAILABLE)
 
         log.info(
             _(
-                u"guest session started, connected with profile [{profile}]".format(
+                "guest session started, connected with profile [{profile}]".format(
                     profile=profile
                 )
             )
@@ -91,16 +91,16 @@
     # we copy data useful in templates
     template_data = request.template_data
     template_data["norobots"] = True
-    if u"name" in data:
-        template_data[u"name"] = data[u"name"]
-    if u"language" in data:
-        template_data[u"locale"] = data[u"language"]
+    if "name" in data:
+        template_data["name"] = data["name"]
+    if "language" in data:
+        template_data["locale"] = data["language"]
 
 def handleEventInterest(self, interest):
     if C.bool(interest.get("creator", C.BOOL_FALSE)):
-        page_name = u"event_admin"
+        page_name = "event_admin"
     else:
-        page_name = u"event_rsvp"
+        page_name = "event_rsvp"
 
     interest["url"] = self.getPageByName(page_name).getURL(
         interest.get("service", ""),
@@ -108,24 +108,24 @@
         interest.get("item"),
         )
 
-    if u"thumb_url" not in interest and u"image" in interest:
-        interest[u"thumb_url"] = interest[u"image"]
+    if "thumb_url" not in interest and "image" in interest:
+        interest["thumb_url"] = interest["image"]
 
 def handleFISInterest(self, interest):
-    path = interest.get(u'path', u'')
-    path_args = [p for p in path.split(u'/') if p]
-    subtype = interest.get(u'subtype')
+    path = interest.get('path', '')
+    path_args = [p for p in path.split('/') if p]
+    subtype = interest.get('subtype')
 
-    if subtype == u'files':
-        page_name = u"files_view"
-    elif interest.get(u'subtype') == u'photos':
-        page_name = u"photos_album"
+    if subtype == 'files':
+        page_name = "files_view"
+    elif interest.get('subtype') == 'photos':
+        page_name = "photos_album"
     else:
-        log.warning(u"unknown interest subtype: {subtype}".format(subtype=subtype))
+        log.warning("unknown interest subtype: {subtype}".format(subtype=subtype))
         return False
 
     interest["url"] = self.getPageByName(page_name).getURL(
-        interest[u'service'], *path_args)
+        interest['service'], *path_args)
 
 @defer.inlineCallbacks
 def prepare_render(self, request):
@@ -137,17 +137,17 @@
         interests = yield self.host.bridgeCall(
             "interestsList", "", "", "", profile)
     except Exception:
-        log.warning(_(u"Can't get interests list for {profile}").format(
+        log.warning(_("Can't get interests list for {profile}").format(
             profile=profile))
     else:
         # we only want known interests (photos and events for now)
         # this dict map namespaces of interest to a callback which can manipulate
         # the data. If it returns False, the interest is skipped
         ns_data = {}
-        template_data[u'interests_map'] = interests_map = {}
+        template_data['interests_map'] = interests_map = {}
 
-        for short_name, cb in ((u'event', handleEventInterest),
-                               (u'fis', handleFISInterest),
+        for short_name, cb in (('event', handleEventInterest),
+                               ('fis', handleFISInterest),
                               ):
             try:
                 namespace = self.host.ns_map[short_name]
@@ -157,13 +157,13 @@
                 ns_data[namespace] = (cb, short_name)
 
         for interest in interests:
-            namespace = interest.get(u'namespace')
+            namespace = interest.get('namespace')
             if namespace not in ns_data:
                 continue
             cb, short_name = ns_data[namespace]
             if cb(self, interest) == False:
                 continue
-            key = interest.get(u'subtype', short_name)
+            key = interest.get('subtype', short_name)
             interests_map.setdefault(key, []).append(interest)
 
     # main URI
@@ -172,4 +172,4 @@
     if main_uri:
         include_url = self.getPagePathFromURI(main_uri)
         if include_url is not None:
-            template_data[u"include_url"] = include_url
+            template_data["include_url"] = include_url