Exemplo n.º 1
0
 def _undone(self, session):
     rows = list()
     for undo in session.query(UndoLog):
         rows.append(
             dict(
                 map(lambda x: (x, getattr(undo, x)),
                     self.tables[UndoLog.__tablename__])))
     prettyPrintLn(rows)
Exemplo n.º 2
0
    def test(self):

        h = '\n' + '_' * 47

        j = {
            'one': {
                'one_one': {
                    'one_one': [{
                        '#text': '_1_1_1'
                    }, {
                        '#text': '_1_1_2'
                    }]
                },
                'one_two': {
                    '@attr': '_1_2',
                    '#text': '_1_2_1'
                }
            }
        }

        print(h)
        prettyPrintLn(j)
        print(h)

        f = '../test/treeify.json'
        with open(f, 'w') as output:
            json.dump(j, output)
        self.bark([f])
        print(h)

        #self.ascii = True
        self.colour = True
        self.process(StringIO(json.dumps(j)), sys.stdout)
        print(h)

        x = xmltodict.unparse(j)
        doParse(StringIO(str(x)), sys.stdout, colour=True)
        print(h)
        self.format = 'xml'
        self.process(StringIO(str(x)), sys.stdout)
        print(h)

        sio = StringIO()
        prettyPrintLn(j, output=sio, style=Style.YAML, colour=False)
        y = sio.getvalue()
        sio.close()
        #print y
        y = y.replace('#text', '"#text"')
        y = y.replace('@attr', '"@attr"')
        #print y
        prettyPrintLn(j, output=sys.stdout, style=Style.YAML, colour=True)
        print(h)
        self.format = 'yaml'
        self.process(StringIO(y), sys.stdout)

        return
Exemplo n.º 3
0
def test():
	global _colour
	global _format
	global _ascii

	h = '\n' + '_' * 47

	j = {
		'one': {
			'one_one': {
				'one_one': [{
					'#text': '_1_1_1'
				}, {
					'#text': '_1_1_2'
				}]
			},
			'one_two': {
				'@attr': '_1_2',
				'#text': '_1_2_1'
			}
		}
	}
	print(h)
	prettyPrintLn(j)
	print(h)

	#_ascii=True
	_colour = True
	process(StringIO(json.dumps(j)), sys.stdout)
	print(h)

	x = xmltodict.unparse(j)
	doParse(StringIO(str(x)), sys.stdout, colour=True)
	print(h)
	_format = 'xml'
	process(StringIO(str(x)), sys.stdout)
	print(h)

	sio = StringIO()
	prettyPrintLn(j, output=sio, style=Style.YAML, colour=False)
	y = sio.getvalue()
	sio.close()
	#print y
	y = y.replace('#text', '"#text"')
	y = y.replace('@attr', '"@attr"')
	#print y
	prettyPrintLn(j, output=sys.stdout, style=Style.YAML, colour=True)
	print(h)
	_format = 'yaml'
	process(StringIO(y), sys.stdout)

	return
Exemplo n.º 4
0
 def _sequences(self, session):
     results = dict()
     for sequence in session.query(t_sqlite_sequence):
         results[sequence.name] = sequence.seq
     prettyPrintLn(results, align=True)
Exemplo n.º 5
0
#!/usr/bin/env python3

import os, re, sys, json, xmltodict

from kafka import KafkaConsumer
from Perdy.pretty import prettyPrintLn
from Perdy.parser import printXML

consumer = KafkaConsumer(bootstrap_servers='voldemort:9092')
consumer.subscribe(['quickstart-events'])

for message in consumer:
    text = message.value.decode('utf8')
    try:
        d = json.loads(text)
        prettyPrintLn(d)
    except:
        try:
            x = xmltodict.parse(text)
            printXML(text, colour=True)
        except:
            print(text)