comparison sat/tools/common/ansi.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 003b8b4b56a7
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
24 24
25 ## ANSI escape sequences ## 25 ## ANSI escape sequences ##
26 RESET = "\033[0m" 26 RESET = "\033[0m"
27 NORMAL_WEIGHT = "\033[22m" 27 NORMAL_WEIGHT = "\033[22m"
28 FG_BLACK, FG_RED, FG_GREEN, FG_YELLOW, FG_BLUE, FG_MAGENTA, FG_CYAN, FG_WHITE = ( 28 FG_BLACK, FG_RED, FG_GREEN, FG_YELLOW, FG_BLUE, FG_MAGENTA, FG_CYAN, FG_WHITE = (
29 "\033[3%dm" % nb for nb in xrange(8) 29 "\033[3%dm" % nb for nb in range(8)
30 ) 30 )
31 BOLD = "\033[1m" 31 BOLD = "\033[1m"
32 BLINK = "\033[5m" 32 BLINK = "\033[5m"
33 BLINK_OFF = "\033[25m" 33 BLINK_OFF = "\033[25m"
34 34
40 """ 40 """
41 # XXX: we expect to have at least one argument 41 # XXX: we expect to have at least one argument
42 if args[-1] != cls.RESET: 42 if args[-1] != cls.RESET:
43 args = list(args) 43 args = list(args)
44 args.append(cls.RESET) 44 args.append(cls.RESET)
45 return u"".join(args) 45 return "".join(args)
46 46
47 47
48 try: 48 try:
49 tty = sys.stdout.isatty() 49 tty = sys.stdout.isatty()
50 except ( 50 except (
53 ): # FIXME: TypeError is here for Pyjamas, need to be removed 53 ): # FIXME: TypeError is here for Pyjamas, need to be removed
54 tty = False 54 tty = False
55 if not tty: 55 if not tty:
56 #  we don't want ANSI escape codes if we are not outputing to a tty! 56 #  we don't want ANSI escape codes if we are not outputing to a tty!
57 for attr in dir(ANSI): 57 for attr in dir(ANSI):
58 if isinstance(getattr(ANSI, attr), basestring): 58 if isinstance(getattr(ANSI, attr), str):
59 setattr(ANSI, attr, u"") 59 setattr(ANSI, attr, "")
60 del tty 60 del tty