comparison sat_frontends/jp/output_xml.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
34 except ImportError: 34 except ImportError:
35 pygments = None 35 pygments = None
36 36
37 37
38 __outputs__ = ["XML"] 38 __outputs__ = ["XML"]
39 RAW = u"xml_raw" 39 RAW = "xml_raw"
40 PRETTY = u"xml_pretty" 40 PRETTY = "xml_pretty"
41 41
42 42
43 class XML(object): 43 class XML(object):
44 """Outputs for XML""" 44 """Outputs for XML"""
45 45
52 52
53 def colorize(self, xml): 53 def colorize(self, xml):
54 if pygments is None: 54 if pygments is None:
55 self.host.disp( 55 self.host.disp(
56 _( 56 _(
57 u"Pygments is not available, syntax highlighting is not possible. Please install if from http://pygments.org or with pip install pygments" 57 "Pygments is not available, syntax highlighting is not possible. Please install if from http://pygments.org or with pip install pygments"
58 ), 58 ),
59 error=True, 59 error=True,
60 ) 60 )
61 return xml 61 return xml
62 if not sys.stdout.isatty(): 62 if not sys.stdout.isatty():
63 return xml 63 return xml
64 lexer = XmlLexer(encoding="utf-8") 64 lexer = XmlLexer(encoding="utf-8")
65 formatter = TerminalFormatter(bg=u"dark") 65 formatter = TerminalFormatter(bg="dark")
66 return pygments.highlight(xml, lexer, formatter) 66 return pygments.highlight(xml, lexer, formatter)
67 67
68 def format(self, data, pretty=True): 68 def format(self, data, pretty=True):
69 parser = etree.XMLParser(remove_blank_text=True) 69 parser = etree.XMLParser(remove_blank_text=True)
70 tree = etree.fromstring(data, parser) 70 tree = etree.fromstring(data, parser)
75 return self.format(data, pretty=False) 75 return self.format(data, pretty=False)
76 76
77 def pretty(self, data): 77 def pretty(self, data):
78 self.host.disp(self.format(data)) 78 self.host.disp(self.format(data))
79 79
80 def pretty_list(self, data, separator=u"\n"): 80 def pretty_list(self, data, separator="\n"):
81 list_pretty = map(self.format, data) 81 list_pretty = list(map(self.format, data))
82 self.host.disp(separator.join(list_pretty)) 82 self.host.disp(separator.join(list_pretty))
83 83
84 def raw(self, data): 84 def raw(self, data):
85 self.host.disp(self.format_no_pretty(data)) 85 self.host.disp(self.format_no_pretty(data))
86 86
87 def list_raw(self, data, separator=u"\n"): 87 def list_raw(self, data, separator="\n"):
88 list_no_pretty = map(self.format_no_pretty, data) 88 list_no_pretty = list(map(self.format_no_pretty, data))
89 self.host.disp(separator.join(list_no_pretty)) 89 self.host.disp(separator.join(list_no_pretty))