In [1]:
import axon
line = '\n'+32*'-'
In [25]:
vals = axon.loads("""
RU: "Moscow"
US: "Washington"
GB: "London"
""")
print(vals, line)
print(axon.dumps(vals))
In [26]:
vals = axon.loads("""
[RU:"Moscow" FR:"Paris"]
[CN:"Beijin" JP:"Tokio"]
[US:"Washington" CA:"Ottava"]
""")
print(vals, line)
print(axon.dumps(vals), line)
print(axon.dumps(vals, pretty=1))
In [27]:
vals = axon.loads("""
{RU:"Moscow" FR:"Paris"}
{CN:"Beigin" JP:"Tokio"}
{US:"Washington" CA:"Ottava"}
""")
print(vals, line)
print(axon.dumps(vals, sorted=1), line)
print(axon.dumps(vals, sorted=1, pretty=1))
In [28]:
vals = axon.loads("""
("RU" "Moscow")
("US" "Washington")
("GB" "London")
""")
print(vals, line)
print(axon.dumps(vals))
In [29]:
vals = axon.loads("""
["RU" "Moscow"]
["US" "Washington"]
["GB" "London"]
""")
print(vals, line)
print(axon.dumps(vals))
In [30]:
vals = axon.loads("""
[1 3.14 1000D "abc абв" 2015-12-01 12:00-03:00 2015-12-01T12:00+03:00 ? ∞]
""")
print(vals, line)
print(axon.dumps(vals))
In [31]:
vals = axon.loads("""
country{id:"RU" capital:"Moscow"}
country{id:"USA" capital:"Washington"}
country{id:"GB" capital:"London"}
""")
print(vals, line)
print(axon.dumps(vals), line)
print(axon.dumps(vals, pretty=1), line)
print(axon.dumps(vals, pretty=1, braces=1))
In [35]:
class Country:
def __init__(self, id, capital):
self.id = id
self.capital = capital
def __repr__(self):
return "Country(id='{}', capital='{}')".format(self.id, self.capital)
@axon.reduce(Country)
def reduce_country(ob):
return axon.node("country", axon.odict([("id",ob.id), ("capital",ob.capital)]))
@axon.factory("country")
def factory_country(map, seq):
return Country(map["id"], map["capital"])
vals = axon.loads("""
country
id:"RU"
capital:"Moscow"
country
id:"USA"
capital:"Washington"
country
id:"GB"
capital:"London"
""", mode='strict')
print(vals, line)
print(axon.dumps(vals), line)
print(axon.dumps(vals, pretty=1, braces=1))
In [ ]: