# HG changeset patch # User Paul Boddie # Date 1457288563 -3600 # Node ID 519e1d452e0d89ac48745b9c118f416d3ec6f1e1 # Parent 9cb80c0c685cb8e642d4cf5852e68985a27f52a3 Added parsing and serialisation functions involving strings. diff -r 9cb80c0c685c -r 519e1d452e0d imiptools/data.py --- a/imiptools/data.py Sun Mar 06 19:19:23 2016 +0100 +++ b/imiptools/data.py Sun Mar 06 19:22:43 2016 +0100 @@ -617,6 +617,19 @@ return None +def parse_string(s, encoding, objtype=None): + + """ + Parse the iTIP content from 's' having the given 'encoding'. If 'objtype' is + given, only objects of that type will be returned. Otherwise, the root of + the content will be returned as a dictionary with a single key indicating + the object type. + + Return None if the content was not readable or suitable. + """ + + return parse_object(StringIO(s), encoding, objtype) + def to_part(method, calendar): """ @@ -638,6 +651,15 @@ def to_stream(out, fragment, encoding="utf-8"): iterwrite(out, encoding=encoding).append(fragment) +def to_string(fragment, encoding="utf-8"): + out = StringIO() + try: + to_stream(out, fragment, encoding) + return out.getvalue() + + finally: + out.close() + # Structure access functions. def get_items(d, name, all=True):