Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dump(obj):
- def seq(obj):
- return " ".join([dump(i) for i in obj])
- if obj is None:
- return "nil"
- elif isinstance(obj, bool):
- if obj:
- return "true"
- else:
- return "false"
- elif isinstance(obj, (int, long, float)):
- return str(obj)
- elif isinstance(obj, decimal.Decimal):
- return "{}M".format(obj)
- elif isinstance(obj, basestring):
- return '"{}"'.format(obj)
- elif isinstance(obj, tuple):
- return "({})".format(seq(obj))
- elif isinstance(obj, list):
- return "[{}]".format(seq(obj))
- elif isinstance(obj, set) or isinstance(obj, frozenset):
- return "#{{{}}}".format(seq(obj))
- elif isinstance(obj, dict):
- return "{{{}}}".format(seq(itertools.chain.from_iterable(obj.items())))
- elif isinstance(obj, datetime.date):
- return '#inst "{}"'.format(obj.isoformat())
- elif isinstance(obj, uuid.UUID):
- return '#uuid "{}"'.format(obj)
- else:
- raise NotImplementedError(
- "Don't know how to handle {} : {}", type(obj), obj)
Advertisement
Add Comment
Please, Sign In to add comment