Mercurial > libervia-backend
comparison sat/core/log.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 | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SàT: a XMPP client | 4 # SàT: a XMPP client |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
65 | 65 |
66 @param message: formatted message | 66 @param message: formatted message |
67 """ | 67 """ |
68 if kwargs.get('exc_info', False): | 68 if kwargs.get('exc_info', False): |
69 message = self.addTraceback(message) | 69 message = self.addTraceback(message) |
70 print message | 70 print(message) |
71 | 71 |
72 def log(self, level, message, **kwargs): | 72 def log(self, level, message, **kwargs): |
73 """Print message | 73 """Print message |
74 | 74 |
75 @param level: one of C.LOG_LEVELS | 75 @param level: one of C.LOG_LEVELS |
195 | 195 |
196 def updateCurrentLogger(self): | 196 def updateCurrentLogger(self): |
197 """update existing logger to the class needed for this backend""" | 197 """update existing logger to the class needed for this backend""" |
198 if self.LOGGER_CLASS is None: | 198 if self.LOGGER_CLASS is None: |
199 return | 199 return |
200 for name, logger in _loggers.items(): | 200 for name, logger in list(_loggers.items()): |
201 _loggers[name] = self.LOGGER_CLASS(logger) | 201 _loggers[name] = self.LOGGER_CLASS(logger) |
202 | 202 |
203 def preTreatment(self): | 203 def preTreatment(self): |
204 pass | 204 pass |
205 | 205 |
233 Logger.filter_name = FilterName(logger) | 233 Logger.filter_name = FilterName(logger) |
234 | 234 |
235 def configureColors(self, colors, force_colors, levels_taints_dict): | 235 def configureColors(self, colors, force_colors, levels_taints_dict): |
236 if colors: | 236 if colors: |
237 # if color are used, we need to handle levels_taints_dict | 237 # if color are used, we need to handle levels_taints_dict |
238 for level in levels_taints_dict.keys(): | 238 for level in list(levels_taints_dict.keys()): |
239 # we wants levels in uppercase to correspond to contstants | 239 # we wants levels in uppercase to correspond to contstants |
240 levels_taints_dict[level.upper()] = levels_taints_dict[level] | 240 levels_taints_dict[level.upper()] = levels_taints_dict[level] |
241 taints = self.__class__.taints = {} | 241 taints = self.__class__.taints = {} |
242 for level in C.LOG_LEVELS: | 242 for level in C.LOG_LEVELS: |
243 # we want use values and use constant value as default | 243 # we want use values and use constant value as default |
281 output = output[:opt_begin] | 281 output = output[:opt_begin] |
282 else: | 282 else: |
283 options = None | 283 options = None |
284 | 284 |
285 if output not in (C.LOG_OPT_OUTPUT_DEFAULT, C.LOG_OPT_OUTPUT_FILE, C.LOG_OPT_OUTPUT_MEMORY): | 285 if output not in (C.LOG_OPT_OUTPUT_DEFAULT, C.LOG_OPT_OUTPUT_FILE, C.LOG_OPT_OUTPUT_MEMORY): |
286 raise ValueError(u"Invalid output [%s]" % output) | 286 raise ValueError("Invalid output [%s]" % output) |
287 | 287 |
288 if output == C.LOG_OPT_OUTPUT_DEFAULT: | 288 if output == C.LOG_OPT_OUTPUT_DEFAULT: |
289 # no option for defaut handler | 289 # no option for defaut handler |
290 handlers[output] = None | 290 handlers[output] = None |
291 elif output == C.LOG_OPT_OUTPUT_FILE: | 291 elif output == C.LOG_OPT_OUTPUT_FILE: |
301 except (TypeError, ValueError): | 301 except (TypeError, ValueError): |
302 limit = C.LOG_OPT_OUTPUT_MEMORY_LIMIT | 302 limit = C.LOG_OPT_OUTPUT_MEMORY_LIMIT |
303 handlers[output] = limit | 303 handlers[output] = limit |
304 | 304 |
305 if options: # we should not have unparsed options | 305 if options: # we should not have unparsed options |
306 raise ValueError(u"options [{options}] are not supported for {handler} output".format(options=options, handler=output)) | 306 raise ValueError("options [{options}] are not supported for {handler} output".format(options=options, handler=output)) |
307 | 307 |
308 @staticmethod | 308 @staticmethod |
309 def memoryGet(size=None): | 309 def memoryGet(size=None): |
310 """Return buffered logs | 310 """Return buffered logs |
311 | 311 |