comparison frontends/src/jp/output_std.py @ 2161:62dfa6e02f54

jp (base, blog, output(std)): fixed bad unicode handling in stdout, use of jp.disp instead of simple print
author Goffi <goffi@goffi.org>
date Tue, 21 Feb 2017 21:01:40 +0100
parents 8f96c242fa89
children 9061c7247964
comparison
equal deleted inserted replaced
2160:e67e8cd24141 2161:62dfa6e02f54
29 29
30 30
31 class Simple(object): 31 class Simple(object):
32 """Default outputs""" 32 """Default outputs"""
33 33
34 def __init__(self, jp): 34 def __init__(self, host):
35 jp.register_output(C.OUTPUT_TEXT, SIMPLE, self.simple_print) 35 self.host = host
36 jp.register_output(C.OUTPUT_LIST, SIMPLE, self.list) 36 host.register_output(C.OUTPUT_TEXT, SIMPLE, self.simple_print)
37 jp.register_output(C.OUTPUT_DICT, SIMPLE, self.dict) 37 host.register_output(C.OUTPUT_LIST, SIMPLE, self.list)
38 jp.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print) 38 host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict)
39 host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print)
39 40
40 def simple_print(self, data): 41 def simple_print(self, data):
41 print data 42 self.host.disp(data)
42 43
43 def list(self, data): 44 def list(self, data):
44 print u'\n'.join(data) 45 self.host.disp(u'\n'.join(data))
45 46
46 def dict(self, data): 47 def dict(self, data):
47 for k, v in data: 48 for k, v in data:
48 print(u'{key}: {value}'.format(key=k, value=v)) 49 self.host.disp((u'{key}: {value}'.format(key=k, value=v)))
49 50
50 51
51 class Json(object): 52 class Json(object):
52 """outputs in json format""" 53 """outputs in json format"""
53 54
54 def __init__(self, jp): 55 def __init__(self, host):
55 jp.register_output(C.OUTPUT_TEXT, JSON, self.dump) 56 self.host = host
56 jp.register_output(C.OUTPUT_LIST, JSON, self.dump_pretty) 57 host.register_output(C.OUTPUT_TEXT, JSON, self.dump)
57 jp.register_output(C.OUTPUT_LIST, JSON_RAW, self.dump) 58 host.register_output(C.OUTPUT_LIST, JSON, self.dump_pretty)
58 jp.register_output(C.OUTPUT_DICT, JSON, self.dump_pretty) 59 host.register_output(C.OUTPUT_LIST, JSON_RAW, self.dump)
59 jp.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump) 60 host.register_output(C.OUTPUT_DICT, JSON, self.dump_pretty)
60 jp.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty) 61 host.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump)
61 jp.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump) 62 host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty)
63 host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)
62 64
63 def dump(self, data): 65 def dump(self, data):
64 print json.dumps(data, default=str) 66 self.host.disp(json.dumps(data, default=str))
65 67
66 def dump_pretty(self, data): 68 def dump_pretty(self, data):
67 print json.dumps(data, indent=4, default=str) 69 self.host.disp(json.dumps(data, indent=4, default=str))