diff libervia/pages/files/list/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 29eb15062416
children f511f8fbbf8a
line wrap: on
line diff
--- a/libervia/pages/files/list/page_meta.py	Tue Aug 13 09:39:33 2019 +0200
+++ b/libervia/pages/files/list/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
@@ -14,9 +14,9 @@
 log = getLogger(__name__)
 """files handling pages"""
 
-name = u"files_list"
+name = "files_list"
 access = C.PAGES_ACCESS_PROFILE
-template = u"file/overview.html"
+template = "file/overview.html"
 
 
 def parse_url(self, request):
@@ -28,27 +28,27 @@
     data = self.getRData(request)
     thumb_limit = data.get("thumb_limit", 300)
     template_data = request.template_data
-    service, path_elts = data[u"service"], data[u"path"]
-    path = u"/".join(path_elts)
+    service, path_elts = data["service"], data["path"]
+    path = "/".join(path_elts)
     profile = self.getProfile(request) or C.SERVICE_PROFILE
 
     files_data = yield self.host.bridgeCall("FISList", service.full(), path, {}, profile)
     for file_data in files_data:
         try:
-            extra_raw = file_data[u"extra"]
+            extra_raw = file_data["extra"]
         except KeyError:
             pass
         else:
-            file_data[u"extra"] = json.loads(extra_raw) if extra_raw else {}
+            file_data["extra"] = json.loads(extra_raw) if extra_raw else {}
         dir_path = path_elts + [file_data["name"]]
-        if file_data[u"type"] == C.FILE_TYPE_DIRECTORY:
+        if file_data["type"] == C.FILE_TYPE_DIRECTORY:
             page = self
-        elif file_data[u"type"] == C.FILE_TYPE_FILE:
+        elif file_data["type"] == C.FILE_TYPE_FILE:
             page = self.getPageByName("files_view")
 
             ## thumbnails ##
             try:
-                thumbnails = file_data[u"extra"]["thumbnails"]
+                thumbnails = file_data["extra"]["thumbnails"]
                 if not thumbnails:
                     raise KeyError
             except KeyError:
@@ -60,16 +60,16 @@
                     if thumb_data["size"][0] > thumb_limit:
                         break
                     thumb = thumb_data
-                if u"url" in thumb:
+                if "url" in thumb:
                     file_data["thumb_url"] = thumb["url"]
-                elif u"id" in thumb:
+                elif "id" in thumb:
                     try:
                         thumb_path = yield self.host.bridgeCall(
-                            "bobGetFile", service.full(), thumb[u"id"], profile
+                            "bobGetFile", service.full(), thumb["id"], profile
                         )
                     except Exception as e:
                         log.warning(
-                            _(u"Can't retrieve thumbnail: {reason}").format(reason=e)
+                            _("Can't retrieve thumbnail: {reason}").format(reason=e)
                         )
                     else:
                         filename = os.path.basename(thumb_path)
@@ -81,28 +81,28 @@
                         )
         else:
             raise ValueError(
-                u"unexpected file type: {file_type}".format(file_type=file_data[u"type"])
+                "unexpected file type: {file_type}".format(file_type=file_data["type"])
             )
-        file_data[u"url"] = page.getURL(service.full(), *dir_path)
+        file_data["url"] = page.getURL(service.full(), *dir_path)
 
         ## comments ##
-        comments_url = file_data.get(u"comments_url")
+        comments_url = file_data.get("comments_url")
         if comments_url:
             parsed_url = uri.parseXMPPUri(comments_url)
-            comments_service = file_data[u"comments_service"] = parsed_url["path"]
-            comments_node = file_data[u"comments_node"] = parsed_url["node"]
+            comments_service = file_data["comments_service"] = parsed_url["path"]
+            comments_node = file_data["comments_node"] = parsed_url["node"]
             try:
-                comments_count = file_data[u"comments_count"] = int(
+                comments_count = file_data["comments_count"] = int(
                     file_data["comments_count"]
                 )
             except KeyError:
                 comments_count = None
             if comments_count and data.get("retrieve_comments", False):
-                file_data[u"comments"] = yield pages_tools.retrieveComments(
+                file_data["comments"] = yield pages_tools.retrieveComments(
                     self, comments_service, comments_node, profile=profile
                 )
 
-    template_data[u"files_data"] = files_data
-    template_data[u"path"] = path
+    template_data["files_data"] = files_data
+    template_data["path"] = path
     if path_elts:
-        template_data[u"parent_url"] = self.getURL(service.full(), *path_elts[:-1])
+        template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1])