diff sat/core/log_config.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents ad00f61fd9f5
children 49c7bc3afb2b
line wrap: on
line diff
--- a/sat/core/log_config.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/core/log_config.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SàT: a XMPP client
@@ -125,7 +125,7 @@
                 ) or self.LOGGER_CLASS.force_colors:
                     message = event.get("message", tuple())
                     if message:
-                        event["message"] = ("".join(message),)  # must be a tuple
+                        event["message"] = (b"".join(message),)  # must be a tuple
                 observer(event)  # we can now call the original observer
 
         return observer_hook
@@ -158,7 +158,7 @@
                 observer = self.changeObserver(observer, can_colors=True)
             else:
                 # we use print because log system is not fully initialized
-                print("Unmanaged observer [%s]" % observer)
+                print(("Unmanaged observer [%s]" % observer))
                 return observer
             self.observers[ori] = observer
         return observer
@@ -202,10 +202,10 @@
         import types  # see https://stackoverflow.com/a/4267590 (thx Chris Morgan/aaronasterling)
 
         twisted_log.addObserver = types.MethodType(
-            addObserverObserver, self.log_publisher, twisted_log.LogPublisher
+            addObserverObserver, self.log_publisher
         )
         twisted_log.removeObserver = types.MethodType(
-            removeObserverObserver, self.log_publisher, twisted_log.LogPublisher
+            removeObserverObserver, self.log_publisher
         )
 
         # we now change existing observers
@@ -282,7 +282,7 @@
                     if event.get("isError", False)
                     else twisted_logger.info
                 )
-                log_method(text.decode("utf-8"))
+                log_method(text)
 
         self.log_publisher._originalAddObserver(twistedObserver)
 
@@ -336,7 +336,7 @@
         import sys
 
         class SatFormatter(logging.Formatter):
-            u"""Formatter which manage SàT specificities"""
+            """Formatter which manage SàT specificities"""
             _format = fmt
             _with_profile = "%(profile)s" in fmt
 
@@ -395,7 +395,7 @@
 
         root_logger = logging.getLogger()
         if len(root_logger.handlers) == 0:
-            for handler, options in log.handlers.items():
+            for handler, options in list(log.handlers.items()):
                 if handler == C.LOG_OPT_OUTPUT_DEFAULT:
                     hdlr = logging.StreamHandler()
                     try:
@@ -426,7 +426,7 @@
                 else:
                     raise ValueError("Unknown handler type")
         else:
-            root_logger.warning(u"Handlers already set on root logger")
+            root_logger.warning("Handlers already set on root logger")
 
     @staticmethod
     def memoryGet(size=None):